Question: For this assignment you will re-implement the Air Ticket Redeemer, refer to the output screen The Destination class should remain the same as that developed

For this assignment you will re-implement the Air Ticket Redeemer, refer to the output screen

The Destination class should remain the same as that developed in Assignment 4. This reusability is one of the advantages of encapsulation, i.e., using object-oriented methodology.

In addition, the MileRedeemer class from Assignment 4 can be reused as well. Many methods of MileRedeemer can be invoked directly by your application, such as readDestinations() and the method that contains the redemption algorithm. There should be no part of your application that displays console-type output as you did in Assignment 4.

where the arguments are in the range 0...255 and the higher the number, the lighter the color. Use colors that are not too intense and displeasing to a user, and be sure that the text is completely legible.

The left panel contains a JList so that the user can go back and forth to look at the information of different tickets to different cities. The array of strings returned by the MileRedeemer method getCityNames() can be used to populate the JList. When a city in the JList is selected, its details (i.e., the members of its corresponding Destination object) should be displayed in the corresponding JTextFields. These JTextFields are not editable. To listen for this event, implement the interface javax.swing.event.ListSelectionListener, and provide the method

public void valueChanged(ListSelectionEvent e)

Add a new method to your MileRedeemer class to return the corresponding Destination object for a given city name, e.g.:

public Destination findDestination(String cityName)

The right panel takes in the accumulated miles using a JTextField and a JSpinner. After the "Redeem Tickets" button is clicked, it outputs ticket details in a JTextArea, and the remaining miles in a JTextField. The components for output are not editable.

The Input File

Create a small GUI window to ask for the name of the input destinations file.

Do not use a form or GUI builder in your IDE to build your GUI; you must code it all by hand.

You are allowed to use GridBagLayout, about which more can be found here.

Any error messages or messages printed as a result of caught exceptions should be printed on the Java console.

For this assignment you will re-implement the Air Ticket Redeemer, refer to

Ticket.java

public class Ticket {

private int type; //1- economy 2- business

private String destination;

private int mileage;

public Ticket(int type, String destination, int mileage)

{

this.type = type;

this.destination = destination;

this.mileage = mileage;

}

public void set(int type, int mileage)

{

this.type = type;

this.mileage = mileage;

}

public int getType()

{

return type;

}

public int getMileage()

{

return mileage;

}

public String getDestination()

{

return destination;

}

public String toString()

{

String str = "* A trip to " + destination + " in ";

if(type == 1)

str += "Economy class";

else

str += "First class";

return str;

}

}

RedemptionInfo.java

