I need a simple interface for this program: It is about booking a ticket online.
ID: 3833174 • Letter: I
Question
I need a simple interface for this program:
It is about booking a ticket online.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
public class Main {
public static void main(String[] args) {
//Customer
// List<Customer> customers = new ArrayList<Customer>();
// Customer c = new Customer();
// customers.add(c);
//Scanner input = new Scanner(System.in);
System .out.println("Welcome to IIUM Airline");
int classNeeded = 1;
int[][] firstArr = new int[2][10];
int i,j;
char s='A';
System.out.println(" 1 2 3 4 5 6 7 8 9 10");
for(i=0;i<2;i++)
{
System.out.print(s+" ");
s++;
for(j=0;j<10;j++)
{
if(j==3 || j==7)
System.out.print(" ");
switch(classNeeded)
{
case 1:
System.out.print(firstArr[i][j]+" ");
break;
}
}
System.out.println();
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
public class Passenger {
private String surname = null;
private String forename = null;
public Passenger() {}
public Passenger( String surname, String forename)
{
this.setSurname(surname);
this.setForename(forename);
}
public String getSurname()
{
return this.surname;
}
public void setSurname( String surname)
{
this.surname = surname;
}
public String getForename()
{
return this.forename;
}
public void setForename( String forename)
{
this.forename = forename;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
public class Airport {
private String city = null;
public Airport() {
}
public Airport( String city) {
this.setCity(city);
}
public String getCity() {
return this.city;
}
public void setCity( String city) {
this.city = city;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
import java.util.*;
public class Booking {
private Integer number;
private final Date date = new Date();
private Customer customer;
private List<Passenger> passengers = new ArrayList<Passenger>();
public Booking() {}
public Booking( Customer customer, List<Passenger> passengers) {
this.setCustomer(customer);
this.setPassengers(passengers);
}
public Integer getBookingNumber() {
return this.number;
}
public void setBookingNumber( Integer bookingNumber) {
this.number = bookingNumber;
}
public Date getDate() {
return this.date;
}
public Customer getCustomer() {
return this.customer;
}
public void setCustomer( Customer customer) {
this.customer = customer;
}
public List<Passenger> getPassengers() {
return this.passengers;
}
public void setPassengers( List<Passenger> passengers) {
this.passengers = passengers;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
public enum Class {
First,Business,Econ
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
import java.util.*;
public class Customer {
private String surname;
private String forename;
private String address;
private String telNum;
private String eMail;
private List<Booking> bookings = new ArrayList<Booking>();
public Customer() {}
public Customer( String surname, String forename,
String address, String telNum, String eMail) {
this.setSurname(surname);
this.setForename(forename);
this.setAddress(address);
this.setTelNum(telNum);
this.setEMail(eMail);
}
public String getSurname() {
return this.surname;
}
public void setSurname( String surname) {
this.surname = surname;
}
public String getForename() {
return this.forename;
}
public void setForename( String forename) {
this.forename=forename;
}
public String getAddress() {
return this.address;
}
public void setAddress( String address) {
this.address = address;
}
public String getTelNum() {
return this.telNum;
}
public void setTelNum( String telNum) {
this.telNum = telNum;
}
public String getEMail() {
return this.eMail;
}
public void setEMail(final String eMail) {
this.eMail = eMail;
}
public List<Booking> getBookings() {
return this.bookings;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
import java.util.*;
public abstract class Flight {
private Date departureTime = null;
private Date arrivalTime = null;
private long validityPeriod = 0;
private Airport departureAirport = null;
private Airport arrivalAirport = null;
private Integer flightNumber = null;
public Flight() {}
public Flight( Date departureTime, Date arrivalTime,
Airport departureAirport, Airport arrivalAirport,
long validityPeriod) {
this.setDepartureTime(departureTime);
this.setArrivalTime(arrivalTime);
this.setDepartureAirport(departureAirport);
this.setArrivalAirport(arrivalAirport);
this.setValidityPeriod(validityPeriod);
}
public Date getDepartureTime() {
return this.departureTime;
}
public void setDepartureTime(final Date departureTime) {
if (departureTime != null) {
if ((this.getArrivalTime() == null)
|| departureTime.before(this.getArrivalTime())) {
this.departureTime = departureTime;
} else {
throw new NullPointerException();
}
} else {
throw new NullPointerException();
}
}
public Date getArrivalTime() {
return this.arrivalTime;
}
void setArrivalTime(final Date arrivalTime) {
if (arrivalTime != null) {
if ((this.getDepartureTime() == null)
|| arrivalTime.after(this.getDepartureTime())) {
this.arrivalTime = arrivalTime;
} else {
throw new NullPointerException();
}
} else {
throw new NullPointerException();
}
}
public long getValidityPeriod() {
return this.validityPeriod;
}
public void setValidityPeriod(final long validityPeriod) {
this.validityPeriod = validityPeriod;
}
public Airport getDepartureAirport() {
return this.departureAirport;
}
public void setDepartureAirport(final Airport departureAirport) {
this.departureAirport = departureAirport;
}
public Airport getArrivalAirport() {
return this.arrivalAirport;
}
public void setArrivalAirport(final Airport arrivalAirport) {
this.arrivalAirport = arrivalAirport;
}
public Integer getFlightNumber() {
return this.flightNumber;
}
public void setFlightNumber(final Integer flightNumber) {
this.flightNumber = flightNumber;
}
public long getLength() {
if ((this.getArrivalTime() != null)
&& (this.getDepartureTime() != null)) {
return this.getArrivalTime().getTime()
- this.getDepartureTime().getTime();
} else {
throw new NullPointerException();
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
import java.util.*;
public class Level {
private int r,c,price;
int ClassNeeded;
int[][] econArr =new int[15][10];
int[][] bussArr= new int[3][10];
int[][] firstArr= new int[2][10];
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
Level l= new Level();
while(true){
l.setup();
l.chooseClass();
System.out.println("==========================================");
}
//l.chooseSeat(l.First);
}
void setup(){
int i,j;
for(i=0;i<15;i++){
for(j=0;j>10;j++){
econArr[i][j]=0;
}
}
i=0;j=0;
for(i=0;i<3;i++){
for(j=0;j>10;j++){
bussArr[i][j]=0;
}
}
i=0;j=0;
for(i=0;i<2;i++){
for(j=0;j>10;j++){
firstArr[i][j]=0;
}
}
}
public void getEconomicClass()
{
printLoop(3, 15 ,10);
chooseSeat(3);
printLoop(3, 15 ,10);
}
public void getBusinessClass()
{
printLoop(2, 3 ,10);
chooseSeat(2);
printLoop(2, 3 ,10);
}
public void getFirstClass()
{
printLoop(1,2 ,10);
chooseSeat(1);
printLoop(1,2 ,10);
}
public void printLoop(int classNeeded, int row, int column)
{
int i,j;
char s='A';
System.out.println(" 1 2 3 4 5 6 7 8 9 10");
for(i=0;i<row;i++)
{
System.out.print(s+" ");
s++;
for(j=0;j<column;j++)
{
if(j==3 || j==7)
System.out.print(" ");
switch(classNeeded){
case 1:
System.out.print(firstArr[i][j]+" ");
break;
case 2:
System.out.print(bussArr[i][j]+" ");
break;
case 3:
System.out.print(econArr[i][j]+" ");
break;
default:
System.out.println("Press Enter the right level");
break;
}
}
System.out.println();
}
}
public void chooseClass()
{
System.out.print(
"Choose a Class please.. "
+"1 Economic $200 for seat "
+"2 Business $315 for seat "
+"3 First $535 for seat ");
Scanner input=new Scanner(System.in);
int num = input.nextInt();
switch(num)
{
case 1:
getEconomicClass();
break;
case 2:
getBusinessClass();
break;
case 3:
getFirstClass();
break;
default:
System.out.println("Choose right option please...");
chooseClass();
break;
}
}
public int chooseSeat(int classNeeded)
{
System.out.println("Choose The row for example A3,B2,C6...");
System.out.println("note: will be extra charge 15% for window seats");
Scanner input=new Scanner(System.in);
String seat_no = input.next();
//char ch = input.next(".").charAt(0);
char lchar= Character.toLowerCase(seat_no.charAt(0));
r= lchar-97;
System.out.println(lchar);
System.out.println(r);
//int lc= input.nextInt();
int lc = seat_no.charAt(1);
c=lc-49;
System.out.println(lc);
System.out.println(c);
switch(classNeeded)
{
case 1:
firstArr[r][c] = 1;
price = 535;
break;
case 2:
bussArr[r][c] = 1;
price = 315;
break;
case 3:
econArr[r][c] = 1;
price = 200;
break;
default:
System.out.println("Choose right option please...");
chooseClass();
break;
}
return price;
}
}
Explanation / Answer
public class Main {
public static void main(String[] args) {
//Customer
// List<Customer> customers = new ArrayList<Customer>();
// Customer c = new Customer();
// customers.add(c);
//Scanner input = new Scanner(System.in);
System .out.println("Welcome to IIUM Airline");
int classNeeded = 1;
int[][] firstArr = new int[2][10];
int i,j;
char s='A';
System.out.println(" 1 2 3 4 5 6 7 8 9 10");
for(i=0;i<2;i++)
{
System.out.print(s+" ");
s++;
for(j=0;j<10;j++)
{
if(j==3 || j==7)
System.out.print(" ");
switch(classNeeded)
{
case 1:
System.out.print(firstArr[i][j]+" ");
break;
}
}
System.out.println();
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
public class Passenger {
private String surname = null;
private String forename = null;
public Passenger() {}
public Passenger( String surname, String forename)
{
this.setSurname(surname);
this.setForename(forename);
}
public String getSurname()
{
return this.surname;
}
public void setSurname( String surname)
{
this.surname = surname;
}
public String getForename()
{
return this.forename;
}
public void setForename( String forename)
{
this.forename = forename;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
public class Airport {
private String city = null;
public Airport() {
}
public Airport( String city) {
this.setCity(city);
}
public String getCity() {
return this.city;
}
public void setCity( String city) {
this.city = city;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
import java.util.*;
public class Booking {
private Integer number;
private final Date date = new Date();
private Customer customer;
private List<Passenger> passengers = new ArrayList<Passenger>();
public Booking() {}
public Booking( Customer customer, List<Passenger> passengers) {
this.setCustomer(customer);
this.setPassengers(passengers);
}
public Integer getBookingNumber() {
return this.number;
}
public void setBookingNumber( Integer bookingNumber) {
this.number = bookingNumber;
}
public Date getDate() {
return this.date;
}
public Customer getCustomer() {
return this.customer;
}
public void setCustomer( Customer customer) {
this.customer = customer;
}
public List<Passenger> getPassengers() {
return this.passengers;
}
public void setPassengers( List<Passenger> passengers) {
this.passengers = passengers;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
public enum Class {
First,Business,Econ
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
import java.util.*;
public class Customer {
private String surname;
private String forename;
private String address;
private String telNum;
private String eMail;
private List<Booking> bookings = new ArrayList<Booking>();
public Customer() {}
public Customer( String surname, String forename,
String address, String telNum, String eMail) {
this.setSurname(surname);
this.setForename(forename);
this.setAddress(address);
this.setTelNum(telNum);
this.setEMail(eMail);
}
public String getSurname() {
return this.surname;
}
public void setSurname( String surname) {
this.surname = surname;
}
public String getForename() {
return this.forename;
}
public void setForename( String forename) {
this.forename=forename;
}
public String getAddress() {
return this.address;
}
public void setAddress( String address) {
this.address = address;
}
public String getTelNum() {
return this.telNum;
}
public void setTelNum( String telNum) {
this.telNum = telNum;
}
public String getEMail() {
return this.eMail;
}
public void setEMail(final String eMail) {
this.eMail = eMail;
}
public List<Booking> getBookings() {
return this.bookings;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
import java.util.*;
public abstract class Flight {
private Date departureTime = null;
private Date arrivalTime = null;
private long validityPeriod = 0;
private Airport departureAirport = null;
private Airport arrivalAirport = null;
private Integer flightNumber = null;
public Flight() {}
public Flight( Date departureTime, Date arrivalTime,
Airport departureAirport, Airport arrivalAirport,
long validityPeriod) {
this.setDepartureTime(departureTime);
this.setArrivalTime(arrivalTime);
this.setDepartureAirport(departureAirport);
this.setArrivalAirport(arrivalAirport);
this.setValidityPeriod(validityPeriod);
}
public Date getDepartureTime() {
return this.departureTime;
}
public void setDepartureTime(final Date departureTime) {
if (departureTime != null) {
if ((this.getArrivalTime() == null)
|| departureTime.before(this.getArrivalTime())) {
this.departureTime = departureTime;
} else {
throw new NullPointerException();
}
} else {
throw new NullPointerException();
}
}
public Date getArrivalTime() {
return this.arrivalTime;
}
void setArrivalTime(final Date arrivalTime) {
if (arrivalTime != null) {
if ((this.getDepartureTime() == null)
|| arrivalTime.after(this.getDepartureTime())) {
this.arrivalTime = arrivalTime;
} else {
throw new NullPointerException();
}
} else {
throw new NullPointerException();
}
}
public long getValidityPeriod() {
return this.validityPeriod;
}
public void setValidityPeriod(final long validityPeriod) {
this.validityPeriod = validityPeriod;
}
public Airport getDepartureAirport() {
return this.departureAirport;
}
public void setDepartureAirport(final Airport departureAirport) {
this.departureAirport = departureAirport;
}
public Airport getArrivalAirport() {
return this.arrivalAirport;
}
public void setArrivalAirport(final Airport arrivalAirport) {
this.arrivalAirport = arrivalAirport;
}
public Integer getFlightNumber() {
return this.flightNumber;
}
public void setFlightNumber(final Integer flightNumber) {
this.flightNumber = flightNumber;
}
public long getLength() {
if ((this.getArrivalTime() != null)
&& (this.getDepartureTime() != null)) {
return this.getArrivalTime().getTime()
- this.getDepartureTime().getTime();
} else {
throw new NullPointerException();
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication12;
/**
*
* @author Dell
*/
import java.util.*;
public class Level {
private int r,c,price;
int ClassNeeded;
int[][] econArr =new int[15][10];
int[][] bussArr= new int[3][10];
int[][] firstArr= new int[2][10];
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
Level l= new Level();
while(true){
l.setup();
l.chooseClass();
System.out.println("==========================================");
}
//l.chooseSeat(l.First);
}
void setup(){
int i,j;
for(i=0;i<15;i++){
for(j=0;j>10;j++){
econArr[i][j]=0;
}
}
i=0;j=0;
for(i=0;i<3;i++){
for(j=0;j>10;j++){
bussArr[i][j]=0;
}
}
i=0;j=0;
for(i=0;i<2;i++){
for(j=0;j>10;j++){
firstArr[i][j]=0;
}
}
}
public void getEconomicClass()
{
printLoop(3, 15 ,10);
chooseSeat(3);
printLoop(3, 15 ,10);
}
public void getBusinessClass()
{
printLoop(2, 3 ,10);
chooseSeat(2);
printLoop(2, 3 ,10);
}
public void getFirstClass()
{
printLoop(1,2 ,10);
chooseSeat(1);
printLoop(1,2 ,10);
}
public void printLoop(int classNeeded, int row, int column)
{
int i,j;
char s='A';
System.out.println(" 1 2 3 4 5 6 7 8 9 10");
for(i=0;i<row;i++)
{
System.out.print(s+" ");
s++;
for(j=0;j<column;j++)
{
if(j==3 || j==7)
System.out.print(" ");
switch(classNeeded){
case 1:
System.out.print(firstArr[i][j]+" ");
break;
case 2:
System.out.print(bussArr[i][j]+" ");
break;
case 3:
System.out.print(econArr[i][j]+" ");
break;
default:
System.out.println("Press Enter the right level");
break;
}
}
System.out.println();
}
}
public void chooseClass()
{
System.out.print(
"Choose a Class please.. "
+"1 Economic $200 for seat "
+"2 Business $315 for seat "
+"3 First $535 for seat ");
Scanner input=new Scanner(System.in);
int num = input.nextInt();
switch(num)
{
case 1:
getEconomicClass();
break;
case 2:
getBusinessClass();
break;
case 3:
getFirstClass();
break;
default:
System.out.println("Choose right option please...");
chooseClass();
break;
}
}
public int chooseSeat(int classNeeded)
{
System.out.println("Choose The row for example A3,B2,C6...");
System.out.println("note: will be extra charge 15% for window seats");
Scanner input=new Scanner(System.in);
String seat_no = input.next();
//char ch = input.next(".").charAt(0);
char lchar= Character.toLowerCase(seat_no.charAt(0));
r= lchar-97;
System.out.println(lchar);
System.out.println(r);
//int lc= input.nextInt();
int lc = seat_no.charAt(1);
c=lc-49;
System.out.println(lc);
System.out.println(c);
switch(classNeeded)
{
case 1:
firstArr[r][c] = 1;
price = 535;
break;
case 2:
bussArr[r][c] = 1;
price = 315;
break;
case 3:
econArr[r][c] = 1;
price = 200;
break;
default:
System.out.println("Choose right option please...");
chooseClass();
break;
}
return price;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.