Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to create a menu that deletes certain plants or an id number from the arr

ID: 3712503 • Letter: I

Question

I want to create a menu that deletes certain plants or an id number from the array list. Here is the stub methods, I want to use this structure.

public void deletePlants(ArrayList<Plants> st) // menu item #7
   {
       //calls the menuDelete method below
       menuDelete();
       // write the code to do the item depending on their choice
       Scanner scan = new Scanner(System.in);
       int ans=0;
        while (true)
        {
            menuDelete();
            System.out.println("CHOICE:");
            ans = scan.nextInt();
          
       if (ans==1)
         {
            //delete plants from existing inventory, remove the entire plants

            
         }             
         if (ans==2)
         {
            // remove the plant (delete id) from inventory, just delete the id number          
         }         
       
         if (ans == 3)
         {
            // Go back to the main menu
         }
   }
   }

here is the array list info:

ArrayList<Plants> plants = new ArrayList<Plants>();
       plants.add(new Plants("JAPMA", "Japanese Maple", 30, 60.25, 85.50));
       plants.add(new Plants("DOG", "Dogwood", 20, 15.50, 32.50));
       plants.add(new Plants("RED", "Redbud", 45, 21.00, 28.00));
       plants.add(new Plants("RBUCK", "Red Buckeye", 24, 21.00, 33.00));
       plants.add(new Plants("CRMY", "Crape Myrtle", 48, 19.00, 29.50));
       plants.add(new Plants("TULIP", "Tulip Tree", 30, 23.00, 38.50));
       plants.add(new Plants("FALSE", "Hinoki False Cypress", 40, 18.35, 29.50));
       plants.add(new Plants("SERVICE", "Serviceberry", 30, 43.00, 58.50));
       plants.add(new Plants("SMOKE", "Smoke Tree", 18, 34.00, 45.50));
       return plants;

Explanation / Answer

Following is the answer:

public void deletePlants(ArrayList<Plants> st) // menu item #7

{

//calls the menuDelete method below

menuDelete();

// write the code to do the item depending on their choice

Scanner scan = new Scanner(System.in);

int ans=0;

boolean exit = false;

do

{

menuDelete();

System.out.println("CHOICE:");

ans = scan.nextInt();

  

if (ans==1)

{

plants.removeAll();

break;

  

}

if (ans==2)

{

plants.remove(id);   

break;

}

if (ans == 3)

{

exit = true;

break;

}

}while(!true)

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote