Question

In this lab, you will create a program to help travelers book flights and hotel stays that will behave like an online bookinghotelStays One nightTwo nights Three nights hotelStaysPrices 100.00 240.00 390.00 Moreover, you will implement the itineraryThen, within a loop, if the user enters an option that is not 1, 2, 3, 4, 5 or 9, display the message This option is not accFollowing the call to displayArrays(), call the method getNumber() public static int getNumber() The method should ask the usBookings Prices $500.00 Morning One night 100.00 Total + tax $649.50 If the arrays are empty display your itinerary is emptyIf option 5 is selected, call the clearBookings () and clearPrices() methods and pass them the bookings and prices arrays, re

In this lab, you will create a program to help travelers book flights and hotel stays that will behave like an online booking website. The description of the flights and hotel stays will be stored in two separate String arrays. In addition, two separate arrays of type double will be used to store the prices corresponding to each description. You will create the arrays and populate them with data at the beginning of your program. This is how the arrays will look like flights Morning Afternoon Evening flightsPrices 500.00 600.00 700.00
hotelStays One nightTwo nights Three nights hotelStaysPrices 100.00 240.00 390.00 Moreover, you will implement the itinerary as two arrays of length 2 each. The first array, called bookings, will store the description of the flight and hotel stay the user wishes to book. The second array, called prices, will contains the corresponding prices. The user will book one flight and one hotel stay that's why these arrays have a length of 2. After you create and initialize all the arrays, the program should then display a menu for the user by calling the method displayMenu(). The method will display the following lines when called and wil return the option the user enters: Welcome to Mustang Tours Choose from the following menu options: 1) Browse Flights and add booking to itinerary 2) Browse Hotel Stays and add booking to itinerary 3) View itinerary 4) Display total and pay 5) Cancel bookings 9) Exit Enter option:
Then, within a loop, if the user enters an option that is not 1, 2, 3, 4, 5 or 9, display the message "This option is not acceptable" and loop back to redisplay the menu. Continue in this manner until a correct option is input. If option 1 or 2 is entered, call the method displayArrays() with the following signature: displayArrays(Stringl] descriptionsArray, double[] pricesArray, String name); to display the available flights or hotel stays and their prices. You should pass the correct two arrays and a String ("Flights" or "Hotel Stays") to the method as shown above depending on which option gets selected. The method should display the arrays in the following format by looping over the arrays (the Flights and their prices are used here as the example; the same formatting applies to Hotel Stays): Number Flights Prices 2 3 Morning Afternoon Evening $500.00 $600.00 $700.00
Following the call to displayArrays(), call the method getNumber() public static int getNumber() The method should ask the user to enter the number for the flight or hotel stay they wish to book and -1 if they wish to redisplay the menu and not select a booking. Then the method will get the number entered by the user and return it. You can take the number which the method getNumber() returns and subtract 1 from it to get the correct index into the array. Use the index to retrieve the description and its corresponding price, and then assign them to the itinerary arrays bookings and prices, respectively. The above discussion applies for option 2 as well. For simplicity, a flight and its corresponding price will be stored at index 0, and a hotel stay and its corresponding price will be stored at index 1 If option 3 is selected, call the displayltineraryArrays() method to accept the bookings and prices arrays and display the itinerary similar to the way you have displayed the available flights and hotel stays. public static void displayltineraryArrays(String[] bookings, double[l prices) Here is how the output should look like format-wise (you can call the getTotal() method to get the current total, see option 4 below):
Bookings Prices $500.00 Morning One night 100.00 Total + tax $649.50 If the arrays are empty display "your itinerary is empty" followed by the menu. To check if an array is empty, check the value of each array element. In the case of the bookings String array, check if the value at each index is null (e.g. bookings[0]null && bookings[1] null). In case of the prices double array, check if each value is 0 Note: Only display a booking if its description is not null. If option 4 is selected, call the method getTotal() which accepts as input, the array prices and return:s the total by looping over prices and calculating the total. public static double getTotal(double[] prices) Make sure you also add an 8.25% tax to the total. Display the total for the user and clear the arrays by calling the clearBookings () and clearPrices() methods (see option 5).
If option 5 is selected, call the clearBookings () and clearPrices() methods and pass them the bookings and prices arrays, respectively. public static void clearBookings(String[] bookings) public static void clearPrices(double[] prices) In these methods, you will "clear" the arrays by setting each element at each index to either null or 0.0 depending on the type of the array. You will use a loop to accomplish this. Continue this looping until option 9 is selected. When option 9 is entered, end the program
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Answer:-

Code:-

import java.util.*;
class Flight{
   static Scanner sc = new Scanner(System.in);
   public static void displayArrays(String a[],double p[],String s){
       // displaying description in given arrays
       System.out.printf("\n%-13s%-15s%-10s\n","Number",s,"Prices");
       System.out.println("==================================");
       for(int i=0;i<a.length;i++){
           System.out.printf("%-13d%-15s%-10.2f\n",i+1,a[i],p[i]);
       }
       System.out.println();
   }
   public static int getNumber(){
       //read input and return
       return (sc.nextInt());
   }
   public static void displayitineraryArrays(String d[],double p[]){
       // displaying description in given arrays,if list empty display empty message
       if(d[0]==null){
           System.out.println("\nYour itinerary list is empty");
       }else{
           System.out.printf("\n%-15s%-10s\n","Bookings","Prices");
           System.out.println("------------------------");
           for(int i=0;i<d.length;i++){
               System.out.printf("%-15s%-10.2f\n",d[i],p[i]);
           }
           System.out.println("------------------------");
           double s =getTotal(p) + (getTotal(p)*0.0825);
           System.out.printf("%-15s%-10.2f\n","Total + tax",s);
           System.out.println();
       }
   }
   public static double getTotal(double p[]){
       double s = 0;
       for(int i=0;i<p.length;i++)
           s += p[i];
       return s;
   }
   public static void clearBookings(String a[]){
       for(int i=0;i<a.length;i++)
           a[i] = null;
   }
   public static void clearPrices(double a[]){
       for(int i=0;i<a.length;i++)
           a[i] = 0;
   }
   public static void main(String[] args) {
       String flights[] = {"Morning","Afternoon","Evening"};
       double flightPrices[] = {500.00,600.00,700.00};
       String hotelStays[] = {"One night","Two nights","Three nights"};
       double hotelStaysPrices[] = {100.00,240.00,390.00};
       int n;
       String bookings[] = new String[2];
       double prices[] = new double[2];
       do{
           //Menu
           System.out.println("\n Welcome to Mustang Tours");
           System.out.println("1) Browse Flights and add booking to itinerary");
           System.out.println("2) Browse Hotel Stays and add booking to itinerary");
           System.out.println("3) View itinerary");
           System.out.println("4) Display total and pay");
           System.out.println("5) Cancel bookings");
           System.out.println("9) Exit");
           System.out.print("Enter option: "); //Ask user to enter option
           n = sc.nextInt();
           switch (n) {
               case 1:
                   displayArrays(flights,flightPrices,"Flights");
                   System.out.print("Enter option(-1 to go to menu): ");
                   int i = getNumber();
                   if(i!=-1){
                       bookings[0] = flights[i-1];
                       bookings[1] = hotelStays[i-1];
                       prices[0] = flightPrices[i-1];
                       prices[1] = hotelStaysPrices[i-1];
                   }
                   break;
               case 2:
                   displayArrays(hotelStays,hotelStaysPrices,"Hotel Stays");
                   System.out.print("Enter option(-1 to go to menu): ");
                   int j = getNumber();
                   if(j!=-1){
                       bookings[0] = flights[j-1];
                       bookings[1] = hotelStays[j-1];
                       prices[0] = flightPrices[j-1];
                       prices[1] = hotelStaysPrices[j-1];
                   }
                   break;
               case 3:
                   displayitineraryArrays(bookings,prices);
                   break;
               case 4:
                   System.out.println(getTotal(prices));
                   break;
               case 5:
                   clearBookings(bookings);
                   clearPrices(prices);
                   break;
               case 9:
                   System.out.println("Thank You...");
                   break;
               default:
                   System.out.println("Please enter valid option");
           }
       }while(n!=9);
   }
}

Output:-

C: \Users\Bhanu Logan\Desktop>javac Flight.java C: \Users\Bhanu Logan\Desktop>java Flight Welcome to Mustang Tours 1) Browse

