I need to finish this program in Java. I have a little bit done, but still need
ID: 3813114 • Letter: I
Question
I need to finish this program in Java. I have a little bit done, but still need help finishing most of the classes.
Project Summary
A smaller airport is in need of a system that keeps track of the various airplanes that use their airport. The System would allow the customer to review and reserve seats as well as let the airport staff see various information. The system would have to keep track of all the planes information including: destination, number of seats, depart time & date, arrival time & date, price, flight length, and plane ID. It will also need a user interface that allows the customer to look at all available flights and make the reservation.
This is what I have so far:
**************************************************************************
**********************************************************************************
********************************************************************
*************************************************************************
******************************************************************************
*******************************************************************************
*************************************************************************
*******************************************************************************
public class package-info{
}
Explanation / Answer
package org.airportsystem.model;
import java.util.Date;
public class Airplane {
private String destination;
private int numberOfSeats;
private String departTime;
private Date departDate;
private String arrivalTime;
private Date arrivalDate;
private double price;
private String planeID;
private double flightLength;
private int totalNumberOfBuyers;
public Airplane() {
}
public Airplane(String destination, int numberOfSeats, String departTime,
Date departDate, String arrivalTime, Date arrivalDate,
double price, String planeID, double flightLength) {
super();
this.destination = destination;
this.numberOfSeats = numberOfSeats;
this.departTime = departTime;
this.departDate = departDate;
this.arrivalTime = arrivalTime;
this.arrivalDate = arrivalDate;
this.price = price;
this.planeID = planeID;
this.flightLength = flightLength;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public int getNumberOfSeats() {
return numberOfSeats;
}
public void setNumberOfSeats(int numberOfSeats) {
this.numberOfSeats = numberOfSeats;
}
public String getDepartTime() {
return departTime;
}
public void setDepartTime(String departTime) {
this.departTime = departTime;
}
public Date getDepartDate() {
return departDate;
}
public void setDepartDate(Date departDate) {
this.departDate = departDate;
}
public String getArrivalTime() {
return arrivalTime;
}
public void setArrivalTime(String arrivalTime) {
this.arrivalTime = arrivalTime;
}
public Date getArrivalDate() {
return arrivalDate;
}
public void setArrivalDate(Date arrivalDate) {
this.arrivalDate = arrivalDate;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getPlaneID() {
return planeID;
}
public void setPlaneID(String planeID) {
this.planeID = planeID;
}
public double getFlightLength() {
return flightLength;
}
public void setFlightLength(double flightLength) {
this.flightLength = flightLength;
}
public int getTotalNumberOfBuyers() {
return totalNumberOfBuyers;
}
public void setTotalNumberOfBuyers(int totalNumberOfBuyers) {
this.totalNumberOfBuyers = totalNumberOfBuyers;
}
@Override
public String toString() {
return "Airplane [destination=" + destination + ", numberOfSeats="
+ numberOfSeats + ", departTime=" + departTime
+ ", departDate=" + departDate + ", arrivalTime=" + arrivalTime
+ ", arrivalDate=" + arrivalDate + ", price=" + price
+ ", planeID=" + planeID + ", flightLength=" + flightLength
+ ", totalNumberOfBuyers=" + totalNumberOfBuyers + "]";
}
}
package org.airportsystem.users;
public interface User {
String getUserType();
}
package org.airportsystem.users;
public class AirportStaff implements User {
public String getUserType() {
return "STAFF";
}
}
package org.airportsystem.users;
public class Customer implements User {
public String getUserType() {
return "CUSTOMER";
}
}
package org.airportsystem.business;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import org.airportsystem.model.Airplane;
public class AirportReservationSystem {
Map<String, List<Airplane>> plainListPerDestination = new HashMap<String, List<Airplane>>();
public boolean addNewPlanetoDestination(String destination,
int numberOfSeats, String departTime, Date departDate,
String arrivalTime, Date arrivalDate, double price, String planeID,
double flightLength) {
Airplane a = new Airplane(destination, numberOfSeats, departTime,
departDate, arrivalTime, arrivalDate, price, planeID,
flightLength);
if (this.plainListPerDestination.containsKey(destination)) {
this.plainListPerDestination.get(destination).add(a);
} else {
List<Airplane> flightList = new ArrayList<Airplane>();
flightList.add(a);
this.plainListPerDestination.put(destination, flightList);
}
return true;
}
public void displayAllFlights() {
if (plainListPerDestination.size() == 0) {
System.out.println("No Flights");
} else {
Iterator<String> it = plainListPerDestination.keySet().iterator();
while (it.hasNext()) {
String destination = it.next();
System.out.println("Destination : - "
+ destination
+ "- Plane information : - "
+ this.plainListPerDestination.get(destination)
.toString());
}
}
}
public List<Airplane> listofFLightstoADestination(String destination) {
if (this.plainListPerDestination.containsKey(destination)) {
return this.plainListPerDestination.get(destination);
} else {
return null;
}
}
public Airplane makeReservation(String destination) {
Airplane bookedFlightDetails = null;
Scanner s = null;
if (!this.plainListPerDestination.containsKey(destination)) {
return null;
}
List<Airplane> listofFlightstoTheDest = listofFLightstoADestination(destination);
for (Airplane availableFlights : listofFlightstoTheDest) {
if (availableFlights.getTotalNumberOfBuyers() <= availableFlights
.getNumberOfSeats()) {
System.out.println(availableFlights + " ###### is available ");
s = new Scanner(System.in);
System.out.println("Press Y to book , C to see next option");
String option = s.next();
if ("Y".equalsIgnoreCase(option)) {
availableFlights.setTotalNumberOfBuyers(availableFlights
.getTotalNumberOfBuyers() + 1);
bookedFlightDetails = availableFlights;
System.out.println("Booking confirmed to this flight "
+ bookedFlightDetails);
break;
} else if ("C".equalsIgnoreCase(option)) {
continue;
}
}
}
return bookedFlightDetails;
}
}
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import org.airportsystem.business.AirportReservationSystem;
import org.airportsystem.model.Airplane;
public class DriverClass {
public static void main(String[] args) {
AirportReservationSystem airportSystem = new AirportReservationSystem();
Scanner s = new Scanner(System.in);
while (true) {
System.out.println("Type of User Staff/Customer ,QUit to QUit");
String typeOfUser = s.next();
if ("CUSTOMER".equalsIgnoreCase(typeOfUser)) {
while (true) {
System.out
.println("Do you want to Book a Ticket - Y/N, To Quit Q");
String answer = s.next();
if ("Y".equalsIgnoreCase(answer)) {
System.out.println("Please enter the destination ");
String destination = s.next();
Airplane confirmedPlane = airportSystem
.makeReservation(destination);
if (confirmedPlane == null) {
System.out
.println("Sorry No Flight to this Destination Yet!!");
} else {
System.out.println(confirmedPlane);
}
} else if ("N".equalsIgnoreCase(answer)) {
System.out.println("It was great to see you !!");
} else if ("Q".equalsIgnoreCase(answer)) {
break;
} else {
System.out.println("Invalid Choice");
}
}
} else if ("STAFF".equalsIgnoreCase(typeOfUser)) {
while (true) {
System.out
.println("Hello Staff , You can do the following");
System.out.println("1 - Enter New FLight Details");
System.out.println("2 - see ALl flights");
System.out
.println("3 - see flights to a particular destination");
System.out.println("0 - To Quit");
int choice = s.nextInt();
if (choice == 1) {
System.out.println("Please enter destination");
String destPlace = s.next();
System.out.println("Please enter no Of seats");
int noOfSeats = s.nextInt();
System.out.println("Please enter Departure time");
String deptTime = s.next();
System.out.println("Please enter Departure Date");
Date deptDate = new Date(s.next());
System.out.println("Please enter Arrival time");
String arrvTime = s.next();
System.out.println("Please enter Arrival Date");
Date arrvDate = new Date(s.next());
System.out.println("Please enter price");
double price = s.nextDouble();
System.out.println("Please enter plane ID");
String planeID = s.next();
System.out.println("Please enter Flight Length");
double flightlength = s.nextDouble();
if (airportSystem.addNewPlanetoDestination(destPlace,
noOfSeats, deptTime, deptDate, arrvTime,
arrvDate, price, planeID, flightlength)) {
System.out.println("Flight addded Successfully");
}
} else if (choice == 2) {
airportSystem.displayAllFlights();
} else if (choice == 3) {
System.out
.println("Please enter the destination of your choice");
String dest = s.next();
System.out.println(airportSystem
.listofFLightstoADestination(dest));
} else if (choice == 0) {
break;
} else {
System.out.println("Invalid Choice!");
}
}
} else if ("Quit".equalsIgnoreCase(typeOfUser)) {
break;
} else {
System.out.println("Invalid User !!!!");
}
}
s.close();
}
}