1 Replies - 745 Views - Last Post: 04 March 2009 - 07:43 PM Rate Topic: -----

#1 swim_fan08  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 19-February 09

Errors in class and driver

Post icon  Posted 04 March 2009 - 06:47 PM

Can someone please check my driver and my class? I keep getting errors also.

Here is what I am suppose to have:

This will require you to create a Flight class and a driver program for the flight class (called FlightTest). In the driver program:

* Instantiate a Flight object named JillsFlight with the following data:
o Delta
o 809
o Lexington KY (no commas in data)
o Dallas TX
Use literal values in the instantiation statement (using the constructor) for the JillssFlight object.
* Instantiate a second flight for you. Input the values from the keyboard and the call the constructor passing the variables.
* Using the toString method in the Flight class, print flight information for both Flight objects.
* Input a change in the airline and flight number for Jill. Update the data using the mutator methods for airline and flight. Display the new flight information using the toString method in the Flight class.
* Using accessors for flight origin and destination, retrieve the flight origin and destination for your flight and print a message (not using the toString method) simlar to:
Departure: SomeCity SomeState ----- Arrival: AnotherCity AnotherState

Flight class
public class FlightTest
{
	private String Name;
	private	String Airline;
	private	int flightNumber;
	private	String Origin;
	private String Destination;

	//--------------------------------------------------------------------------------
	//  Constructor - has 5 parameters: name, airline, flight, orgin, and
	//destination
	//--------------------------------------------------------------------------------

	public FlightTest(String cName, String cAirline, int cflightNumber,String cOrigin,String cDestination)
	{
		Name = cName;
		Airline = cAirline;
		flightNumber = cflightNumber;
		Origin=cOrigin;
		Destination=cDestination;

	}

	//--------------------------------------------------------------------------------
	//  Constructor - Default:
	//--------------------------------------------------------------------------------

	public FlightTest()
	{
		Name = "";
		Airline= "";
		flightNumber=0;
		Origin= "";
		Destination = "";

	}

	//--------------------------------------------------------------------------------
	//  Accessors
	//--------------------------------------------------------------------------------

	public String getName()
	{
		return Name;
	}

	public int getAirline()
	{
		return Airline;
	}

	public int getFlightNumber()
	{
		return flightNumber;
	}

	public String getOrigin()
	{
		return Origin;
	}
	public String getDestination()
	{
		return Destination;
	}

	//--------------------------------------------------------------------------------
	//  Mutators
	//--------------------------------------------------------------------------------

	public void setName(String cName)
	{
		Name = cName;
	}
	public void setAirline(String cAirline)
	{
		Airline = cAirline;
	}

	public void setFlightNumber(int cflightNumber)
	{
		flightNumber = cflightNumber;
	}

	public void setOrigin (String cOrigin)
	{
		Origin=cOrigin;
	}

	public void setDestination(String cDestination)
	{
		Destination=cDestination;
	}


---------------------------------------------
Driver
import java.util.Scanner;

public class JillsFlight
{
	public static void main (String[] args)
	{
		Scanner in = new Scanner (System.in);

		//-----------------------------------------------------------------------------------------------
		// New objects are instantiated using the Flight class (Jill and You)
		//-----------------------------------------------------------------------------------------------

		FlightTest Jill = new FlightTest ("Jill","Delta", 809, "Lexington KY", "Dallas TX");
		FlightTest You = new FlightTest();

		//-----------------------------------------------------------------------------------------------
		// Variables are declared
		//-----------------------------------------------------------------------------------------------

		String Name;
		String Airline;
		int flightNumber;
		String Origin;
		String Destination;


		//-----------------------------------------------------------------------------------------------
		// Data is input for the You object
		//-----------------------------------------------------------------------------------------------

		System.out.print ("Name: ");
		Name = in.nextLine();


		System.out.print ("Airline: ");
		Airline= in.nextLine();

		System.out.print ("Flight number: ");
		flightNumber= in.nextInt();

		System.out.print ("Origin: ");
		Origin=in.nextLine();

		System.out.print("Destination: ");
		Destination=in.nextLine();
		System.out.println();


		//-----------------------------------------------------------------------------------------------
		// The data values for You are updated using mutators
		//-----------------------------------------------------------------------------------------------

		You.setName(Name);
		You.setAirline(Airline);
		You.setFlightNumber(flightNumber);
		You.setOrigin(Origin);
		You.setDestination(Destination);


		//-----------------------------------------------------------------------------------------------
		// Data values for the objects are printed
 		//-----------------------------------------------------------------------------------------------

		System.out.println (Jill.toString());
		System.out.println (Name + Airline + flightNumber + Origin + Destination + "\n");

		System.out.println (You.toString());
		System.out.println (Name + Airline + flightNumber + Origin + Destination + "\n");


	}
}


Errors that I get in the flight class
java:105: <identifier> expected
System.out.println("Departure: " + Origin + "Arrival: " + Destination);

java:105: illegal start of type
System.out.println("Departure: " + Origin + "Arrival: " + Destination);

Errors that I get in the driver
\FlightTest.java:105: <identifier> expected
System.out.println("Departure: " + Origin + "Arrival: " + Destination);

\FlightTest.java:105: illegal start of type
System.out.println("Departure: " + Origin + "Arrival: " + Destination);

\FlightTest.java:105: cannot find symbol
symbol : class out
location: class java.lang.System
System.out.println("Departure: " + Origin + "Arrival: " + Destination);
^
.\FlightTest.java:56: incompatible types
found : java.lang.String
required: int
return Airline;

Is This A Good Question/Topic? 0
  • +

Replies To: Errors in class and driver

#2 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Errors in class and driver

Posted 04 March 2009 - 07:43 PM

Just change the return type of this method
    public int getAirline()
    {
        return Airline;
    }



To String and the code you posted will run fine, Though The rest of the errors it appears the code you psoted is incomplete, you will have to post the rest of your code for your flightTest to determine the remaining errors.

Also here:

Quote

System.out.print ("Origin: ");
Origin=in.nextLine();

System.out.print("Destination: ");
Destination=in.nextLine();
System.out.println();


I would use the next method not next line or else it won't work as you intend
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1