monorail problem in java

import java.util.ArrayList;

import java.util.Scanner;

class assg05

{

      private static final Scanner in = new Scanner(System.in);

     

      public static void main(String s[])

      {

             ArrayList<Train> train = new ArrayList<Train>();

             ArrayList<Monorail> mono = new ArrayList<Monorail>();

           

             while(true)

             {

                   System.out.println("\n\n1. Add a train\n2. Add sequential stoppages\n3. Print train stoppages\n4.Add Mono rail\n5.Print Capacity");

                   System.out.print("Enter your choice: ");

                   int choice = in.nextInt();

                   in.nextLine();

                   switch(choice)

                   {

                         case 1: train.add(new Train());

                         break;

                         case 2: System.out.print("Enter the tain no: ");

                                 int nos = in.nextInt();

                                 in.nextLine();

                                 boolean flag = false;

                                 for(int i=0; i<train.size(); ++i)

                                 {

                                    flag = false;

                                    if(train.get(i).trainNo == nos)

                                    {

                                       train.get(i).addStop();

                                       flag = true;

                                       break;

                                    }  

                                 }

                               

                                 if(flag == false)

                                   System.out.println("Train Number not found");    

                         break;

                         case 3: System.out.print("Enter the tain no: ");

                                 int no = in.nextInt();

                                 in.nextLine();

                                 boolean flag1 = false;

                                 for(int i=0; i<train.size(); ++i)

                                 {

                                    flag1 = true;

                                    if(train.get(i).trainNo == no)

                                    {

                                       train.get(i).printStops();

                                       flag = true;

                                       break;

                                    }  

                                 }

                               

                                 if(flag1 == false)

                                   System.out.println("Train Number not found");

                         break;

                         case 4: mono.add(new Monorail());

                         break;

                         case 5: System.out.print("Enter the tain no: ");

                                 int no1 = in.nextInt();

                                 in.nextLine();

                                 boolean flag2 = false;

                                 for(int i=0; i<mono.size(); ++i)

                                 {

                                    flag1 = true;

                                    if(mono.get(i).trainNo == no1)

                                    {

                                       mono.get(i).printSeatCapacity();

                                       flag2 = true;

                                       break;

                                    }  

                                 }

                               

                                 if(flag2 == false)

                                   System.out.println("Train Number not found");

                         break;

                         case 6: System.exit(0);

                         default:System.out.println("Wrong choice entered");

                   }

             }

      }                

     

}

class Train

{

       private Scanner in = new Scanner(System.in);

       public static int n;

       public String source,destination;

       public int start,reach,totSeat,trainNo, noStop;

       public String stopArrival[][];

         

       Train()

       {

           

            System.out.print("Enter the source of train: ");

            source = in.nextLine();

            System.out.print("Enter the destination of train: ");

            destination = in.nextLine();

            System.out.print("Enter Start time: ");

            start = in.nextInt();

            System.out.print("Enter End time: ");

            reach = in.nextInt();

            System.out.print("Enter total no of seats: ");

            totSeat = in.nextInt();

            in.nextLine();

           

            ++n;

            trainNo = n;

            System.out.print("Train No: "+trainNo+"\n");

           

       }          

           

     

       public void addStop()

       {

              System.out.print("Enter the no. of stoppages:");

              noStop = in.nextInt();

           

              in.nextLine();

              stopArrival = new String[noStop][2];

             

              for(int i = 0; i<noStop; ++i)

              {

                  System.out.print("Enter the stopppage name: ");

                  stopArrival[i][0] = in.nextLine();

                  System.out.print("Enter the arrival time: ");

                  stopArrival[i][1] = in.nextLine();

              }  

                 

       }

     

       public void printStops()

       {

             System.out.printf("%-15s%15s%n","Stoppage Name","Arrival Time");

             System.out.println("-----------------------------------------");

             for(int i =0; i<noStop; ++i)

             {

                System.out.printf("%-15s%15s%n",stopArrival[i][0],stopArrival[i][1]);

             }

             System.out.println("-----------------------------------------");

       }

}

class Monorail extends Train

{

      private final Scanner in = new Scanner(System.in);

      String modelName;

      int ecoNo;

      int busNo;

     

      Monorail()

      {

          System.out.print("Enter the model name: ");

          modelName = in.nextLine();

          System.out.print("Enter seats no in economy class: ");                

          ecoNo = in.nextInt();

          System.out.print("Enter seats no in economy class: ");                

          busNo = in.nextInt();

         

          in.nextLine();

     }

   

     public void printSeatCapacity()

     {

         System.out.println("Model name: "+modelName);

         System.out.println("Seat Capacity: "+(ecoNo+busNo));

         System.out.println("Train no: "+ trainNo);

     }  

}          

           

           

           

           

           

           

           

           

           

/*

 * To change this license header, choose License Headers in Project Properties.

 * To change this template file, choose Tools | Templates

 * and open the template in the editor.

 */

package powerset;

import java.util.Scanner;

/**

 *

 * @author Vinayak

 */

public class Powerset {

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic here

        Scanner in=new Scanner(System.in);

        System.out.println("enter the no of elements");

        int n=in.nextInt();

        int[] x=new int[n];

        for(int i=0;i<n;i++)

        {

            System.out.println("enter the number");

            x[i]=in.nextInt();

        }

       

       

       

    }

   

}
monorail problem in java monorail problem in java Reviewed by Unknown on 03:47 Rating: 5

1 comment:

  1. Best casinos to play slots & casino games in MI 2021
    This casino is close to the rest of the state. The 인천광역 출장안마 games available 목포 출장안마 at casinos that 사천 출장샵 accept 밀양 출장마사지 American players include Mega Fortune, Wheel 바카라 사이트 of Fortune,

    ReplyDelete

Powered by Blogger.