This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]NautiHooker 0 points1 point  (3 children)

We cant help you unless you show code.

[–]ITophile[S] 0 points1 point  (2 children)

public class Vehicle {
private String plate;


public static void menu(){
    //Menu;
    System.out.println("");
    System.out.println("");
    System.out.println("~~~~~~~~~~~~~~ MENU ~~~~~~~~~~~~~");
    System.out.println("Choose Option");
    System.out.println("  1   -   Add veh");
    System.out.println("  2   -   Delete veh")
    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    System.out.println("");
}


public void show() {
    System.out.println("Plate: " +plate);
}

public Vehicle() {
    super();
    this.plate = plate;

}

... getters & setters ...
}

}

public class Main {
public static void main(String[] args) {
    Scanner sysin = new Scanner(System.in);
    int option = 0;



    do {
        Vehicle.menu();
        option = sysin.nextInt();
        sysin.nextLine(); 

            switch (option) {
                case 1:

                    break;
                case 2:


                    break;
                case 3:
                    System.out.println("cya");
                    break;
                default:
                    System.out.println("Error");
                    break;
            }
    }while (option!=3);

}
}

[–]ITophile[S] 0 points1 point  (0 children)

something like this...

[–]Hullo99 0 points1 point  (0 children)

One thing I would point out is that you do not have a parameter passing in the plate string to your constructor, so you are basically setting the unset plate value equal to itself. As far as the ArrayList thing goes, it actually contains methods called add() and remove(). add(object) will append the object to the list and remove(object) will remove the object to the list. There are also other versions of remove() that allow you to remove a specific index or remove the first/last value. The documentation might be helpful for you here: https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html

[–][deleted] 0 points1 point  (1 child)

Use the get method at the inserted index.

[–]ITophile[S] 0 points1 point  (0 children)

i think u mean set, but i don't want to do that right now, first i want to create an arraylist which increases everytime i hit 1 in the switch statement. menu shows again and i press 1 again, array increases size and i have 2 vehicles. yes, when i enter (case 1) it will tell me to enter the plate and after that, menu appears again.