Likes

Java Lab02 Ans1

Wrire a Proram to creat a class that stores the train reservation details. In addition, define a method that will display the stored details..

ANSWER

1. Create a Java application, Lab02_Ans1.
2. Create a class, Reservation, in the Java application, Lab02_Ans1.
3. Replace the exisiting code in the Reservation.java file with following code:

   public class Reservation {

int ticketID;
String name;
String source;
String destination;

Reservation()   {
ticketID = 80;
name ="Harry";
source = "Chicago"
destination = "Dallas";
}


public void showTicket ()  {
         System.out.println("The Ticket ID is "+ ticketID);
         System.out.println("The Passenger Name is "+ name);
         System.out.println("The Sourse is" + sourse);
         System.out.println("The Destination is" + Destination);
         System.out.println("\nChoose the option:  ");


public static void main(String[] args)  {
Reservation g = new Reservation();
g.showTicket();
    }
}