Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
Microsoft Word - Programming Assignment 4_Spring2019.docx
CSE1341 - Lab 4 Programming Assignment
A
ays, 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 a
ay
called distance
. prompt the user to enter time in hours and store the hours in a double a
ay 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 = XXXXXXXXXXmiles 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 = XXXXXXXXXXmiles 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 e
ors and
should run to produce outputs described. The following points will be discounted if the related element
is missing or inco
ect:
• 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 e
or up to 5 e
ors provided that after
fixing the e
ors the program compiles. If the program does not compiler after the 5 e
ors
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 a
ay where a
ay is required [10 points each]
• Logical e
ors 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 a
ays. In addition,
two separate a
ays of type double will be used to store the prices co
esponding to each description.
You will create the a
ays and populate them with data at the beginning of your program. This is how
the a
ays will look like:
flights
Morning Afternoon Evening

flightsPrices
XXXXXXXXXX

hotelStays
One night Two nights Three nights

hotelStaysPrices
XXXXXXXXXX

Moreover, you will implement the itinerary as two a
ays of length 2 each. The first a
ay, called
ookings, will store the description of the flight and hotel stay the user wishes to book. The second
a
ay, called prices, will contains the co
esponding prices. The user will book one flight and one hotel
stay that’s why these a
ays have a length of 2.
After you create and initialize all the a
ays, 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
eturn 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 co
ect
option is input.
If option 1 or 2 is entered, call the method displayA
ays() with the following signature:
displayA
ays(String[] descriptionsA
ay, double[] pricesA
ay, String name);
to display the available flights or hotel stays and their prices. You should pass the co
ect two a
ays and
a String (“Flights” or “Hotel Stays”) to the method as shown above depending on which option gets
selected. The method should display the a
ays in the following format by looping over the a
ays (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 displayA
ays(), 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
co
ect index into the a
ay. Use the index to retrieve the description and its co
esponding price, and
then assign them to the itinerary a
ays bookings and prices, respectively.
The above discussion applies for option 2 as well.
For simplicity, a flight and its co
esponding price will be stored at index 0, and a hotel stay and its
co
esponding price will be stored at index 1.
If option 3 is selected, call the displayItineraryA
ays() method to accept the bookings and prices a
ays
and display the itinerary similar to the way you have displayed the available flights and hotel stays.
public static void displayItineraryA
ays(String[] bookings, double[] prices)
Here is how the output should look like format-wise (you can call the getTotal() method to get the
cu
ent total, see option 4 below):
Bookings Prices
--------------------
Morning $500.00
One night $100.00
--------------------
Total + tax $649.50

If the a
ays are empty display “your itinerary is empty” followed by the menu. To check if an a
ay is
empty, check the value of each a
ay element. In the case of the bookings String a
ay, check if the value
at each index is null (e.g. bookings[0] == null && bookings[1] == null). In case of the prices double a
ay,
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 a
ay 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 a
ays 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 a
ays, respectively.
public static void clearBookings(String[] bookings)
public static void clearPrices(double[] prices)
In these methods, you will “clear” the a
ays by setting each element at each index to either null or 0.0
depending on the type of the a
ay. 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 Day Mar 22, 2021

Solution

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 displayA
ays(String[], double[], String);
public static int getNumber();
public static void displayItineraryA
ays(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