Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assessment, you will complete the programming of a Java method in a console application that registers students for courses in a term of

In this assessment, you will complete the programming of a Java method in a console application that registers students for courses in a term of study. 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 this method such that the application meets its stated requirements. Specifically, your added code should: Validate the user course selection for registration against the given registration businessrules 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 enters only integers to select courses for registration from a menu. No data typevalidation of the user menu selection is checked or required Each course carries 3 credit hours 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 methods 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 program prints out a confirmation message. Otherwise, the program prints an error message. In all cases, the program also prints out the current list of registered classes. The program terminates when the user does not want to register for classes any more. The program uses the Java method ValidateChoice() to validate the user integer menu selection and acts accordingly. If the user selection is valid against the registration business rules, the program displays a registration confirmation message to the student for the selected course. Otherwise, the program displays an error message explaining the reason of the invalidation of the selection. The application maintains and displays a current list of registered courses.Use these course codes, in this order, to test your application: IT2230 IT3349 IT2230 IT4782 IT4784 Successful completion of this assignment will display a valid message or an invalid message, with reason, for the selected course code. In addition, the application should display and update current list of registered courses. Your program interaction should look like the sample interaction video in the resources, Console Register for Course Result.

package u6a1_consoleregisterforcourse;

import java.util.Scanner;

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

/** * @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); //choice is the current menu selection //firstChoice is the first menu selection mande by the user //secondChoice is the second menu selection mande by the user //thirdChoice is the third menu selection mande by the user // a choice of 0 means the choice has not been made yet int choice; int firstChoice = 0, secondChoice = 0, thirdChoice = 0; int totalCredit = 0; String yesOrNo = "";

do {

choice = getChoice(input); switch (ValidateChoice(choice, firstChoice, secondChoice, thirdChoice, totalCredit)) { 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 " + ChoiceToCourse(choice) + " 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 " + ChoiceToCourse(choice) ); totalCredit += 3; if (firstChoice == 0) firstChoice = choice; else if (secondChoice == 0) secondChoice = choice; else if (thirdChoice == 0) thirdChoice = choice; break; }

WriteCurrentRegistration(firstChoice, secondChoice, thirdChoice); 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"); }

public static int getChoice(Scanner input) { System.out.println("Please type the number inside the [] to register for a course"); System.out.println("[1]IT4782 [2]IT4784 [3]IT4786 [4]IT4789 [5]IT2230 [6]IT3345 [7]IT3349"); 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 firstChoice, int secondChoice, int thirdChoice, int totalCredit) {

// TO DO - Add Code to: // Validate user menu selection (the int choice method arguement) // against the given registration business rules return 0; } public static void WriteCurrentRegistration(int firstChoice, int secondChoice, int thirdChoice) {

if (firstChoice == 0) System.out.println("Current course registration: { none } " ); else if (secondChoice == 0) System.out.println("Current course registration: { " + ChoiceToCourse(firstChoice) + " }" ); else if (thirdChoice == 0) System.out.println("Current course registration: { " + ChoiceToCourse(firstChoice) + ", " + ChoiceToCourse(secondChoice) + " }"); else System.out.println("Current course registration: { " + ChoiceToCourse(firstChoice) + ", " + ChoiceToCourse(secondChoice) + ", " + ChoiceToCourse(thirdChoice) + " }"); }

public static String ChoiceToCourse(int choice) { String course = ""; switch (choice) { case 1: course = "IT4782"; break; case 2: course = "IT4784"; break; case 3: course = "IT4786"; break; case 4: course = "IT4789"; break; case 5: course = "IT2230"; break; case 6: course = "IT3345"; break; case 7: course = "IT3349"; break; default: break; } return course; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

LO2 Distinguish among three types of performance information.

Answered: 1 week ago