Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// This program is an emulator. It emulates a airline reservation system. // Non

ID: 3641838 • Letter: #

Question

// This program is an emulator. It emulates a airline reservation system.
// None of the methods are implemented as they would in a real system.
// The emulator is ONLY being used as a prototype against our requirements and IPO.
// The emulator assumes the base case (easy path with no errors and no issues with data entry or db connections)


// I want you to update getUserInput() to actually get user input from a user using the Scanner class.
// I want you to update checkFlight() to return a different flight each time it is called. Assume there are ONLY three flight numbers
// I want you to update "if (confirmed)" section of code to handle the case when it returns false.
// If it returns false I want you to print a message that says "Your order has been terminated"


public class Airplane {
public static void main(String[] args) {

String CCinfo = "";
externaldbConnect();

int uniqueId = getUniqId();
displayOutput("Enter Departure Date and Time");
String departureInfo = getUserInput();

displayOutput("Enter Return Date and Time");
String returnInfo = getUserInput();

String fltnoDepart = flightAvailibilty(departureInfo);
String fltnoReturn = flightAvailibilty(returnInfo);


displayOutput("Please confirm flight pair for purchase" + fltnoDepart + " " + fltnoReturn);
boolean confirmed = getUserConfirmation();
if (confirmed)
{
displayOutput("Enter your name, address, and Credit Card information");
CCinfo = getCreditCard();
storeOrderInLocalDb(uniqueId, CCinfo, fltnoDepart, fltnoReturn);
displayItinerary(uniqueId);
}

}


// Checks availability of flight through the external database
// Returns a flight number
public static String flightAvailibilty(String datetime) {
String fltno = checkFlight(datetime);
boolean open = seatAvailibility(fltno);
return fltno;
}

// Queries a date and time against the remote database and returns a flight no
public static String checkFlight(String dt)
{
return "BA201";
}


// Given a string will present this to the user
public static void displayOutput(String s)
{
System.out.println(s);
}

// Gets user input and returns it
public static String getUserInput()
{
return "6/21/2012 18:00 DCA RSW" ;
}

// Gets confirmation that want to buy ticket
public static boolean getUserConfirmation()
{
return true;
}


// via external database checks if any seats available on a flight
// flightno is passed in to be checked
public static boolean seatAvailibility(String fn)
{
return true;
}

// Connects to external flight info database
public static void externaldbConnect()
{
// Connects to external db. Connection is global to all methods
}

// gets CC info and returns it
public static String getCreditCard()
{
return "Brian Geary, 123 Main Street, 1111-2222-3333-4444 04/13";
}

// Display users full itinerary and order #
public static void displayItinerary(int uid)
{

// Right before this line you could connect to the local database
// and query for the unique id (uid) and then create a string to
// present to the user
displayOutput("");

}

// Given a uniqueid and all other user and flight information stores it in database
public static void storeOrderInLocalDb(int pk, String userinfo, String fltnoDepart, String fltnoReturn)
{
//using the uniqueid as a primary key in the db you would store the
// cc info, fltdepart and return information

}


// returns next sequence # from local db and returns it
public static int getUniqId()
{
// connect to local database and get the next sequence #
return 1;
}




}

Explanation / Answer

import java.util.Scanner; import java.util.Random; public class Airplane { static Random rnd = new Random(); static Scanner scan = new Scanner(System.in); public static void main(String[] args) { String CCinfo = ""; externaldbConnect(); int uniqueId = getUniqId(); displayOutput("Enter Departure Date and Time"); String departureInfo = getUserInput(); displayOutput("Enter Return Date and Time"); String returnInfo = getUserInput(); String fltnoDepart = flightAvailibilty(departureInfo,""); String fltnoReturn = flightAvailibilty(returnInfo,fltnoDepart); displayOutput("Please confirm flight pair for purchase " + fltnoDepart + " " + fltnoReturn); boolean confirmed = getUserConfirmation(); if (confirmed) { displayOutput("Enter your name, address, and Credit Card information"); CCinfo = getUserInput(); CCinfo = getCreditCard(); storeOrderInLocalDb(uniqueId, CCinfo, fltnoDepart, fltnoReturn); displayItinerary(uniqueId); } else { displayOutput("Your order has been terminated"); } } // Checks availability of flight through the external database // Returns a flight number public static String flightAvailibilty(String datetime,String from) { String fltno = checkFlight(datetime,from); boolean open = seatAvailibility(fltno); return fltno; } // Queries a date and time against the remote database and returns a flight no public static String checkFlight(String dt,String from) { int r = rnd.nextInt(); if(from.isEmpty()) { if(r%4==0) { return "LA231"; } else if(r%5==0) { return "SEA234"; } else{ return "qewr"; } } else if(from.equals("LA231")) { if(r%2==0) { return "qwer"; } else { return "SEA234"; } } else if(from.equals("SEA234")) { if(r%2==0) { return "qwer"; } else { return "LA231"; } } else { if(r%2==0) { return "SEA234"; } else { return "LA231"; } } } // Given a string will present this to the user public static void displayOutput(String s) { System.out.println(s); } // Gets user input and returns it public static String getUserInput() { String usr; String in=""; usr = scan.next(); in+=usr; return in; } // Gets confirmation that want to buy ticket public static boolean getUserConfirmation() { String ans; ans = scan.next(); if(ans.startsWith("y")||ans.startsWith("Y")) { return true;} return false; } // via external database checks if any seats available on a flight // flightno is passed in to be checked public static boolean seatAvailibility(String fn) { return true; } // Connects to external flight info database public static void externaldbConnect() { // Connects to external db. Connection is global to all methods } // gets CC info and returns it public static String getCreditCard() { return "Brian Geary, 123 Main Street, 1111-2222-3333-4444 04/13"; } // Display users full itinerary and order # public static void displayItinerary(int uid) { // Right before this line you could connect to the local database // and query for the unique id (uid) and then create a string to // present to the user displayOutput(""); } // Given a uniqueid and all other user and flight information stores it in database public static void storeOrderInLocalDb(int pk, String userinfo, String fltnoDepart, String fltnoReturn) { //using the uniqueid as a primary key in the db you would store the // cc info, fltdepart and return information } // returns next sequence # from local db and returns it public static int getUniqId() { // connect to local database and get the next sequence # return 1; } }