PDA

View Full Version : Java help! Please help by tonight!


guthrien
Nov 9, 2012, 09:10 PM
The question is:

B) Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Have the getter methods return the data they are associated with. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest whose main method instantiates (creates) and updates several Flight objects. Be sure to plan out what you need for this class and the driver class before you begin to code. Doing so will make your task much easier. (The account class we studied in class is a good model for this lab.)





The code I've created so far:






import java.util.Scanner;
import java.text.DecimalFormat;

public class Flight
{

private int id;
private float newDestination, newOrigin;
String flight1, flight2;
String number1, number2;
String origin1, origin2;
String destination1, destination2;


Scanner scan = new Scanner(System.in);

public void AirlineName()
{
flight1 = "Delta";
flight2 = "United";



}

public void FlightNumber()
{
number1 = "12345";
number2 = "54321";

}

public void FlightOrigin()
{
origin1 = "Denver, Colorado";
origin2 = "Boise, Idaho";


}

public void FlightDestination()
{
destination1 = "Miami, Florida";
destination2 = "Las Vegas, Nevada";

}


public void One()
{
System.out.println ("This is " + flight1 + " flight " + number1 + " from " + origin1 + " to " + destination1);
System.out.println ("This is " + flight2 + " flight " + number2 + " from " + origin2 + " to " + destination2);
}



}

public void newDestination()
{
System.out.println ("Enter the new destination for flight 12345 " + id);
newDestination = scan.nextFloat();
//Billings, Montana in example below
}

public void Two()
{
System.out.println ("This is " + flight1 + " Flight " + number1 + " from " + origin1 + " to " + newDestination);

}


public void newOrigin()
{
System.out.println ("Enter the new origin for flight 54321 " + id);
newOrigin = scan.nextFloat();
//cheyenne, Wyoming in example below
}

public void Three()
{
System.out.println ("This is " + flight2 + " Flight " + number2 + " from " + newOrigin + " to " + destination2);

}

public void Four()
{
return id + "First Flight: This is " + flight1 + " Flight " + number1 + " from " + origin1 + " to " + newDestination;
return id + "Second Flight: This is " + flight2 + " Flight " + number2 + " from " + newOrigin + " to " + destination2;

}



}

-----------------------------------------------------------------------------------------






public class FlightTest
{
public static void main (String[] args)
{
Flight fly1 = new Flight();
Flight fly2 = new Flight();

fly1.AirlineName();
fly1.FlightNumber();
fly1.FlightOrigin();
fly1.FlightDestination();

fly2.AirlineName();
fly2.FlightNumber();
fly2.FlightOrigin();
fly2.FlightDestination();

emp1.GetHeading();
System.out.println();
System.out.println (emp1);
System.out.println();
System.out.println (emp2);
}
}








What the program is supposed to look like! :







----jGRASP exec: java FlightTest


This is Delta Flight 12345 From Denver,Colorado to Miami,Florida
This is United Flight 54321 From Boise,Idaho to Las Vegas,Nevada

Enter the new destination for flight 12345
Billings,Montana

This is Delta Flight 12345 From Denver,Colorado to Billings,Montana

Enter the new origin for flight 54321
Cheyenne,Wyoming

This is United Flight 54321 From Cheyenne,Wyoming to Las Vegas,Nevada

First flight: This is Delta Flight 12345 From Denver,Colorado to Billings,Montana
Second flight: This is United Flight 54321 From Cheyenne,Wyoming to Las Vegas,Nevada

----jGRASP wedge2: exit code for process is 0.
----jGRASP: operation complete.