Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me figure out this assignment--please detail why you're doing what you're doing in the added code so I can line by line check

Please help me figure out this assignment--please detail why you're doing what you're doing in the added code so I can line by line check my answer. I'm inserting the directions and both codes though the Course code does not need to be changed at all.

image text in transcribed

image text in transcribed

Java Course code that is fine:

public class Course {

private String code = ""; private int creditHour = 0; private boolean isRegisterdFor = false; public Course(String code, int creditHour){ this.code = code; this.creditHour = creditHour; } public void setCode(String code){ this.code = code; } public String getCode() { return this.code; } public void setCrditHour(int creditHour) { this.creditHour = creditHour; } public int getCreditHour() { return this.creditHour; } public void setIsRegisteredFor(boolean trueOrFalse){ this.isRegisterdFor = trueOrFalse; } public boolean getIsRegisteredFor() { return this.isRegisterdFor; } }

Code that needs additions/changes:

import java.util.Scanner;

/** * * @author omora */ public class U10A1_OOConsoleRegisterForCourse {

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here System.out.println("Teacher's Copy");

Scanner input = new Scanner(System.in); //Courses is an array of course objects //see the Course.java source code for members of Course Course[] courses = { new Course("IT1006", 6), new Course("IT4782", 3), new Course("IT4789", 3), new Course("IT4079", 6), new Course("IT2230", 3), new Course("IT3345", 3), new Course("IT2249", 6) };

//choice is the number selected by the user int choice; int totalCredit = 0; String yesOrNo = "";

do {

choice = getChoice(courses, input); switch (ValidateChoice(choice, totalCredit, courses)) { case -1: System.out.println("**Invalid** - Your selection of " + choice + " is not a recognized course."); break; case -2: System.out.println("**Invalid** - You have already registerd for this " + courses[choice-1].getCode() + " course."); break; case -3: System.out.println("**Invalid** - You can not register for more than 9 credit hours."); break; case 0: System.out.println("Registration Confirmed for course " + courses[choice-1].getCode() ); totalCredit += courses[choice-1].getCreditHour(); courses[choice-1].setIsRegisteredFor(true); break; } WriteCurrentRegistration(courses, totalCredit); System.out.print(" Do you want to try again? (Y|N)? : "); yesOrNo = input.next().toUpperCase(); } while (yesOrNo.equals("Y"));

System.out.println("Thank you for registering with us"); }

//This method prints out the selection menu to the user in the form of //[selection number]Course Code (Course Credit Hours) //from the courses array one per line //and then prompts the user to make a number selection public static int getChoice(Course[] courses, Scanner input) { System.out.println("Please type the number inside the [] to register for a course"); System.out.println("The number inside the () is the credit hours for the course"); // 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

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

return (input.nextInt()); } //This method validates the user menu selection //against the given registration business rules //it returns the following code based on the validation result // -1 = invalid, unrecognized menu selection // -2 = invalid, alredy registered for the course // -3 = invalid, No more than 9 credit hours allowed // 0 = menu selection is valid

public static int ValidateChoice(int choice, int totalCredit, Course[] courses) { if (choice 7) return -1; else if (IsRegisteredBefore(choice, courses) ) return -2; else if ( (totalCredit + courses[choice-1].getCreditHour()) > 9) return -3; return 0; } //This method checks the courses array of course object to //see if the course has already been registered for or not public static boolean IsRegisteredBefore(int choice, Course[] courses) { for(int i = 0; i

System.out.print("Current course registration: { " ); // 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 , } System.out.println(" }" );

System.out.println("Current registration total credit = " + totalCredit); } }

In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using the Object-Oriented features of the Java programming language. The application does compile and does run, but it does not produce the expected result as stated in its requirements. You can use either the Toolwire environment or your local Java development environment to complete this assignment. You have been hired to complete the source code of these two methods such that the application meets its stated requirements. Specifically, your added code should In one method, prints out a list of courses available for registration and prompt the user to select a course for which to register . In the second method, prints out a current list of registered courses and their total credit hours . The requirements of this application are as follows: The application is register students for courses in a term of study The assumptions used by the application are Student enter only integers to select courses for registration from a menu. No data type validation of the user menu selection is checked or required The program terminates only when the student closes it The program must follow these registration business rules No registration of other courses not displayed by the program No registration more than once for the same course . .No registration for more than 9 credit hours (e.g. no more than 3 courses) The application uses Java Object-Oriented features for its implementation. Students select from a menu of courses for which they wish to register. The program then validates the user selection against the registration business rules. If the selection is valid, the a confirmation message. Otherwise, the program prints out the current list of registered classes along with total registered credit hours. The program terminates when the user does not want to register for classes any more program prints out There are two Java classes of this application 1. 2. Course java. This Java class is complete and does not need any modification U10A1 OOConsoleRegisterForCourse.java. This is the class with the two methods that need to be completed The two methods that need to be completed of the U10A1_OOConsoleRegisterForCourse.java are 1. getChoice) method. This method loops over an array of course objects and prints out their attributes, one per line according to this format

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions