Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Countrywide Tours conducts sightseeing trips for groups from its home base in Io

ID: 3796538 • Letter: C

Question

Countrywide Tours conducts
sightseeing trips for groups from its
home base in Iowa. Create an
application that continuously
accepts tour data, including a
three-digit tour number; the
numeric month, day, and year
values representing the tour start
date; the number of travelers taking
the tour; and a numeric code that
represents the destination. As data is
entered for each tour, verify that the
month, day, year, and destination code
are valid; if any of these is not valid, continue
to prompt the user until valid data is
entered. The valid destination codes are
shown in Table 6-6.
pseudocode for: chapter 6 in programming,design and logic n0 10: Design the logic for an application that
outputs each tour number, validated
start date, destination code, destination
name, number of travelers, gross total
price for the tour, and price for the tour after discount. The gross total price is
the tour price per guest times the number of travelers. The final price includes a
discount for each person in larger tour groups, based on Table 6-7.

Code Destination
Price per
Person ($)
1 Chicago 300.00
2 Boston 480.00
3 Miami 1050.00
4 San Francisco 1300.00
Table 6-6 Countrywide Tours codes and prices

Number of Tourists
Discount per
Tourist ($)
1–5 0
6–12 75
13–20 125
21–50 200
51 and over 300
Table 6-7 Countrywide Tours discounts

Explanation / Answer

import java.util.Calendar;
import java.util.Scanner;
public class Example {
   public static void main(String[] args) {       
       int t_code,date,month,year,no_of_pass,dest,error;
       String dest_name="";
       int discount,cost=0,total_cost,paid_cost,ch;
      
       Scanner in=new Scanner(System.in); // scanner object to read input from keyboard
       Calendar now = Calendar.getInstance(); //creating calander object to get current date
       while(1==1) // to take the input details conntinuously
       {
       System.out.println("enter the 3-digit tour number :");
       t_code=in.nextInt();// read tour number and store it in t_code variable
       do //loop helps in checking the validity of date and prompts to enter date untill correct date is entered
       {
       error=1;
       System.out.println("enter the date month year of journey :");
       date=in.nextInt(); //read date
       month=in.nextInt(); //read month
       year=in.nextInt(); //read year
   //code to check the validity of date entered  
       if(date<=0 ||month<=0 ||year<=0)
       error=0;
       else if(year< now.get(Calendar.YEAR) )// to check whether year is valid
       error=0;
       else if(year==now.get(Calendar.YEAR)&& month<(now.get(Calendar.MONTH) + 1) || month>12) //to check      //month is valid
       error=0;
       else if(year==now.get(Calendar.YEAR)&& month==(now.get(Calendar.MONTH) + 1)&& date<=Calendar.DATE)// to check whether the given date is before the current date
       error=0;
       else if((month==1 || month==3 || month==5 || month==7|| month==8 || month==10 || month==12)&&date>31 )
       error=0;
       else if((month==4 || month==6 || month==9 || month==11)&&date>30 )
       error=0;
       else if(month==2 && date>28)
       error=0;
       if(error==0)
       System.out.println("incorrect date");
       }
       while(error==0);

       do //loop to ask the user to enter no of travellers untill he enters proper number
       {
       error=1;
       System.out.println("Enter the no of travelers taking tour");
       no_of_pass=in.nextInt(); //read the passenger number
       if(no_of_pass<=0)
       error=0;
       if(error==0)
       System.out.println("invalid no of travellers");
       }
       while(error==0);
       do //loop to ask the user to enter destination code untill he enters proper number
       {
           error=1;
       System.out.println("1:Chicago 2:Boston 3.Miami 4.San Francisco enter the code of destination of your tour");
       dest=in.nextInt();
      
       if(dest<1 || dest>4)
       error=0;
       if(error==0)
       System.out.println("invalid destination code");
       }
       while(error==0);
   //depending on code cost per head and destination name are stored to respective variables
       if(dest==1)
       {dest_name="Chicago";
       cost=300;
       }
       else if(dest==2)
       {
       dest_name="Boston";
       cost=480;
       }
       else if(dest==3)
       {
       dest_name="Miami";
       cost=1050;
       }
       else if(dest==4)
       {
       dest_name="San_Francisco";
       cost=1300;
       }
//discount calculated based on no of travellers
       if(no_of_pass<5)
       discount=0;
       else if(no_of_pass<13)
       discount=no_of_pass*75;
       else if(no_of_pass<21)
       discount=no_of_pass*125;
       else if(no_of_pass<51)
       discount=no_of_pass*200;
       else
       discount=no_of_pass*300;
       total_cost=no_of_pass*cost; // total cost is cost per head * no of travelers
       paid_cost=total_cost-discount; //amount to be paid is total cost -discount
      
//printing output      
       System.out.println(" tour number:"+t_code);
       System.out.println("Date of Journey: "+date+"-"+month+"-"+year);
       System.out.println("Destination code is: "+dest);
       System.out.println("Destination is: "+dest_name);
       System.out.println("Total number of travellers: "+no_of_pass);
       System.out.println("Gross total:$"+total_cost);
       System.out.println("Total to be paid after discount: $"+paid_cost);
//to check whether to ask for next tour details      
       System.out.println("do you want to enter details of another tour(1:yes(or)2:no) enter appropriate number:") ;
       ch=in.nextInt();
       if(ch==2)
       break;
       }

   }

}

Sample Output:

enter the 3-digit tour number :
257
enter the date month year of journey :
12 06 2016
incorrect date
enter the date month year of journey :
12 06 2017
Enter the no of travelers taking tour
0
invalid no of travellers
Enter the no of travelers taking tour
53
1:Chicago
2:Boston
3.Miami
4.San Francisco
enter the code of destination of your tour
5
invalid destination code
1:Chicago
2:Boston
3.Miami
4.San Francisco
enter the code of destination of your tour
3


tour number:257
Date of Journey: 12-6-2017
Destination code is: 3
Destination is: Miami
Total number of travellers: 53
Gross total:$55650
Total to be paid after discount: $39750
do you want to enter details of another tour(1:yes(or)2:no)
enter appropriate number:
1
enter the 3-digit tour number :
234
enter the date month year of journey :
14 9 2019
Enter the no of travelers taking tour
34
1:Chicago
2:Boston
3.Miami
4.San Francisco
enter the code of destination of your tour
4


tour number:234
Date of Journey: 14-9-2019
Destination code is: 4
Destination is: San_Francisco
Total number of travellers: 34
Gross total:$44200
Total to be paid after discount: $37400
do you want to enter details of another tour(1:yes(or)2:no)
enter appropriate number:
2