These are my program requrements:
1. Create a program that asks the user to choose a number from 1 - 5.
2. Using a switch statement, assign a vacation package to each number.
3. Display a congratulations message which includes the vacation package information.
4. Display a message to prompt the user to enter the first name, last name, and age of four guests using a for loop which will create a list of the four guests.
5. Prompt the user to enter a departure date.
6. Display the congratulations message, guest list, and the departure date.
I have been able to do steps 1 - 4 but have been unable to correctly program steps 5 - 6. The problems I am having are listed in order below.
5. I can't figure out how to get the entire departure date to print out i.e. "July 1, 2013". Instead it only prints out "July".
6. I can't figure out how to get the congratulations message from the switch statement to be displayed a second time at the end of my code.
So far my code is as follows:
import java.util.Scanner; public class MidTerm { public static void main(String[]args) { Scanner keyboard = new Scanner(System.in); String vacationNumber; int count; String guest; String fName; String lName; String age; String list = ""; String date; //************************************************* System.out.print("Enter a number between 1 - 5 "); vacationNumber = keyboard.nextLine(); switch (vacationNumber.charAt (0)) { case '1': System.out.println("Congragulations! You won a three day Cruise to the Bahamas!"); break; case '2': System.out.println("Congragulations! You won a three day Cruise to the Caribbean!"); break; case '3': System.out.println("Congragulations! You won a three day trip to New York City!"); break; case '4': System.out.println("Congragulations! You won a three day trip to Hawaii!"); break; case '5': System.out.println("Sorry! You won a four month trip to Afghanistan!"); break; } for(count = 1; count <= 4; count++) { System.out.print("Enter the first name of guest # " + count +":"); fName = keyboard.next(); list = list + fName + "\t"; System.out.println(); System.out.print("Enter the last name of guest # " + count +":"); lName = keyboard.next(); list = list + lName + "\t"; System.out.println(); System.out.print("Enter the age of guest # " + count +":"); age = keyboard.next(); list = list + age + "\n"; System.out.println(); } System.out.print("Please enter a departure date"); date = keyboard.next(); System.out.print(list + "\n"); System.out.print(date); } }