I am a first year student and learning setter and getter at school. When I run it, it is ignoring the following statement:
String Origin = scan.nextLine();
and then it goes to the next line.
Here is the main:
import java.util.Scanner;
public class FlightTest
{
public static void main (String [] args)
{
Scanner scan = new Scanner (System.in);
Flight Flight1 = new Flight ();
System.out.print ("Airline Name: ");
String AirlineName = scan.nextLine ();
System.out.print ("Flight Number: ");
int FlightNumber = scan.nextInt ();
System.out.print ("Origin: ");
String Origin = scan.nextLine(); // There is a problem here
System.out.print ("Destination: ");
String Destination = scan.nextLine ();
}
}
This is the class
public class Flight
{
private String AirlineName;
private int FlightNumber;
private String Origin;
private String Destination;
public String setAirlineName()
{
String Name = AirlineName;
return Name;
}
public String getAirlineName()
{
return AirlineName;
}
public int setFlightNumber ()
{
int Number = FlightNumber;
return Number;
}
public int getFlightNumber ()
{
return FlightNumber;
}
public String setOrigin ()
{
String Orig = Origin;
return Orig;
}
public String getOrigin ()
{
return Origin;
}
public String setDestination ()
{
String Desti = Destination;
return Desti;
}
public String getDestination ()
{
return Destination;
}
public String toString ()
{
String result = AirlineName + " flight number "
+ FlightNumber + " leaves from " + Origin + " to "
+ Destination + ".";
return result;
}
}