|
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.
|