Microsoft Word - Programming Assignment 4_Spring2019.docx CSE1341 - Lab 4 Programming Assignment Arrays, Strings, more practice with multiple methods Assignment Due Saturday, March 23rd, 2019 at 6:00...

1 answer below »
need help


Microsoft Word - Programming Assignment 4_Spring2019.docx CSE1341 - Lab 4 Programming Assignment Arrays, Strings, more practice with multiple methods Assignment Due Saturday, March 23rd, 2019 at 6:00 AM Uploaded to Canvas This assignment will require a Pre-Lab and a Lab. Pre-Lab (10 POINTS) Write a Java program called Speed which does the following: 1. Uses a for loop which repeats 3 times. Within the loop, a. prompt the user to enter a distance in miles and store the distance in a double array called distance b. prompt the user to enter time in hours and store the hours in a double array called hours 2. Calls the method calculateSpeed with the following header public static void calculateSpeed(double[] distance, double[] time) to calculate and display the speed for each distance and time (Hint: speed = distance/time). For completion, make sure that you include the units as shown in the sample output. User input is highlighted in yellow. Bring the working Speed.java and Speed.class files to your lab session for pre-lab credit. Sample output: Enter distance in miles: 180 Enter time in hours: 3 Enter distance in miles: 16 Enter time in hours: 0.75 Enter distance in miles: 268 Enter time in hours: 4.5 The speed for distance = 180.00 miles and time = 3.00 hours is: 60.00 miles/hours The speed for distance = 16.00 miles and time = 0.75 hours is: 21.33 miles/hours The speed for distance = 268.00 miles and time = 4.50 hours is: 59.56 miles/hours Lab (90 POINTS) NOTES: Comment your program to explain your steps. Each program should compile without errors and should run to produce outputs described. The following points will be discounted if the related element is missing or incorrect: • Output formatting monetary amounts (dollar sign and 2 places after the decimal point) [2 points each] • Proper names for classes, variables, and methods [1 point each] • No Comments [5 points] • Program doesn't compile [5 points for each minor error up to 5 errors provided that after fixing the errors the program compiles. If the program does not compiler after the 5 errors are fixed, partial credit will be given not to exceed 50 points] • Source code (java file) missing [ 20 points] • Executable (class file) missing [20 points] • Both java file and class file missing [100 points] • Missing method where a method is required [5 points each] • Missing loop where loop is required [5 points each] • Missing array where array is required [10 points each] • Logical errors in calculation [5 points each] 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 night Two 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 will 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(String[] 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 ---------------------------------------- 1 Morning $500.00 2 Afternoon $600.00 3 Evening $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 displayItineraryArrays() 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 displayItineraryArrays(String[] bookings, double[] 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 -------------------- Morning $500.00 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 returns 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. As always, comment you program well. Here’s a sample output. User input is highlighted in yellow. 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: 6 This option is not acceptable. 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: 3 option 3 Your itinerary is empty. 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: 4 option 4 Total + tax $0.00 Payment accepted.... 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: 5 Canceling bookings... 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: 1 option 1 Number Flights Prices ========================== 1 Morning $500.0 2 Afternoon $600.0 3 Evening $700.0 Please enter a number from the list above or -1 if you wish to redisplay the menu: -1 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: 1 option 1
Answered Same DayMar 22, 2021

Answer To: Microsoft Word - Programming Assignment 4_Spring2019.docx CSE1341 - Lab 4 Programming Assignment...

Pritam answered on Mar 25 2021
147 Votes
MustangTours.class
public synchronized class MustangTours {
static java.util.Scanner sc;
public void MustangTours();
public static int displayMenu();
public static void displayArrays(String[], double[], String);
public static int getNumber();
public static void displayItineraryArrays(String[], double[]);
public static double getTotal(double[]);
public static void clearBookings(String[]);
public static void clearPrices(double[]);
public static void main(String[]);
static void...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here