Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A new term in school is coming up and I am ready to register for my courses that I would like to take for the

A new term in school is coming up and I am ready to register for my courses that I would like to take for the coming semester. They told me to use this program to register for my course so I am going to give it a try.

I would like to learn more about databases and I heard the IT2230 is really a great class so I would like to register for this class so I enter 5 and so it confirmed that I entered the correct class, IT2230, and it gives me a list of the courses that I registered for so far. It asked me if I wanted to register for another class. I say yes, I would like to register for the Intermediate Java Programming class. I would like to expand my java skills so I select that course, and oops, I made a mistake. It says that the selection of 8 is not a recognized course, I should have entered a 7, not an 8, so yes, I wanted to register for one more course and this time I enter the right number, 7, and it confirms that I register for IT3349 and it gives me an expanded list of the course I registered, I registered for two courses so far. I would like to register for a third class and I wanted to apply my java skills to more than desk top applications. I wanted to get into the mobile development so I would like to register for the 4782 course, so I enter the number associated with that oh, it tells me that I already registered for IT3349, but yeah, this is not the course I wanted to register for. Oh, I think I entered the wrong number. I needed to enter 1 to register for the IT4782. So, I say yes, I would like to register for one more class and this time I enter 1 and it tells me that that is confirmed and I'm registered for the three courses I wanted. The IT2230, the IT3349, and the IT4782.

Do I want to register for another class? Just for the sake of it, let's says yes, and let me register for the advanced, or the follow up for the mobile class, which is the 4784 and it tells me I cannot register for more than 9 credit hours and that is true because I cannot really carry more than three courses per term, so I am done with my registration and I registered for the three classes that I wanted to register for, so I will just type no.

Here is the source that doesn't compile. Some pointers on where to look for the fix would be awesome.

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ 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

More Books

Students also viewed these Databases questions

Question

1. What is the size of our competitors marketing budgets?

Answered: 1 week ago

Question

Is rehearsal a useful tool? How or how not?

Answered: 1 week ago