Question
Good-day please assist me with my task corrections on the attempted code. Task Compulsory Task 2 Follow these steps: Using one of the patterns described,
Good-day
please assist me with my task corrections on the attempted code.
Task
Compulsory Task 2
Follow these steps:
Using one of the patterns described, write the code needed to create 3
student objects. Each student object should have a describe() method
that returns a string that describes the student. Each student will be
described using a full name and a student number. The rest of the
description will be built up based on the students activity at HyperionDev.
For example, the description should explain which Bootcamps the
student has registered for and which level of the Bootcamp has been
completed.
Below is sample output:
Student 1: Susan Smith:
- Registered for the Software Engineering Bootcamp
- Completed level 1
Student 2: Michael Jansen:
- Registered for the Web Development Bootcamp
- Completed level 1
- Completed level 2
- Completed level 3
- Registered for the Software Engineering Bootcamp
Student 3: Saoirse Ronan
- Registered for the Web Development Bootcamp
- Completed level 1
- Completed level 2
- Completed level 3
- Registered for the Software Engineering Bootcamp
- Completed level 1
Corrections to be done.
Your implementation for Task 2 is not well documented and looks very much like the standard OOP we have been doing all along. It is not implementing any one of the discussed design patterns. Please could you use an appropriate package/ class name or add docstring comments to give an overview of your program Your spacing is very inconsistent. You are using too much whitespace. To keep your code clean and readable, please limit blank lines to one line between code blocks as per guidelines. Adding multiple blank lines generally serves to only take up space without improving the readability The link below will give you better insight on how to correctly space out your code in Java: https://www.oracle.com/java/technologies/javase/codeconventions-whitespace.html Comments should always be indented to the same level as their code Comments should be used to give overviews of code and provide additional information that is not readily available in the code itself. Over-commenting and stating the obvious can take away from the quality of your code e.g: //Student class class Student {
Code to be corrected
//Student class class Student{ //declaring Student class variables int studentId, noOfCourses; String name; String[] courses; int[] courseLevels; //Student constructor to initialize the variables Student(int studentId, String name, int noOfCourses, String[] courses, int[] courseLevels) { this.studentId = studentId; this.name = name; this.courses = new String[noOfCourses]; this.courseLevels = new int[noOfCourses]; for (int i = 0 ; i < noOfCourses; i ++) { this.courses[i] = courses[i]; this.courseLevels[i] = courseLevels[i]; } this.noOfCourses = noOfCourses; } //describe method to display the details public void describe() { //displaying all the details System.out.println("Student" + this.studentId + ": " + name + ":-"); for (int i = 0; i < this.noOfCourses; i ++) { System.out.println("Registered for the" + this.courses[i] + " - "); for (int j = 0; j < this.courseLevels[i]; j++) { System.out.println("Completed level " + (j+1)); } } } } //Main class public class Main { //main method public static void main(String[] args) { //initializing courses and course levels for 3 students String[] courses1 = new String[] {"Software Engineering"}; int[] courseLevels1 = new int[] {1}; String[] courses2 = new String[] {"Web Development", "Software Engineering"}; int[] courseLevels2 = new int[] {3,0}; String[] courses3 = new String[]{"Web Development", "Software Engineering"}; int[] courseLevels3 = new int[]{3,1}; //creating 3 student objects Student obj1 = new Student(1, "Susan Smith", courses1.length, courses1, courseLevels1); Student obj2 = new Student(2, "Michael Jackson", courses2.length, courses2, courseLevels2); Student obj3 = new Student(3, "Saoirse Ronan", courses3.length, courses3, courseLevels3); //calling describe method for each Student object obj1.describe(); obj2.describe(); obj3.describe(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started