I have a menu system that will print various information about an ArrayList. In my third case I have to call a method that prints the size of the arraylist. The method that I am trying to call is part of the same class. These are the error messages that I am receiving. How would I resolve these?
error:
non-static method printrecordnumber(ArrayList<vehicle>) cannot be referenced from a static context
case 3: System.out.println("Number of records: " + printrecordnumber(vehiclearray));
error:
'void' type not allowed here
case 3: System.out.println("Number of records: " + printrecordnumber(vehiclearray));
Here is the code I have:
//Menu System
do{
System.out.println("Enter number of option or stop to stop the program\n1. Print all data\n2. Print all data (Sorted)\n3. Print number of records\n4. Print Bicycles and Trucks from the sorted data\n5. Print vehicles from area code 987");
try{
String option = input.next();
if((option.equals("stop"))) {
System.exit(0);
}
int optionint = Integer.parseInt(option);
switch (optionint){
case 1:
break;
case 2:
break;
case 3:
System.out.println("Number of records: " + printrecordnumber(vehiclearray));
break;
case 4:
break;
case 5:
break;
}
}
catch (NumberFormatException e){}
}while(true);
//Main Method Ending Bracket
}
public void printrecordnumber(ArrayList<vehicle> vehiclearray){
System.out.println(vehiclearray.size());
}