mardi 27 octobre 2015

Getter method not working in enhanced loop

I'm making an enhanced for loop to sort through part objects in my part array list. But when the enhanced for loop gets to the if statement it doesn't do anything(with exception to Damper) and there are no errors so i don't know why it's not working. thelist is the name of my array list holding objects.

    for(int z=0; z<20; z++){
        displayMenu();
            int selection = sc.nextInt();
            if(selection == 0){
                System.out.println("You have exited the system");
            } else if(selection == 1){  
                System.out.println("Choose stock name to replenish");
                for(Part y: thelist){
                    String nS = sc.nextLine();
                    System.out.print(nS);
                    if(nS.equals(y.getName())){
                        System.out.println("Please enter replenish quantity");
                        int qty = sc.nextInt();
                        y.replenish(qty);
                        System.out.println("Complete");
                    }
                }
            } else if

My objects

    Part part0 = new Part("p100", "Spring", 43, 120);
    Part part1 = new Part("p101", "Damper", 72, 150);
    Part part2 = new Part("p102", "Lower CA", 38, 80);
    Part part3 = new Part("p103", "Upper CA", 26, 70);

And just to show that up to 'String nS' is working

Also, it works for Damper only

Aucun commentaire:

Enregistrer un commentaire