For this assignment you will re-implement the Air Ticket Redeemer, refer to the
ID: 3865356 • Letter: F
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 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.
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 <= endMonth)
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<RedemptionInfo> list)
{
int minIdx ;
for(int i = 0; i < list.size(); i++)
{
minIdx = i;
for( int j = 0; j < list.size(); j++)
{
if(list.get(j).getFlycheapMileage() < list.get(minIdx).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<RedemptionInfo> list, HashMap<String, RedemptionInfo> map, ArrayList<String> 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<Ticket> tickets = new ArrayList<Ticket>(); //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 < list.size(); 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 //not in flycheap month
{
if(accumulated >= info.getNormalMileage())
{
t = new Ticket(1, info.getDestination(), info.getNormalMileage());
accumulated -= info.getNormalMileage();
tickets.add(t);
}
}
}
if(accumulated > 0)
{
//now 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();
}
}
}
//now 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/n) ? ");
ans = keyScan.next();
if(!ans.equals("y"))
break;
}
}
public static void main(String[] args) {
ArrayList<RedemptionInfo> redeemInfo = new ArrayList<RedemptionInfo>();
HashMap<String, RedemptionInfo> map = new HashMap<String, RedemptionInfo>();
ArrayList<String> destinations = new ArrayList<String>();
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 milesExplanation / Answer
MileRedemptionApp.java
-----------------------------------------
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Scanner;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerListModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class MileRedemptionApp extends JFrame {
// Variables - declaration and initialization
private static Scanner fileScanner = null;
private static String[] destinationCity = null, listOfTickets = null;
private static String tkt = "";
// Object instance of MileRedeemer class created to call its methods
private static MileRedeemer mileRedeemer = new MileRedeemer();
Destination destination = null;
// Fields Declaration
final JLabel comment = new JLabel(
" Your miles can be used to redeem the following tickets:");
final JLabel remMilesLabel = new JLabel("Congrats! Your Remianing Miles is");
JTextArea ticketArea = new JTextArea();
JList listBox;
JButton button;
JTextField text1, text2, text3, text4, remMiles = new JTextField("", 10);
@SuppressWarnings("unchecked")
public MileRedemptionApp() {
// Setting the container's properties .
this.setSize(710, 380);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(0, 2));
this.setBackground(Color.red);
this.setResizable(false);
// Creating new panel and adding it.
JPanel leftPane = new JPanel();
JPanel rightPane = new JPanel();
this.add(leftPane);
this.add(rightPane);
// Setting background colors and layout for the panes
leftPane.setBackground(Color.getHSBColor(30, 100, 90));
rightPane.setBackground(Color.getHSBColor(30, 0, 90));
leftPane.setLayout(new GridLayout(2, 0, 20, 20));
rightPane.setLayout(new GridLayout(2, 0, 20, 20));
// Setting title borders for the panes
leftPane.setBorder(BorderFactory
.createTitledBorder("List of Destination Cities"));
rightPane.setBorder(BorderFactory.createTitledBorder("Redeem Tickets"));
// Creating 4 panels, setting the bkg color & layout and adding it
final JPanel leftTopPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
leftPane.add(leftTopPanel);
leftTopPanel.setBackground(Color.white);
final JPanel leftBottomPanel = new JPanel(new GridLayout(0, 2));
leftPane.add(leftBottomPanel);
leftBottomPanel.setBackground(Color.getHSBColor(30, 100, 80));
final JPanel rightTopPanel = new JPanel(new FlowLayout(
FlowLayout.CENTER));
rightPane.add(rightTopPanel);
rightTopPanel.setBackground(Color.getHSBColor(30, 0, 75));
final JPanel rightBottomPanel = new JPanel(new FlowLayout(
FlowLayout.CENTER));
rightPane.add(rightBottomPanel);
rightBottomPanel.setBackground(Color.white);
// Create a new listbox control for displaying destination cities
final JList listBox = new JList(destinationCity);
listBox.setFixedCellWidth(330);
leftTopPanel.add(listBox);
// Creating 2 panels each for label and textfields respectively
JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
leftBottomPanel.add(labelPanel);
labelPanel.setBackground(Color.getHSBColor(30, 100, 80));
JPanel textFieldPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
leftBottomPanel.add(textFieldPanel);
textFieldPanel.setBackground(Color.getHSBColor(30, 100, 80));
// Creating the required labels, textfields & setting its font & size
JLabel label1 = new JLabel("Required Miles");
label1.setFont(new Font("Serif", Font.PLAIN, 15));
text1 = new JTextField("", 14);
JLabel label2 = new JLabel("Miles for upgrading");
label2.setFont(new Font("Serif", Font.PLAIN, 15));
text2 = new JTextField("", 14);
JLabel label3 = new JLabel("Miles for Supersaver");
label3.setFont(new Font("Serif", Font.PLAIN, 15));
text3 = new JTextField("", 14);
JLabel label4 = new JLabel("Months for Supersaver");
label4.setFont(new Font("Serif", Font.PLAIN, 15));
text4 = new JTextField("", 14);
// Setting the text fields to non editable forms
text1.setEditable(false);
text2.setEditable(false);
text3.setEditable(false);
text4.setEditable(false);
// Adding labels and textfields to the panels
labelPanel.add(label1);
textFieldPanel.add(text1);
labelPanel.add(label2);
textFieldPanel.add(text2);
labelPanel.add(label3);
textFieldPanel.add(text3);
labelPanel.add(label4);
textFieldPanel.add(text4);
listBox.addListSelectionListener(new ListSelectionListener() {
// Method to get invoked when a city is chosen from the list
public void valueChanged(ListSelectionEvent event) {
// it will return if the value is changed
if (event.getValueIsAdjusting())
return;
// Getting the miles details of a city
destination = mileRedeemer.getMileDetails(listBox
.getSelectedValue().toString());
// Setting the text to details respective to the cities
text1.setText(String.valueOf(destination.getNormalMiles()));
text2.setText(String.valueOf(destination
.getUpgradingAdditionalMiles()));
text3.setText(String.valueOf(destination.getSuperSaverMiles()));
text4.setText(mileRedeemer.getMonthDetails(destination
.getStartMonth())
+ " to "
+ mileRedeemer.getMonthDetails(destination
.getEndMonth()));
}
});
// Setting the label and textfield for accumulated miles
JLabel accumulatedMiles = new JLabel("Your Accumulated Miles");
final JTextField accumulatedMilesText = new JTextField("", 10);
// Setting the label and spinner for departure month
JLabel departureMonth = new JLabel("Month of Departure");
SpinnerListModel monthModel = new SpinnerListModel(
mileRedeemer.getMonthStrings());
final JSpinner spinner = new JSpinner(monthModel);
spinner.setPreferredSize(new Dimension(130, 20));
// Creating the button that invokes the required method
JButton button = new JButton("Redeem Tickets >>>");
// Adding the fields
rightTopPanel.add(accumulatedMiles);
rightTopPanel.add(accumulatedMilesText);
rightTopPanel.add(departureMonth);
rightTopPanel.add(spinner);
rightTopPanel.add(button);
button.addActionListener(new ActionListener() {
// Method that is invoked when the buton is clicked
public void actionPerformed(ActionEvent arg0) {
// Adding the comment section to the panel
rightBottomPanel.add(comment);
// Setting the redeemable tickets to null
tkt = "";
// Setting the visibility of elements to false first
comment.setVisible(false);
ticketArea.setVisible(false);
remMilesLabel.setVisible(false);
remMiles.setVisible(false);
// Getting the month value in number from the spinner
int month = mileRedeemer.getMonthNumber((String) spinner
.getValue());
// Getting miles from the textfield & checking its validity
String milesValue = accumulatedMilesText.getText();
boolean match = milesValue.matches("[0-9]*");
// Continued if its a number
if (match) {
// Converting the miles value to int
int accumulatedMiles = Integer.parseInt(milesValue);
// Getting the list of redeemed tickets
listOfTickets = mileRedeemer.redeemMiles(accumulatedMiles,
month);
// Setting the comment section to true
comment.setVisible(true);
// Traversing through String array and printing the
// redeemable tickets
if (listOfTickets[0] != null) {
for (String ticket : listOfTickets)
if (ticket != null)
tkt = tkt.concat(ticket + " ");
} else
tkt = "You need more miles to redeem a ticket";
// Setting the text area with the tickets
ticketArea.setText(tkt);
// Adding the tickets and setting it to visible
rightBottomPanel.add(ticketArea);
ticketArea.setVisible(true);
// Adding the Rem miles label and setting it to visible
rightBottomPanel.add(remMilesLabel);
remMilesLabel.setVisible(true);
// Adding the rem miles text to visible and non editable
remMiles.setText("" + mileRedeemer.getRemainingMiles());
remMiles.setEditable(false);
remMiles.setVisible(true);
rightBottomPanel.add(remMiles);
} else
System.out
.println("Please enter a number in the accumulated miles field");
}
});
}
public static void main(String args[]) throws Exception {
// To check the number of arguments that is passed to the method
if (!(args[0].equals(""))) // The file from the file's location passed
// thru the args is stored
fileScanner = new Scanner(new File(args[0]));
else {
System.err
.println("Provide only one argument containing the file's location.");
System.exit(0);
}
// Methods of MileRedeemer class are called by the object's instance
mileRedeemer.readDestinations(fileScanner);
destinationCity = mileRedeemer.getCityNames();
// Swing Utility method to synchronize with the user's action
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
// Create an instance of the test application
new MileRedemptionApp();
}
});
}
}
-----------------------------------------------------------------------------------
MileRedeemer.java
-------------------------------
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
public class MileRedeemer {
// Constants - declaration and initialization
private static final String ECONOMY = "economy";
private static final String FIRST = "first";
// Variables - declaration and initialization
private int key = 0, index = 0, lastIndex = 0, redeemedTicketsLength = 0,
destinationLength = 0, normalMiles = 0, superSaverMiles = 0,
upgradedMiles = 0, remainingMiles = 0;
private boolean superSaverEligible = false;
private String destinationObject = null;
private String[] destinationObjects = null, redeemedTickets = null,
ticketClass = null;
private List<Destination> destinationArrayList = new ArrayList<Destination>();
private Destination[] destinationList;
/**
* This method reads the file from the location provided in the args[],
* converts to String array & also to an object of a list of Destination
*/
public void readDestinations(Scanner fileScanner) {
// Checking of the file has more lines
while (fileScanner.hasNext()) {
// Storing a single line to the String
destinationObject = fileScanner.nextLine();
// Finding the lindex of last occuring '-'
lastIndex = destinationObject.lastIndexOf("-");
// Replacing '-' with ';', splitting at ';' & storing as arrays
destinationObjects = (new StringBuilder(destinationObject).replace(
lastIndex, lastIndex + 1, ";").toString()).split(";");
// Adding the array to an instance object of a list of Destination
destinationArrayList.add(new Destination(
destinationObjects[index++], Integer
.parseInt(destinationObjects[index++]), Integer
.parseInt(destinationObjects[index++]), Integer
.parseInt(destinationObjects[index++]), Integer
.parseInt(destinationObjects[index++]), Integer
.parseInt(destinationObjects[index])));
// Resetting the index to zero for the next loop
index = 0;
}
}
/**
* This method reads destinationArrayList object and stores only the
* destination in the destinationObjects array and sorts it too.
*/
public String[] getCityNames() {
// Setting the size of the array to that of the arraylist object
destinationObjects = new String[destinationArrayList.size()];
// Storing the destination city to the destinationObjects array
for (Destination dest : destinationArrayList) {
destinationObjects[index++] = dest.getDestinationCity();
}
Arrays.sort(destinationObjects);
return destinationObjects;
}
/**
* This method reads destinationArrayList object and returns the mile
* details of the city.
*/
public Destination getMileDetails(String selectedCity) {
Destination destination = null;
// Storing the destination city to the destinationObjects array
for (Destination destn : destinationArrayList)
if (selectedCity.equals(destn.getDestinationCity()))
destination = destn;
return destination;
}
/**
* This method reads month(number) of supersaver of the destination city and
* returns the corresponding Month details in words.
*/
public String getMonthDetails(int month) {
String monthString;
switch (month) {
case 1:
monthString = "January";
break;
case 2:
monthString = "February";
break;
case 3:
monthString = "March";
break;
case 4:
monthString = "April";
break;
case 5:
monthString = "May";
break;
case 6:
monthString = "June";
break;
case 7:
monthString = "July";
break;
case 8:
monthString = "August";
break;
case 9:
monthString = "September";
break;
case 10:
monthString = "October";
break;
case 11:
monthString = "November";
break;
case 12:
monthString = "December";
break;
default:
monthString = "Invalid month";
break;
}
return monthString;
}
/**
* This method reads month details in words as the input and returns its
* corresponding number.
*/
public int getMonthNumber(String monthValue) {
Date date = null;
try {
date = new SimpleDateFormat("MMM", Locale.ENGLISH)
.parse(monthValue);
} catch (ParseException e) {
System.out.println(e.getMessage());
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month = cal.get(Calendar.MONTH) + 1;
return month;
}
/**
* The month Strings can be obtained in this method.
*
*/
public String[] getMonthStrings() {
String[] months = new java.text.DateFormatSymbols().getMonths();
int lastIndex = months.length - 1;
if (months[lastIndex] == null || months[lastIndex].length() <= 0) {
String[] monthStrings = new String[lastIndex];
System.arraycopy(months, 0, monthStrings, 0, lastIndex);
return monthStrings;
} else { // if last item not empty
return months;
}
}
/**
* This method consturcts the destinationList object from arraylist & sorts
* it. It also sends back a list of redeemable ticket information
*
*/
public String[] redeemMiles(int miles, int month) {
// Converting destinationArrayList to an object instance of Destination
destinationList = (Destination[]) destinationArrayList
.toArray(new Destination[destinationArrayList.size()]);
// Sorting the destinationList in the descending order of normal miles
Arrays.sort(destinationList, new Comparator<Destination>() {
public int compare(Destination destination1,
Destination destination2) {
return destination2.getNormalMiles()
- destination1.getNormalMiles();
}
});
// Calling the method which handles all the logic of redeeming tickets
redeemLogic(miles, month);
// Constructing the list of redeemable tickets information
for (index = 0; index < redeemedTickets.length; index++) {
if (redeemedTickets[index] != null)
redeemedTickets[index] = "* A trip to "
+ redeemedTickets[index] + ", " + ticketClass[index]
+ " class.";
}
return redeemedTickets;
}
/**
* This method calculates whether user is eligible to use super saver miles,
* checks for upgradation of ticket & also calculates the remaining miles
*/
public void redeemLogic(int miles, int month) {
// Assigning the destinationLength also to both the other arrays
key = 0;
destinationLength = destinationList.length;
redeemedTickets = new String[destinationLength];
ticketClass = new String[destinationLength];
for (index = 0; index < destinationLength; index++) {
// Supersaver logic for months, if its in the range of 1-12
if ((destinationList[index].getEndMonth() - destinationList[index]
.getStartMonth()) >= 0) {
if ((month >= destinationList[index].getStartMonth())
&& (month <= destinationList[index].getEndMonth()))
superSaverEligible = true;
else
superSaverEligible = false;
} else { // Supersaver logic for months, if its in the range of
// 12-11
if ((month < destinationList[index].getStartMonth())
&& (month > destinationList[index].getEndMonth()))
superSaverEligible = false;
else
superSaverEligible = true;
}
normalMiles = destinationList[index].getNormalMiles();
superSaverMiles = destinationList[index].getSuperSaverMiles();
// Checking for enough superSaverMiles, if travel is in super saver
// month
if ((superSaverEligible == true) && (miles >= superSaverMiles)) {
redeemedTickets[key] = destinationList[index]
.getDestinationCity();
miles = miles - superSaverMiles;
ticketClass[key++] = ECONOMY; // Economy class set for
// redeemable tickets
} // Checking for enough normalMiles, if travel isn't in super saver
// month
else if ((superSaverEligible == false) && (miles >= normalMiles)) {
redeemedTickets[key] = destinationList[index]
.getDestinationCity();
miles = miles - normalMiles;
ticketClass[key++] = ECONOMY;
}
}
redeemedTicketsLength = redeemedTickets.length;
for (index = 0; index < destinationLength; index++) {
for (key = 0; key < redeemedTicketsLength; key++) {
upgradedMiles = destinationList[index]
.getUpgradingAdditionalMiles();
// Checking for miles to upgrade the redeemable tickets to first
// class
if ((destinationList[index].getDestinationCity()
.equals(redeemedTickets[key]))
&& (miles >= upgradedMiles)) {
ticketClass[key] = FIRST; // Overriding the value from
// economy to first
miles = miles - upgradedMiles;
}
}
}
remainingMiles = miles; // The miles subtracted above is the remaining
// miles
}
public int getRemainingMiles() {
return remainingMiles;
}
}
---------------------------------------------------------------------------------------
Destination.java
--------------------------------------------
public class Destination {
// Variables - declaration
private String destinationCity;
private int normalMiles, superSaverMiles, upgradingAdditionalMiles,
startMonth, endMonth;
// Constructor
public Destination(String city, int miles, int superMiles,
int upgradingMiles, int startingMonth, int endingMonth) {
destinationCity = city;
normalMiles = miles;
superSaverMiles = superMiles;
upgradingAdditionalMiles = upgradingMiles;
startMonth = startingMonth;
endMonth = endingMonth;
}
// Getters and Setters
public String getDestinationCity() {
return destinationCity;
}
public void setDestinationCity(String destinationCity) {
this.destinationCity = destinationCity;
}
public int getNormalMiles() {
return normalMiles;
}
public void setNormalMiles(int normalMiles) {
this.normalMiles = normalMiles;
}
public int getUpgradingAdditionalMiles() {
return upgradingAdditionalMiles;
}
public void setUpgradingAdditionalMiles(int upgradingAdditionalMiles) {
this.upgradingAdditionalMiles = upgradingAdditionalMiles;
}
public int getSuperSaverMiles() {
return superSaverMiles;
}
public void setSuperSaverMiles(int superSaverMiles) {
this.superSaverMiles = superSaverMiles;
}
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;
}
}
----------------------------------------------------------------
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.