Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Explain your approach you took to complete this assignment and the major decisio

ID: 3727516 • Letter: E

Question

Explain your approach you took to complete this assignment and the major decisions you made. As part of your explanation, be sure to identify the fundamental Java constructs you used that were specific and relevant.

Design and code a simple Java application called "U9A1_DefineClassInstantiateObj" that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a specific way.

The requirements of this application are as follows: The application is to define a Java class called Course. The Course class has the following attributes:

1. code - a string field to store the course code (e.g. IT1006)

2. creditHours – an int field to store the credit hours of the course (e.g. 6)

The application then instantiates, in order, seven instances (objects) from the Course class and assigns to each instance the following values: Order of instantiation Course Object code attribute Course Object creditHours attribute

1 IT1006 6

2 IT4782 3

3 IT4789 3

4 IT4079 6

5 IT2230 3

6 IT3345 3

7 IT2249 6

Finally, the application prints out, in the same order as the instantiation order, the attributes of these instances using this format: [order of instantiation] Course Code (Course Credit Hours) Successful completion of this assignment will show the correct order of object instantiation and the correct attributes of each object when the application is run.

Your program output should look like this sample output:

Course Registration.
Course Objects each has a code (ex. AD1005) and credit hours (ex. 3).
The number inside [] is the display order number.
The number inside () is the credit hours for the course.

[1] AD1005 (6)
[2] AD2005 (3)
[3] AD3005 (3)
[4] AD4005 (6)
[5] AD5005 (3)
[6] AD6005 (3)
[7] AD7005 (6)

Explain your approach you took to complete this assignment and the major decisions you made. As part of your explanation, be sure to identify the fundamental Java constructs you used that were specific and relevant.

An example output would be:

Course Registration. Course Objects each has a code (ex. IT4782) and credit hours (ex. 3) The number inside [] is the display order number. The number inside ) is the credit hours for the course. [1] IT1006 (6) [2] IT4782 (3) 31 IT4789 (3) [4] IT4079 (6) 5 IT2230 (3) [6] IT3345 (3) [7] IT2249 (6)

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

// U9A1_DefineClassInstantiateObj.java

public class U9A1_DefineClassInstantiateObj {

                public static void main(String[] args) {

                                /**

                                * Creating an array of Course objects

                                */

                                Course courses[] = new Course[7];

                                /**

                                * Filling the array with each courses in proper order

                                */

                                courses[0] = new Course("IT1006", 6);

                                courses[1] = new Course("IT4782", 3);

                                courses[2] = new Course("IT4789", 3);

                                courses[3] = new Course("IT4079", 6);

                                courses[4] = new Course("IT2230", 3);

                                courses[5] = new Course("IT3345", 3);

                                courses[6] = new Course("IT2249", 6);

                                /**

                                * Displaying the description

                                */

                                System.out.println("Course Registration.");

                                System.out.println("Course Objects each has a code (ex. IT4782)"

                                                                + " and credit hours (ex. 3)");

                                System.out.println("The number inside [] is the display order number.");

                                System.out

                                                                .println("The number inside () is the credit hours for the course.");

                                /**

                                * Displaying the courses, and their order

                                */

                                for (int i = 0; i < courses.length; i++) {

                                                /**

                                                * the toString method will be automatically invoked when courses[i]

                                                * is printed, we are just appending a [] before course details for

                                                * displaying the order

                                                */

                                                System.out.println("[" + (i + 1) + "] " + courses[i]);

                                }

                }

}

/**

* Represents one Course, has attributes- course code and credit hours. this

* should be placed within the same .java file

*

*/

class Course {

                private String code;

                private int creditHours;

                // constructor to initialize course code and credit hours

                public Course(String code, int creditHours) {

                                this.code = code;

                                this.creditHours = creditHours;

                }

               

                //getters and setters

               

                public String getCode() {

                                return code;

                }

                public void setCode(String code) {

                                this.code = code;

                }

                public int getCreditHours() {

                                return creditHours;

                }

                public void setCreditHours(int creditHours) {

                                this.creditHours = creditHours;

                }

                /**

                * returns a String containing course code and credit hours in proper format

                */

                public String toString() {

                                return code + " (" + creditHours + ")";

                }

}

/*OUTPUT*/

Course Registration.

Course Objects each has a code (ex. IT4782) and credit hours (ex. 3)

The number inside [] is the display order number.

The number inside () is the credit hours for the course.

[1] IT1006 (6)

[2] IT4782 (3)

[3] IT4789 (3)

[4] IT4079 (6)

[5] IT2230 (3)

[6] IT3345 (3)

[7] IT2249 (6)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote