Complete The Programming Of An Object-Oriented Console Application in Java

profileAnne_Writer
Week10_Assignment_Solution.docx

CU_Horiz_RGBIT2249 Assignment Submission Template

CU_Horiz_RGBUnit 1, Part 1 Assignment Instructions

Name: Date: Class: IT2249 Unit:

1

When you submit your assignment, attach the complete, zipped NetBeans project (not just the .java file) to your submission and attach a completed copy of this submission template as a second attachment. (Please do not embed the zip file in this document.)

For u03a1, u06a1, u08a1, and u10a1: Be sure to turn in the zip file with code that you have completed, not the original zip file downloaded from the resources.

Insert here a copy of your *.java source code text that you used here (copy and paste source code here, do not simply insert *.java files):

// TO DO

// loop over the courses array and print out the attributes of its

//objects in the format of

//[selection number]Course Code (Course Credit Hours)

//one per line

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

System.out.printf("[%d] %s (%d)\n", (i + 1), courses[i].getCode(),courses[i].getCreditHour());

System.out.print("Enter your choice: ");

return (input.nextInt());

}

// TO DO

// loop over the courses array, determine which courses are registered

//for thus and print them out in the format of

//{ list of courses separated by , }

boolean first = true;

for (Course c : courses) {

if (c.getIsRegisteredFor()) {

if (first) {

System.out.print(c.getCode());

first = false;

} else {

System.out.print(", " + c.getCode());

}

}

}

2

Insert screenshot(s) here showing the result of testing your application as directed by the assignment instructions. (Programs with more than 1 possible outcome require screen shots to show that the different possible outcomes work as required.)

3

Describe your approach to complete the coding for this assignment and explain the major decisions you made in designing a program that meets the specified requirements.

As part of your explanation, be sure to identify the Java constructs you used that are specific and relevant to your program. Depending on the program, these may include the mechanisms for output, input, selection statements, loops, methods, and so forth. In units 9 and 10, be sure to discuss the classes used in the application. (Please do not just list Java keywords or snippets of code without indicating why they are important.)

/ TO DO

// loop over the courses array and print out the attributes of its

//objects in the format of

//[selection number]Course Code (Course Credit Hours)

//one per line

To complete the above task, I used for loop to iterate through the courses, then, used print() method to display the course details. For this to work I called and passed course Code and creditHours from the class as arguments in the printIn() method. To achieve the expected format, I used %d to represent an integer and %s a String and also used commas to separate the arguments passed in the method. I also used the return method to output the values stored in the two variables (Code and creditHours).

// TO DO

// loop over the courses array, determine which courses are registered

//for thus and print them out in the format of

//{ list of courses separated by , }

To complete this part of the assignment, I began by creating a Boolean that ensured no comma was printed before the first entry variable. Then, I went ahead and used for loop to check if the course is registered and if, yes, I used if statement to check if it is the first entry and if true, the loop ended by printing out the code registered. To ensure that courses registered are separated with a comma, I set the first variable to false and used the following method System.out.print(“,” +c.getCode ()); Please see the code provided above.

Capella Proprietary and Confidential 1

Capella Proprietary and Confidential

ShortDoc_Internal.doc

Last updated: 12/16/2019 2:44 AM 3