public class RedemptionInfo {

private String destination;

private int normalMileage;

private int flycheapMileage;

private int upgradeMileage;

private int startMonth;

private int endMonth;

public String getDestination() {

return destination;

}

public void setDestination(String destination) {

this.destination = destination;

}

public int getNormalMileage() {

return normalMileage;

}

public void setNormalMileage(int normalMileage) {

this.normalMileage = normalMileage;

}

public int getFlycheapMileage() {

return flycheapMileage;

}

public void setFlycheapMileage(int flycheapMileage) {

this.flycheapMileage = flycheapMileage;

}

public int getUpgradeMileage() {

return upgradeMileage;

}

public void setUpgradeMileage(int upgradeMileage) {

this.upgradeMileage = upgradeMileage;

}

public int getStartMonth() {

return startMonth;

}

public void setStartMonth(int startMonth) {

this.startMonth = startMonth;

}

public int getEndMonth() {

return endMonth;

}

public void setEndMonth(int endMonth) {

this.endMonth = endMonth;

}

public boolean isMonthIncluded(int month)

{

if(month >= startMonth && month

return true;

else

return false;

}

}

RedeemerApp.java

import java.io.File;

import java.io.FileNotFoundException;

import java.nio.file.Files;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Scanner;

public class RedeemerApp {

//sort the list on fly cheap mileage

private static void sort(ArrayList list)

{

int minIdx ;

for(int i = 0; i

{

minIdx = i;

for( int j = 0; j

{

if(list.get(j).getFlycheapMileage()

minIdx = j;

}

if(minIdx != i)

{

RedemptionInfo temp = list.get(i);

list.set(i, list.get(minIdx));

list.set(minIdx, temp);

}

}

}

private static void menu(Scanner keyScan,ArrayList list, HashMap map, ArrayList dest)

{

System.out.println("-------------------------------------------------");

System.out.println("WELCOME TO THE JAVA AIRLINES MILES REDEMPTION APP");

System.out.println("-------------------------------------------------");

System.out.println("List of destination cities you can travel to:");

for(String s : dest)

System.out.println(s);

System.out.println("-------------------------------------------------");

String ans;

int accumulated, month;

while(true)

{

System.out.print("Please enter your accumulated Frequent Flyer Miles: ");

accumulated = keyScan.nextInt();

System.out.print("Enter your month of departure (1-12): ");

month = keyScan.nextInt();

ArrayList tickets = new ArrayList(); //a list of tickets generated

//iterate through each redemption info and see if a ticket can be generated for it

for(int i = 0; i

{

RedemptionInfo info = list.get(i);

Ticket t = null;

//is the month a flycheap month for this destination

if(info.isMonthIncluded(month))

{

//do we have enough flyer miles for fly cheap miles

if(accumulated >= info.getFlycheapMileage())

{

t = new Ticket(1, info.getDestination(),info.getFlycheapMileage());

accumulated -= info.getFlycheapMileage();

tickets.add(t);

}

}

else /ot in flycheap month

{

if(accumulated >= info.getNormalMileage())

{

t = new Ticket(1, info.getDestination(), info.getNormalMileage());

accumulated -= info.getNormalMileage();

tickets.add(t);

}

}

}

if(accumulated > 0)

{

/ow try to upgrade the tickets if possible

for(Ticket t : tickets)

{

RedemptionInfo info = map.get(t.getDestination());

if(accumulated >= info.getUpgradeMileage())

{

t.set(2, t.getMileage() + info.getUpgradeMileage());

accumulated -= info.getUpgradeMileage();

}

}

}

/ow print out the tickets

System.out.println("Your Frequent Flyer Miles can be used to redeem the following tickets:");

for(Ticket t : tickets)

System.out.println(t);

System.out.println("Your remaining Frequent Flyer Miles: " + accumulated);

System.out.print("Do you want to continue (y) ? ");

ans = keyScan.next();

if(!ans.equals("y"))

break;

}

}

public static void main(String[] args) {

ArrayList redeemInfo = new ArrayList();

HashMap map = new HashMap();

ArrayList destinations = new ArrayList();

Scanner keyScan = new Scanner(System.in);

String filename;

System.out.print("Enter input file name containing redemption info: ");

filename = keyScan.nextLine().trim();

try {

Scanner fileScan = new Scanner(new File(filename));

while(fileScan.hasNextLine())

{

String line = fileScan.nextLine();

Scanner lineScan = new Scanner(line);

lineScan.useDelimiter(";");

RedemptionInfo info = new RedemptionInfo();

info.setDestination(lineScan.next());

info.setNormalMileage(lineScan.nextInt());

info.setFlycheapMileage(lineScan.nextInt());

info.setUpgradeMileage(lineScan.nextInt());

String months = lineScan.next();

int idx = months.indexOf('-');

String sm = months.substring(0, idx);

String em = months.substring(idx+1);

info.setStartMonth(Integer.parseInt(sm));

info.setEndMonth(Integer.parseInt(em));

redeemInfo.add(info);

destinations.add(info.getDestination());

map.put(info.getDestination(), info);

}

fileScan.close();

sort(redeemInfo); // sort the list so we can take the ones which are farthest

menu(keyScan, redeemInfo, map, destinations);

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

input file: redeem.txt

Berlin;17250;12750;5250;3-5

Hong Kong;30000;20250;17500;2-4

Hyderabad;30000;20000;15000;2-4

Sidney;50000;30000;20000;5-6

Paris;20000;15000;10000;2-4

New York;10000;5000;8000;10-11

Tokyo;29000;16500;5350;2-5

Vienna;17500;12500;5000;2-4

Washington, D.C.;9000;7500;2000;10-12

Mile Redemption App Destinations Redeem Miles Berlin Hong Kong Hyderabad Sidney Paris New York Tokyo Vienna Washington, D.C Enter your miles elect the month of departure Jan Redeem miles Normal miles50000 Supersaver miles 30000 upgrade cost 20000 Supersaver DatesMay June Your remaining miles

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!