0

public class Class_of_var {

 public  String[] su_name =new String[100];

}

`public class Main_Class {

 public void show_all(int a)
 {
     Class_of_var arr = new Class_of_var() ;

     for (int i = 0; i < a; i++)
     {
      System.out.println("Surname  " + arr.su_name[i]);

     }

 }

public static void main(String[] agrs)
{

    Add_Car Car=new Add_Car();
    Main_Class m = new Main_Class() ;
    Scanner sc = new Scanner(System.in);
      int x = 1;
    int a = 0;
    do
    {
        int y=0;
        System.out.println("enter 1 to add a car");
        System.out.println("enter 3 to show all cars infromation");

        y=sc.nextInt();

        switch (y)
        {

            case 1: 
             *emphasized text*
              Car.add_car(a);
                a++;
                break;

            case 3:

*when i call the s_name in class_of_var the value will be null * System.out.println("the a number" + a); m.show_all(a); break;

        }

    } while (x == 1);

}

}

public class Add_Car { Class_of_var arr = new Class_of_var() ; public void add_car(int a) {

      Scanner sc = new Scanner(System.in);

    System.out.println("enter the surname of owner");
    arr.su_name[a] = sc.nextLine();

}

} `

0 Answers0