0

I'm making an application to keep inventory of homes. I give a menu where the user can choose an action, such as add a home to the inventory, and the first time it runs fine and accepts all inputs. When I go to add a second item to the inventory, the first variable is skipped and the input is directed to the second variable immediately, what am I doing wrong? I attached the code blocks that add a home. In the photo you can see I choose to add another home and it immediately skips the model name

enter image description here

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        boolean skip = false;
        Scanner input = new Scanner(System.in);
        while(!skip){
            System.out.println("Welcome to your home inventory. Please make a selection");
            System.out.println("1: Add a home");
            System.out.println("2: Remove a home");
            System.out.println("3: Check Inventory");
            System.out.println("4: Update a home");
            System.out.println("5: Find home details");
            System.out.println("6: Print inventory to text file");
            System.out.println("7: Exit menu");
            int response = input.nextInt();
            switch (response) {
                case 1 -> HomeInventory.add();
                case 2 -> HomeInventory.remove();
                case 3 -> HomeInventory.listInventory();
                case 4 -> HomeInventory.update();
                case 5 -> HomeInventory.listInfo();
                case 7 -> skip = true;
                default -> System.out.println("Could not define action");
            }
        }
    }

    public static void add() {
        try {
            new HomeInventory();
        } catch (Exception e) {
            System.out.println("Failure to add to inventory");
        }
    }

    public HomeInventory() {
        System.out.println("Enter the model name:");
        this.modelName = input.nextLine();
        System.out.println("Enter the sale status:");
        this.saleStatus = input.nextLine();
        System.out.println("Enter the address:");
        this.address = input.nextLine();
        System.out.println("Enter the city:");
        this.city = input.nextLine();
        System.out.println("Enter the state:");
        this.state = input.nextLine();
        System.out.println("Enter the zip code:");
        this.zipCode = input.nextInt();
        System.out.println("Enter the square feet:");
        this.squareFeet = input.nextInt();
        try {
            inventory.add(this);
            System.out.println("Successfully added " + this.modelName + " to inventory");
        } catch (Exception e) {
            System.out.println("Failure adding to inventory");
        }
    }
}
Abra
  • 19,142
  • 7
  • 29
  • 41

0 Answers0