d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > I Need Help With An Assignment In Java
12Next
Add Reply New Topic New Poll
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Sep 9 2013 04:59pm
Assignment Description:

People want to buy tickets to a Homecoming football game

Requirements
  • Develop a program that displays a menu and instructs a user to enter the category of seats they want to purchase for the homecoming game on Saturday, October 26th (they will choose only one). Number the categories as follows: 1) Student, 2) Alumni, 3) Faculty & Staff, 4) Military, or 5) General Public.
  • If the user makes an invalid selection (not 1-5), display an error message (such as “Invalid Category selected”) and exit the program (since loops are not required).
  • Assuming the user has entered a valid category, ask how many tickets they would like and then ask if they would like to purchase a parking pass (‘Y’ or ‘N’). Accept upper or lower case.
  • Ticket prices are $60 for the general public. Alumni get a 10% discount, Faculty & Staff a 15% discount, Military a 20% discount, and students get tickets for half-price.
  • Calculate and display the total number of tickets requested and the total cost for all tickets. If requested, add $20 for parking.

Example
  • if the user entered 2 for the category (alumni) and 5 for number of tickets with no parking, you would display:
  • You ordered 5 tickets without parking for a total cost of $270
  • If the user entered 1 for the category (student) and 2 for number of tickets with parking, you would display:
  • You ordered 2 tickets with parking for a total cost of $80.

Extra Credit
  • If the user enters an invalid category number, display an error message and LOOP until a valid category number is entered before continuing in your program. (3 pts.)
  • If the user does NOT enter a ‘Y’ or ‘N’ (upper or lower case) to the parking question, display an error message and LOOP until a valid answer (‘Y’ or ‘N’) is entered before continuing in your program. (3 pts.)
  • Add a Loop to ask if they would like to process another order. If so, display the opening menu again and repeat the program until they answer that they do not want to process another order. (4 pts.)
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 9 2013 05:13pm
what part of that do you need help with?
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Sep 9 2013 05:16pm
Quote (carteblanche @ Sep 9 2013 06:13pm)
what part of that do you need help with?


when i make the if statement on what prices go with each number, all is fine. then when i try to make it display the double totalTicketPrice by multiplying ticketPrice and ticketCount together it says that the variable cannot be utilized.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 9 2013 05:39pm
Declare the variable earlier in your code.
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Sep 9 2013 07:20pm
how do i make a display menu?
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Sep 9 2013 08:04pm
i have everything working but the last thing in the extra credit.

I need to ask if the buyer would like to place another order and if answered Y for yes, then the whole program loops, and if answered N for no, then the program terminates.

I also am not sure what he means by make a display menu. I just did a lot of System.out.print statements for all the categories.
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Sep 9 2013 08:12pm
Quote (GetSpanked @ Sep 9 2013 10:04pm)
i have everything working but the last thing in the extra credit.

I need to ask if the buyer would like to place another order and if answered Y for yes, then the whole program loops, and if answered N for no, then the program terminates.

I also am not sure what he means by make a display menu.  I just did a lot of System.out.print statements for all the categories.


to display the menu

Code
System.out.println("1)Student/n2)Alumni/n3)Falcuty & Staff/n4)Military/n5)General Public");


And for the bonus mark put everything inside your main method in a
Code
while(true)
loop. For example..

Code
while(true){

//your code goes here
//...
//...
//...


//then add these lines at the end of the while loop
System.out.println("Start again?");
char answer = new Scanner(System.in).next().charAt(0);

if(answer=='n'||answer=='N'){
System.exit(0);
}
}



for selecting the category...

Code
int category=0;
while(true){
System.out.println("1)Student/n2)Alumni/n3)Falcuty & Staff/n4)Military/n5)General Public");
category = new Scanner(System.in).nextInt();
if(category >5 || category < 1){
System.out.println("Invalid selection");
continue;
}else{
break
}
}


Hope there's no errors. I don't have an IDE installed.



This post was edited by labatymo on Sep 9 2013 08:17pm
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Sep 9 2013 08:22pm
it wont let me send a pm...
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Sep 9 2013 08:54pm
I completed the assignment.

Thanks for the help!
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Sep 10 2013 11:23am
how would i get my code to run in a window rather than the command line?
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll