0

Within a class, this method was purpose-constructed to remove an item from an array list.

import java.util.Scanner;
import java.util.ArrayList;
import static java.util.Arrays.*;
/************************
 * This part enables the user to add an item, remove an item, and view the list.
 * Created 17 FEB 2016
************************/
public class Menu
{

    public Scanner aryans = new Scanner(System.in);

    public String additem1 = "1";
    public String removeitem1 = "2";
    public String viewlist1 = "3";
    public String startISLA = "j";

    Item item; // From the Item class
    String itemName;
    double itemPrice;
    int quantity;

    UPC upc; // From the UPC class
    int universalproductcode;

    Location location; // From the Location class
    String locations;

    ItemList list1 = new ItemList();

    String keepShopping = "j";
    String continueISLA= "n";

    public Menu()
    {

        Drivingmethod();

    }

    public void Drivingmethod()
    {

        System.out.println("Start ISLA (j/n)? "); // input "admin" for full access to the program
        String userused = aryans.nextLine();


        if(userused.equals(startISLA))
        {

            System.out.println(" __________________________"); // Menu lines
            System.out.println("| 1: Add item              |");
            System.out.println("| 2: Remove item           |");
            System.out.println("| 3: View list             |");
            //System.out.println("| 4: Restart               |");
            System.out.println("|__________________________|");
            System.out.println("> Input selection: ");
            String ans1 = aryans.nextLine();

            if(ans1.equals(additem1))
            {

                addItem(); // add an item

            }
            else
            {

                if(ans1.equals(removeitem1))
                {

                    removeItem(); // remove an item

                }
                else
                {

                    if(ans1.equals(viewlist1))
                    {

                        viewList(); // view the list

                    }
                    else
                    {

                        if(ans1 == "4")
                        { 

                            Drivingmethod(); // returns you two the start.

                        }

                    }

                }

            }

        }

    }


    public void addItem()
    {

        do 
        {

            System.out.print("> Input item name: ");
            aryans.nextLine();
            itemName = aryans.nextLine();
            System.out.print("> Input item price: ");
            itemPrice = aryans.nextDouble();
            System.out.print("> Input item quantity: ");
            quantity = aryans.nextInt();
            System.out.print("> Input item UPC: ");
            universalproductcode = aryans.nextInt();
            System.out.print("> Input item location: ");
            aryans.nextLine();
            locations = aryans.nextLine(); // I was getting issues with this line, but this new way of setting the string fixed it. Applied this alternative to "itemName".
            list1.addToList(itemName, itemPrice, quantity, universalproductcode, locations);
            System.out.print("> Add another item (j/n)? ");
            keepShopping = aryans.nextLine();

        }

        while (keepShopping.equalsIgnoreCase("j"));

        if (keepShopping.equalsIgnoreCase("n"))
        {

            Drivingmethod();

        }

    }

    public void removeItem()
    {

        System.out.println(list1);
        System.out.println("Input the number of items you wish to remove: ");

        int Q = 1;
        int removenumberitems = aryans.nextInt();

        while(Q <= removenumberitems)
        {

            System.out.print("Input the numerical location of the item: ");
            int index1 = aryans.nextInt();
            list1.remove(index1);

            System.out.println(list1.get(index1) + " was successfully removed from the list.");

            Q++;

        }

    }

    public void viewList()
    {

        System.out.println(list1);
        System.out.println("Would you like to end ISLA (j/n)?");

        if (continueISLA.equalsIgnoreCase("n"))
        {

            Drivingmethod();

        }

    }

}

However, while compiling, I BlueJ highlights "remove" in the line "list1.remove(index1);" as an error, stating "cannot find symbol - method remove(int)".

What is causing this problem and how can I fix it in my code?

  • Please post a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). What is the type of `list1`? – MikeCAT Mar 25 '16 at 01:07
  • ItemList list1 = new ItemList(); – Walt Ziegler Mar 25 '16 at 01:08
  • `ItemList` doesn't seem in the [Java Standard API](https://docs.oracle.com/javase/8/docs/api/index.html). Please include the class in your question. – MikeCAT Mar 25 '16 at 01:09
  • It simply means that type of `list1` reference doesn't implement nor inherit `remove(int)` method so you can't use it. Which part of your code makes you think that your code should work? – Pshemo Mar 25 '16 at 01:12

0 Answers0