Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me code the following in JAVA Please read the task thoroughly, and include many COMMENTS so I can understand! Full points will be

Please help me code the following in JAVA

Please read the task thoroughly, and include many COMMENTS so I can understand!

Full points will be awarded, thanks in advance!

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed BoatDriver class:

/*

* Driver for Boat Reservation system

* Reads input file and prints reservations to console

*/

public class BoatDriver {

public static void main(String[] args) {

ResManager manager = new ResManager();

try {

Scanner scanner = new Scanner(new FileInputStream("boatFile.txt"));

while (scanner.hasNext())

{

manager.addReservable(new Boat(scanner));

}

} catch (FileNotFoundException e) {

System.out.println("file not found");

System.exit(0);

}

System.out.println();

BoatReservation r1 = new BoatReservation(2, "Chen family");

r1.addBoatPreference("kayak");

r1.addBoatPreference("zodiak");

r1.addBoatPreference("canoe");

manager.makeReservation(r1);

BoatReservation r2 = new BoatReservation(8, "Singh party");

r2.addBoatPreference("speedboat");

r2.addBoatPreference("zodiak");

r2.addBoatPreference("submarine");

manager.makeReservation(r2);

r2 = new BoatReservation(8, "Kal");

r2.addBoatPreference("dinghy");

r2.addBoatPreference("yacht");

r2.addBoatPreference("rowboat");

manager.makeReservation(r2);

r2 = new BoatReservation(8, "Party9");

r2.addBoatPreference("speedboat");

r2.addBoatPreference("zodiak");

r2.addBoatPreference("submarine");

manager.makeReservation(r2);

r2.addBoatPreference("speedboat");

r2.addBoatPreference("zodiak");

r2.addBoatPreference("submarine");

r2 = new BoatReservation(2, "Newmans");

r2.addBoatPreference("speedboat");

r2.addBoatPreference("zodiak");

r2.addBoatPreference("submarine");

manager.makeReservation(r2);

r2 = new BoatReservation(3, "Party2");

r2.addBoatPreference("speedboat");

r2.addBoatPreference("zodiak");

r2.addBoatPreference("submarine");

manager.makeReservation(r2);

r2 = new BoatReservation(9, "Party5");

r2.addBoatPreference("speedboat");

r2.addBoatPreference("zodiak");

r2.addBoatPreference("submarine");

manager.makeReservation(r2);

r2 = new BoatReservation(1, "Party6");

r2.addBoatPreference("aircraft carrier");

r2.addBoatPreference("zodiak");

r2.addBoatPreference("submarine");

manager.makeReservation(r2);

r2 = new BoatReservation(3, "Party3");

r2.addBoatPreference("speedboat");

r2.addBoatPreference("zodiak");

r2.addBoatPreference("submarine");

manager.makeReservation(r2);

// Force failure

r2 = new BoatReservation(3, "Unlucky party");

r2.addBoatPreference("zodiak");

manager.makeReservation(r2);

System.out.println(" reservations before sort by customer");

System.out.println(manager);

System.out.println(" reservations after sort by customer");

manager.sortReservations();

System.out.println(manager);

}

} RestaurantDriver class:

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.util.Scanner;

/*

* Driver for Restaurant Reservations

*/

public class RestaurantDriver {

public static void main(String[] args) {

ResManager

manager = new ResManager
();

try {

Scanner scanner = new Scanner(new FileInputStream("tableFile.txt"));

while (scanner.hasNext())

{

manager.addReservable(new Table(scanner));

}

} catch (FileNotFoundException e) {

System.out.println("file not found");

System.exit(0);

}

//manager.printItems(); // debugging code, prints list of Tables

RestaurantReservation r1 = new RestaurantReservation(2, 3, "Chen family");

manager.makeReservation(r1);

RestaurantReservation r2 = new RestaurantReservation(8, 4, "Singh party");

manager.makeReservation(r2);

r2 = new RestaurantReservation(8, 4, "Kal");

manager.makeReservation(r2);

r2 = new RestaurantReservation(8, 4, "business1");

manager.makeReservation(r2);

RestaurantReservation r3 = new RestaurantReservation(2, 2, "Newmans");

manager.makeReservation(r3);

r2 = new RestaurantReservation(11, 4, "TooBig");

manager.makeReservation(r2);

r2 = new RestaurantReservation(10, 4, "party5");

manager.makeReservation(r2);

r3 = new RestaurantReservation(10, 4, "party6");

manager.makeReservation(r3);

r3 = new RestaurantReservation(10, 4, "overflow");

manager.makeReservation(r3);

System.out.println("Listing of reservations:");

System.out.println(manager);

System.out.println(" Sorted reservations");

manager.sortReservations();

System.out.println(manager);

}

} boatFile.txt:

kayak

rowboat

submarine

yacht

speedboat

aircraft carrier

pedalboat

canoe

zodiak

dinghy

tableFile.txt:

table1 6

table2 2

table3 4

table4 4

table5 8

table6 8

table7 10

table8 10

table9 2

table10 4

table11 4

Overview You are to write a general-purpose reservation system. You will then extend this system to be able to reserve Tables in a Restaurant, and to reserve Boats with boat rental company. In all three cases (Base system, Restaurant system, and Boat Rental system) you will read in the resources to reserve from provided files: A list of tables and how many people they seat, and a list of boats. I will provide these files, names tables.txt and boats.txt. Additionally, you will provide two Driver classes (one for each derived system) that will read in the data files, allow the user to make reservations, and to print out various information about the state of the system. You will be provided with a skeleton driver Reservation are made for a time slot, identified only by its position in the array of time slots. Each type of Reservable has different criteria for choosing the best fit. Similarly, the user enters different data as part of the reservation request. For a table, the user indicates how many people are in the party, and the table must have at least that many seats. For the boat, the user gives a list of boats, ordered by preference, and the best fit is the first on the list that has the requested time slot open. The Base System The base system will contain three classes. Reservableltem -repsents an item that can be reserved Reservation represents a request to the system to reserve an item for a specific time slot if the reservation is successful it will know what Reservable it matched with ResManager- a manager that holds a list of Reservables, and a list of Reservations Overview You are to write a general-purpose reservation system. You will then extend this system to be able to reserve Tables in a Restaurant, and to reserve Boats with boat rental company. In all three cases (Base system, Restaurant system, and Boat Rental system) you will read in the resources to reserve from provided files: A list of tables and how many people they seat, and a list of boats. I will provide these files, names tables.txt and boats.txt. Additionally, you will provide two Driver classes (one for each derived system) that will read in the data files, allow the user to make reservations, and to print out various information about the state of the system. You will be provided with a skeleton driver Reservation are made for a time slot, identified only by its position in the array of time slots. Each type of Reservable has different criteria for choosing the best fit. Similarly, the user enters different data as part of the reservation request. For a table, the user indicates how many people are in the party, and the table must have at least that many seats. For the boat, the user gives a list of boats, ordered by preference, and the best fit is the first on the list that has the requested time slot open. The Base System The base system will contain three classes. Reservableltem -repsents an item that can be reserved Reservation represents a request to the system to reserve an item for a specific time slot if the reservation is successful it will know what Reservable it matched with ResManager- a manager that holds a list of Reservables, and a list of Reservations

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions