Question
Answer car Reservation application in exercise 25.15.
Explanation / Answer
import java.util.Scanner; import java.util.ArrayList; public class bookingtester1 { public static void main(String[]args) { String name, addy, number, car; int adults, kids, seniors; String date, time, origin, destination; int selection; int i=1; Scanner in= new Scanner(System.in); String sentinal= "exit"; System.out.println("To create booking Enter 1, Find booking enter 2 "); System.out.println(", Exit enter 3"); selection=in.nextInt(); ArrayList bookingList= new ArrayList(); while(i==1) { switch(selection) { case 1: System.out.println("Please enter your name:"); name= in.nextLine(); System.out.println("Please enter your address:"); addy= in.nextLine(); System.out.println("Please enter your telephone number:"); number= in.nextLine(); System.out.println("Please enter your if you would like to bring your car"+ "(yes/no):"); car= in.nextLine(); System.out.println("Please enter how many adults will be travelling:"); adults= in.nextInt(); System.out.println("Please enter how many seniors will be travelling:"); seniors= in.nextInt(); System.out.println("Please enter how many children are travelling:"); kids= in.nextInt(); passenger myPassenger = new passenger(name, addy, number, car, adults, kids, seniors); System.out.println("Please enter the date your looking to travel:"); date= in.nextLine(); System.out.println("Please enter the time of day the ferry leaves:"); time= in.nextLine(); System.out.println("Please enter where you will be meeting the ferry:"); origin= in.nextLine(); System.out.println("Please enter where you are travelling to:"); destination= in.nextLine(); trip myTrip = new trip(date, time, origin, destination); booking myBooking = new booking(myPassenger, myTrip); bookingList.add(myBooking); break; case 2: i=2; break; case 3: System.out.println("Please enter The name for the reservation"); String target= in.nextLine().toUpperCase; while(i0) 49 { 50 total=total+k; 51 } 52 if(adultsCost>0) 53 { 54 total=total+a; 55 } 56 if(seniorsCost>0) 57 { 58 total=total+s; 59 } 60 if(carCost>0) 61 { 62 total=total+c; 63 } 64 total=total+" "+"The total cost of the booking is: "+totalCost; 65 return total; 66 } 67 } or import java.util.*; class Car { private String make; private String model; private String regNo; private int deposit; private int rate; public Car(String newMake, String newModel, String newRegNo, int newDeposit, int newRate) { make = newMake; model = newModel; regNo = newRegNo; deposit = newDeposit; rate = newRate; } public String getMake() { return make; } public String getModel() { return model; } public String getRegNo() { return regNo; } public int getDeposit() { return deposit; } public int getRate() { return rate; } } public class TestProject { public static void main(String args[]) { List carlist = new ArrayList(); carlist.add(new Car("Toyota", "Altis", "SJC2456X", 100, 60)); carlist.add(new Car("Toyota", "Vios", "SJG9523B", 100, 50)); carlist.add(new Car("Nissan", "Latio", "SJB7412B", 100, 50)); carlist.add(new Car("Murano", "SJC8761M", "Nissan", 300, 150)); carlist.add(new Car("Honda", "Jazz", "SJB4875N", 100, 60)); carlist.add(new Car("Honda", "Civic", "SJD73269C", 120, 70)); carlist.add(new Car("Honda", "Stream", "SJL5169J", 120, 70)); carlist.add(new Car("Honda", "Odyssey", "SJB3468E", 200, 150)); carlist.add(new Car("Subaru", "WRX", "SJB8234L", 300, 200)); carlist.add(new Car("Subaru", "Imprezza", "SJE8234K", 150, 80)); Scanner input = new Scanner(System.in); System.out.print("Enter model to rent: "); String model = input.nextLine(); for (Car s : carlist) { if (model.equals(s.getModel())) { System.out.println("Model " + model + " is available"); System.out.print("Enter number of days: "); int days = input.nextInt(); System.out.println("***************Details*****************"); int cost = (days * s.getRate()) + s.getDeposit(); System.out.println("Deposit DailyRate Duration TotalCost"); System.out.println(s.getDeposit() + " " + s.getRate()+ " " + days + " " + cost); System.out.print("Proceed to rent?( y/n ): "); String dec = input.next(); if (dec.equals("y")) { System.out.println("Enter Customer Name: "); String name = input.next(); System.out.println("Enter IC Number: "); int num = input.nextInt(); System.out.println("************Receipt*************"); System.out.println("Name ICNo Car RegNo Duration TCost"); System.out.println(name + " " + num + " " + model + " " + s.getRegNo() + " " + days + " "+cost); System.out.println("Serving Next Customer "); } else if (dec.equals("n")) { System.out.println("Serving Next Customer: "); } } } } }