In: Computer Science
IN JAVA
Frank wants to take his wife, son, and daughter on a vacation next summer.
This program will prompt Frank to choose a number between 1 and 6.
Use a switch…case to determine which number he chose.
1 - Hawaii – 7 days / 6 nights
2 - New York – 3 days / 2 nights
3 - London – 7 days / 6 nights
4 - Bahamas – 7 days / 6 nights
5 - Miami – 3 days / 2 nights
6 - Los Angeles – 3 days / 2 nights
The default will be: Stay Home – 7 days / 6 nights
Use a Do…while loop to return to the prompt if the number is <1 and >6.
Create a message that tells Frank about his vacation he chose.
Use a for loop to create a list when Frank enters his first name, last name, and age,
then enters the same for his wife, son, and daughter.
Frank Last Age
Wife “ “
Son “ “
Daughter “ “
Prompt Frank to input the departure date of his vacation.
The final output should be in the following format:
Congratulations! You and your family are going to “location”
Frank Last Age
Wife “ “
Son “ “
Daughter “ “
Your departure date is “date”
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String location="";
int choice;
do
{
System.out.println("Choose a number between 1 and 6\n1 - Hawaii – 7
days / 6 nights\n2 - New York – 3 days / 2 nights\n3 - London – 7
days / 6 nights\n4 - Bahamas – 7 days / 6 nights\n5 - Miami – 3
days / 2 nights\n6 - Los Angeles – 3 days / 2 nights\nThe default
will be: Stay Home – 7 days / 6 nights");
choice = sc.nextInt();
switch (choice)
{
case 1:
location="Hawaii – 7 days / 6 nights";
break;
case 2:
location="New York – 3 days / 2 nights";
break;
case 3:
location="London – 7 days / 6 nights";
break;
case 4:
location="Bahamas – 7 days / 6 nights";
break;
case 5:
location="Miami – 3 days / 2 nights";
break;
case 6:
location="Los Angeles – 3 days / 2 nights";
break;
default:
location="Stay Home – 7 days / 6 nights";
break;
}
}while(choice<1||choice>7);
String message="Congratulations! You and your family
are going to "+location;
String[] fName=new String[4];
String[] lName=new String[4];
int[] age=new int[4];
String[] temp={"your's","your wife's","your
son's","your daghter's"};
for(int i=0;i<4;i++)
{
System.out.print("Enter "+temp[i]+" first name:
");
fName[i]=sc.next();
System.out.print("Enter "+temp[i]+" last name:
");
lName[i]=sc.next();
System.out.print("Enter "+temp[i]+" age: ");
age[i]=sc.nextInt();
}
System.out.print("Enter the departure date of his
vacation: ");
String date=sc.next();
System.out.println("\n\n"+message+"\nFirst Name\tlast
Name\tAge");
for(int i=0;i<4;i++)
{
System.out.println(fName[i]+"\t\t"+lName[i]+"\t\t"+age[i]);
}
System.out.println("Your departure date is
"+date);
}
}