Question: Can someone help me with my java programing, there are a few mistaks that i am not able to figure out. public class Destination {
Can someone help me with my java programing, there are a few mistaks that i am not able to figure out.
public class Destination {
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;
}
}
public class MileRedeemer {
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;
}
}
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 MileRedemptionApp {
//sort the list on fly cheap mileage
private static void sort(ArrayList
{
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)
{
MileRedeemer temp = list.get(i);
list.set(i, list.get(minIdx));
list.set(minIdx, temp);
}
}
}
private static void menu(Scanner keyScan,ArrayList
{
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
//iterate through each redemption info and see if a ticket can be generated for it
for(int i = 0; i < list.size(); i++)
{
MileRedeemer info = list.get(i);
Destination d = 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())
{
d = new Destination(1, info.getDestination(),info.getFlycheapMileage());
accumulated -= info.getFlycheapMileage();
Destination.add(t);
}
}
else //not in flycheap month
{
if(accumulated >= info.getNormalMileage())
{
t = new Destination(1, info.getDestination(), info.getNormalMileage());
accumulated -= info.getNormalMileage();
tickets.add(t);
}
}
}
if(accumulated > 0)
{
//now try to upgrade the tickets if possible
for(Destination 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(Destination 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
HashMap
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();
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
