title: Printing specific data from an array, fulfilling conditions
body: <p>I have been tasked with writing a code to create 4 classes(<strong>Main, Person,Account,Vehicle</strong>)and create objects of the <strong>Person</strong> class as per user requirements, doing so using an array. I had to store data within the array via user input, and retrieve them as per user choice. Which I believe I have successfully done so. One of the two inputs I had to ask from the user were, &quot;Do you have an Account&quot; and &quot;Do you have a vehicle&quot;. If the User answers &quot;Yes&quot;, I had to pass the object or something as a reference to the <strong>Account</strong> and <strong>Vehicle</strong> class to seclude them separately as well, and when the User asks for the People with an Account and Vehicle, It were to print the details of those specific users only.
  .
  Here is my code below
  <strong>Main.java</strong>:</p>
  <pre><code>package com.company;
  import java.util.Scanner;
  
  public class Main {
  public static int ids;
  static int choice = 0;
  static Scanner sc = new Scanner(System.in);
  public static void main(String[] args) {
      menus();
  }
  public static void conditions(int choice){
      switch (choice) {
          case 1:
              int i;
              System.out.println(&quot;Enter id of person&quot;);
              i = sc.nextInt();
              Person user2[] = new Person[10];
              user2[i] = new Person();
              user2[i].setArray(i,user2);
              //Getters
              int k;
              System.out.println(&quot;Enter id of existing person to retrieve info or press 0 to go to menu&quot;);
              int l;
              l = sc.nextInt();
              if (l == 0) {
                  menus();
              }
              else {
                  System.out.println(user2[l].getName());
                  System.out.println(user2[l].getGender());
                  System.out.println(user2[l].getAge());
                  System.out.println(user2[l].isAccount());
                  System.out.println(user2[l].isVehicle());
              }
          case 2:
              //Call getters
              Account a1=new Account();
              a1.getArrays();
  
  
          case 3:
              Vehicle v1=new Vehicle();
              v1.printArray();
      }
  }
  public static void menus() {
      System.out.println(&quot;Choose an option&quot;);
      System.out.println(&quot;1.Enter new person details&quot;);
      System.out.println(&quot;2.Does not work(should display people who want an acc only&quot;);
      System.out.println(&quot;3.Does not work(Should display people who have a vehicle only)&quot;);
      choice = sc.nextInt();
      conditions(choice);
  }
  </code></pre>
  <p>}</p>
  <p><strong>Person.java</strong>:</p>
  <pre><code>package com.company;
  
  import java.util.Scanner;
  
  public class Person {
      private String name;
      private int age;
      private String gender;
      private static String Account;
      private static String Vehicle;
      Person array[];
  
  
  public String isAccount() {
      return Account;
  }
  
  public void setAccount(String account) {
      Account = account;
  }
  
  public String isVehicle() {
      return Vehicle;
  }
  
  public void setVehicle(String vehicle) {
      Vehicle = vehicle;
  }
  
  public Person[] getArray() {
      return array;
  }
  
  public void setArray(int i,Person[] array) {
      this.array = array;
      Scanner sc=new Scanner(System.in);
      System.out.println(&quot;Enter name&quot;);
      name=sc.next();
      array[i].setName(name);
      System.out.println(&quot;Enter age&quot;);
      age=sc.nextInt();
      array[i].setAge(age);
      System.out.println(&quot;Enter gender&quot;);
      gender=sc.next();
      array[i].setGender(gender);
      System.out.println(&quot;Enter Yes if you want an account,No if otherwise&quot;);
      Account=sc.next();
      if(Account==&quot;Yes&quot;){
          Account user3[] = new Account[10];
          user3[i].setArray(i,this.array);
          user3[i] = new Account(i,name,gender,Account);
  
      }
      else{
          array[i].setAccount(&quot;No&quot;);
      }
      System.out.println(&quot;Enter Yes if you have a vehicle, No if otherwise&quot;);
      Vehicle=sc.next();
      if(Vehicle==&quot;Yes&quot;){
          Vehicle user4[] = new Vehicle[10];
          user4[i] = new Vehicle();
          user4[i].setArray(i,this.array);
      }
      else{
          array[i].setVehicle(&quot;No&quot;);
      }
  }
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public int getAge() {
      return age;
  }
  
  public void setAge(int age) {
      this.age = age;
  }
  
  public String getGender() {
      return gender;
  }
  
  public void setGender(String gender) {
      this.gender = gender;
  }
  </code></pre>
  <p>}</p>
  <p><strong>Accounts.java</strong>:</p>
  <pre><code>package com.company;
  
  public class Account extends Person{
  Account[] arrays;
  private int ages;
  private String names;
  private String genders;
  private String vehicles;
  private String accounts;
  
  Account(int id,String names,String genders,String accounts){
      arrays[id].setNames(names);
      arrays[id].setAges(ages);
      arrays[id].setGenders(genders);
      arrays[id].setAccounts(accounts);
  </code></pre>
  <p>}</p>
  <pre><code>Account(){
  
  }
  
  public com.company.Account[] getArrays() {
      return arrays;
  }
  
  public void setArrays(com.company.Account[] arrays) {
      this.arrays = arrays;
  }
  
  public int getAges() {
      return ages;
  }
  
  
  public void setAges(int ages) {
      this.ages = ages;
  }
  
  
  public String getNames() {
      return names;
  }
  
  
  public void setNames(String names) {
      this.names = names;
  }
  
  
  public String getGenders() {
      return genders;
  }
  
  public void setGenders(String genders) {
      this.genders = genders;
  }
  
  public String getVehicles() {
      return vehicles;
  }
  
  public void setVehicles(String vehicle) {
      this.vehicles = vehicles;
  }
  
  public String getAccounts() {
      return accounts;
  }
  
  public void setAccounts(String accounts) {
      this.accounts = accounts;
  }
  
  public void printArray(){
      for(int k=0;k&lt;array.length;k++){
          System.out.println(array[k]);
      }
  }
  </code></pre>
  <p>}</p>
  <p>My Vehicle class is the same as Accounts.
  -To seclude and print
  -I have tried to pass the array from the Person class to the Accounts class and Vehicle, If the User does wish to have an Account and has a Vehicle.
  -However, upon printing via for loop or a basic getter, I am met with an Error &quot;this.array is null&quot; which probably means my Array isnt being passed or stored within the Account class.
  -Maybe there is a simpler way of secluding and printing them, as per the task I have to implement the use of Abstraction, Arrays, Constructors and Functions.
  I am new to Java and the Stackoverflow platform, so please forgive me If the formatting of the question isnt precise. Hope to recieve some detailed help on getting around this.</p>