Welcome to Mustang Tours 1) Browse Flights and add booking to itinerary 2) Browse Hotel Stays and add booking to itinerary 3)

Add a comment
Know the answer?
Add Answer to:
In this lab, you will create a program to help travelers book flights and hotel stays that will b...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Question Question 3 [43] The Question: You are required to write a program for an...

    C++ Question Question 3 [43] The Question: You are required to write a program for an Online Tutoring Centre to determine the weekly rate depending on the number of sessions the students attend and then to calculate total revenue for the center. The Online Tutoring Centre charges varying weekly rates depending on the on grade of the student and number of sessions per week the student attends as shown in Table 1 below. Grade 8 9 Session 1 75 80...

  • making a file You are tasked with creating a text-based program for storing data on Hotel...

    making a file You are tasked with creating a text-based program for storing data on Hotel Room Bookings - however, as this is a comparative languages course, you will be creating the same application in the following three programming languages: • Java, • Python, and • Lisp As you implement the application in each language you should keep notes on: - The features of the languages used, - Which features you found useful, and - Any issues or complications which...

  • This project will allow you to practice with one dimensional arrays, function and the same time...

    This project will allow you to practice with one dimensional arrays, function and the same time review the old material. You must submit it on Blackboard and also demonstrate a run to your instructor. General Description: The National Basketball Association (NBA) needs a program to calculate the wins-losses percentages of the teams. Write a complete C++ program including comments to do the following: Create the following: •a string array that holds the names of the teams •an integer array that...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • In this lab, you will create one class named ArrayFun.java which will contain a main method...

    In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...

  • public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...

    public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...

  • C++ Create an array-based implementation of a stack. Each element of the stack should store a...

    C++ Create an array-based implementation of a stack. Each element of the stack should store a string. The stack class should include 3 private member variables (maximum stack size, top of the stack index, and a pointer to the array that holds the stack elements). Public member methods should include a constructor (with an argument of stack maximum size that is used to create a dynamic array), a destructor (that deletes the dynamic array), a push method (argument is a...

  • Using Java In this assignment we are working with arrays. You have to ask the user...

    Using Java In this assignment we are working with arrays. You have to ask the user to enter the size of the integer array to be declared and then initialize this array randomly. Then use a menu to select from the following Modify the elements of the array. At any point in the program, if you select this option you are modifying the elements of the array randomly. Print the items in the array, one to a line with their...

  • Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and...

    Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and use a 2D array Student will demonstrate the ability to create and use a jagged array Student will demonstrate the ability to design a menu system Student will demonstrate the ability to think Program Specifications: Write a program that does the following: Uses a menu system Creates an array with less than 25 rows and greater than 5 rows and an unknown number of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT