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

Java Program - GUI help - Create an interface for the user to add, remove, sort,

ID: 3818237 • Letter: J

Question

Java Program - GUI help

- Create an interface for the user to add, remove, sort, filter, save and load information from our flower pack.
-You should USE ALL of the following at least once in your interface:
       JFrame
       JButton
       JLabel
       JTextField
       JCheckBox / JRadioButton
       Layout (Flow, grid,or border layouts)
       JMenu
       JMenuItem

-The flower pack should hold flowers, weeds, fungus, and now herbs. All should be a subclass of a plant class.
-Each subclass shares certain qualities (ID, Name, and Color)
-Flower traits include (Thorns, and Smell)
-Fungus traits include (Poisonous)
-Weed traits include (Poisonous, Edible and Medicinal)
-Herb traits include (Flavor, Medicinal, Seasonal)

Use the code below:

package flowerpack;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Scanner;

public class FlowerPack {
   public static void main(String[] args) {
       try{
           ArrayList flowerPack= new ArrayList<>();
           Scanner input=new Scanner(System.in);
           int choice;
           String name, color, ID;
           boolean poisonous,edible,medicinal,smell,thorns;
           while(true)
           {
               System.out.println(" 1. Add plants");
               System.out.println("2. Remove plants");
               System.out.println("3. Search plants");
               System.out.println("4. Filter plants");
               System.out.println("5. Save to file");
               System.out.println("6. Load from file");
               System.out.println("7. Quit");
               System.out.print("Enter your choice: ");
               choice=input.nextInt();
               switch(choice)
               {
               case 1:
                   input.nextLine();
                   System.out.print("You want to add Flower, Fungus or Weed? ");
                   String type=input.nextLine();
                   if(type.equalsIgnoreCase("Flower"))
                   {
                       System.out.print("Enter name : ");
                       name=input.nextLine();
                       System.out.print("Enter ID : ");
                       ID=input.nextLine();
                       System.out.print("Enter color : ");
                       color=input.nextLine();
                       System.out.print("Has thorns? ");
                       thorns=input.hasNextBoolean();
                       input.nextLine();
                       System.out.print("Has smell? ");
                       smell=input.hasNextBoolean();
                       input.nextLine();
                       flowerPack.add(new Flower(name,ID,color,thorns,smell));
                   }
                   else if(type.equalsIgnoreCase("Fungus"))
                   {
                       System.out.print("Enter name : ");
                       name=input.nextLine();
                       System.out.print("Enter ID : ");
                       ID=input.nextLine();
                       System.out.print("Enter color : ");
                       color=input.nextLine();
                       System.out.print("Is it poisonous? ");
                       poisonous=input.hasNextBoolean();
                       input.nextLine();
                       flowerPack.add(new Fungus(name,ID,color,poisonous));
                   }
                   else if(type.equalsIgnoreCase("Weed"))
                   {
                       System.out.print("Enter name : ");
                       name=input.nextLine();
                       System.out.print("Enter ID : ");
                       ID=input.nextLine();
                       System.out.print("Enter color : ");
                       color=input.nextLine();
                       System.out.print("Is it Poisonous? ");
                       poisonous=input.hasNextBoolean();
                       input.nextLine();
                       System.out.print("Is it Edible? ");
                       edible=input.hasNextBoolean();
                       input.nextLine();
                       System.out.print("Is it Medicinal? ");
                       medicinal=input.hasNextBoolean();
                       input.nextLine();
                       flowerPack.add(new Weed(name,ID,color,poisonous,edible,medicinal));
                   }
                   break;
               case 2:input.nextLine();
               System.out.print("Enter the name of the plant you want to remove : ");
               name=input.nextLine();
               int flag=0;
               for(Plant plant:flowerPack)
               {
                   if(plant.getName().equalsIgnoreCase(name))
                   {
                       System.out.println("plant removed sucessfully") ;
                       flag=1;
                       break;
                   }
               }
               if(flag==0)
               {
                   System.out.println("plant not found") ;
               }
               break;
               case 3:
                   input.nextLine();
                   System.out.print("Enter the name of the plant you want to search : ");
                   name=input.nextLine();
                   int f=0;
                   for(Plant plant:flowerPack)
                   {
                       if(plant.getName().equalsIgnoreCase(name))
                       {
                           System.out.println("plant found sucessfully") ;
                           f=1;
                           break;
                       }
                   }
                   if(f==0)
                   {
                       System.out.println("plant not found") ;
                   }
                   break;
               case 4:
                   input.nextLine();
                   System.out.print("Enter the name of the plant you want to filter: ");
                   name=input.nextLine();
                   f=0;
                   for(Plant plant:flowerPack)
                   {
                       if(plant.getName().equalsIgnoreCase(name))
                       {
                           System.out.println("Name: " + plant.getName() + " ID: " + plant.getID()) ;
                           f=1;
                       }
                   }
                   if(f==0)
                   {
                       System.out.println("NO plant of this name in List") ;
                   }
                   break;
               case 5:
                   File file = new File("Plants.txt");
                   FileOutputStream fStream = new FileOutputStream(file);
                   ObjectOutputStream stream = new ObjectOutputStream(fStream);
                   stream.writeObject(flowerPack);
                   stream.close();
                   break;
                
               case 6:
                   File file2 = new File("Plants.txt");
                   FileInputStream fileStream = new FileInputStream(file2);
                   ObjectInputStream oStream = new ObjectInputStream(fileStream);
                   ArrayList readObject = ((ArrayList)oStream.readObject());
                   flowerPack.addAll(readObject);
                   oStream.close();
                   break;
               case 7: System.exit(0);
               }
           }
       }catch(Exception e)
       {
           System.out.println(e);
       }
   }

}

*******
package flowerpack;

import java.io.Serializable;

public class Plant implements Serializable{
String name;
String ID;
Plant(String name,String ID)
{
this.name=name;
this.ID=ID;
}
public String getName()
{
return name;
}
public String getID()
{
return ID;
}

********
package flowerpack;

class Fungus extends Plant
{
String Color;
boolean Poisonous;
public Fungus(String name, String ID,String Color,boolean Poisonous) {
super(name, ID);
this.Color=Color;
this.Poisonous=Poisonous;
}
}
*******
package flowerpack;

class Flower extends Plant
{
String color;
boolean thorns;
boolean smell;
public Flower(String name, String ID,String color,boolean thorns,boolean smell) {
super(name, ID);
this.color=color;
this.thorns=thorns;
this.smell=smell;
}
}
*********
package flowerpack;

class Weed extends Plant
{
String Color;
boolean Poisonous;
boolean Edible;
boolean Medicinal;
public Weed(String name, String ID,String Color,boolean Poisonous,boolean Edible, boolean Medicinal) {
super(name, ID);
this.Color=Color;
this.Poisonous=Poisonous;
this.Edible=Edible;
this.Medicinal=Medicinal;
}
}

Explanation / Answer

PlantDriverGUI.java

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Font;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;


public class PlantDriverGUI extends JFrame {
        JRadioButton rdoBtnPlant, rdoBtnFlower, rdoBtnHerb, rdoBtnWeed, rdoBtnFungus;
        JCheckBox isPoisonous, isEdible, isMedicinal, isNicelyFlavored, isSeasonal, hasThorns, smellsNice;
        JButton btnAdd, btnRemove, btnFilter, btnClear, btnSort, btnDisplayPlants;
        JTextField txtPlantID, txtColor, txtName;
        JScrollPane scrollPane;
        JTextArea plantSummary;
        JMenuBar appMenu;
        JMenu fileMenu;
        JMenuItem open, save;
      
        ArrayList<Plant> plantList = new ArrayList();
      
   public PlantGUIDriverFinalAssignment() {
            try {
                this.setTitle("Iziren's Plant Interface");
                setLayout(new FlowLayout());
                JPanel plantPanel1 = new JPanel(); //Create a Pane to add components within them to better organize the UI
                JPanel plantPanel2 = new JPanel(); //Create another Panel to hold more plant components (checkboxes, etc)
                JPanel plantPanel3 = new JPanel(); //Create this panel to hold buttons.
                JPanel plantPanel4 = new JPanel(new BorderLayout()); //Create this Panel to hold TextArea plantSummary
              
                rdoBtnPlant = new JRadioButton("Plant");
                rdoBtnFlower = new JRadioButton("Flower");
                rdoBtnWeed = new JRadioButton("Weed");
                rdoBtnHerb = new JRadioButton("Herb");
                rdoBtnFungus = new JRadioButton("Fungus");              

                rdoBtnPlant.setSelected(true);

                //Create a group of Radio Buttons
                ButtonGroup plantSelection = new ButtonGroup();
                plantSelection.add(rdoBtnPlant);
                plantSelection.add(rdoBtnFlower);
                plantSelection.add(rdoBtnHerb);
                plantSelection.add(rdoBtnWeed);
                plantSelection.add(rdoBtnFungus);
                JLabel plantSelectLabel = new JLabel("Please select from the following plants to add below: ");
                plantSelectLabel.setFont(new Font("Serif", 20, 20));
              
                //Add radio buttons to contentPane
                add(plantSelectLabel);
                add(rdoBtnPlant);
                add(rdoBtnFlower);
                add(rdoBtnWeed);
                add(rdoBtnHerb);
                add(rdoBtnFungus);
              
                rdoBtnPlant.addActionListener(new RadioHandler());
                rdoBtnFlower.addActionListener(new RadioHandler());
                rdoBtnHerb.addActionListener(new RadioHandler());
                rdoBtnWeed.addActionListener(new RadioHandler());
                rdoBtnFungus.addActionListener(new RadioHandler());
                JLabel clrLabel = new JLabel("Enter Color:");
              
                txtColor = new JTextField("",15);
              
                JLabel plantIdentity = new JLabel("Enter Name:");
              
                txtName = new JTextField("",15);
                JLabel idLabel = new JLabel("Enter ID:");
              
                txtPlantID = new JTextField("", 15);
              
                plantPanel1.add(clrLabel);
                plantPanel1.add(txtColor);
                plantPanel1.add(plantIdentity);
                plantPanel1.add(txtName);
                plantPanel1.add(idLabel);
                plantPanel1.add(txtPlantID);
                add(plantPanel1);
              
                //Create CheckBoxes for Boolean value representations (0 and 1 / True or False)
                JLabel traits = new JLabel("Traits:");
                isPoisonous = new JCheckBox("Poisonous");
                isEdible = new JCheckBox("Edible");
                isMedicinal = new JCheckBox("Medicinal");
                isNicelyFlavored = new JCheckBox("Nice Flavor");
                isSeasonal = new JCheckBox("Seasonal");
                hasThorns = new JCheckBox("Thorny");
                smellsNice = new JCheckBox("Smells Nice");
                isPoisonous.setEnabled(false);
                isEdible.setEnabled(false);
                isMedicinal.setEnabled(false);
                isNicelyFlavored.setEnabled(false);
                isSeasonal.setEnabled(false);
                hasThorns.setEnabled(false);
                smellsNice.setEnabled(false);
                plantPanel2.add(traits);
                plantPanel2.add(isPoisonous);
                plantPanel2.add(isEdible);
                plantPanel2.add(isMedicinal);
                plantPanel2.add(isNicelyFlavored);
                plantPanel2.add(isSeasonal);
                plantPanel2.add(hasThorns);
                plantPanel2.add(smellsNice);
              
                add(plantPanel2);
              
             
              
                btnAdd = new JButton("Add");
                btnRemove = new JButton("Remove");
                btnSort = new JButton("Sort");
                btnDisplayPlants = new JButton("Display Plants");
                btnFilter = new JButton("Filter");
                btnClear = new JButton("Clear");
                btnAdd.addActionListener(new ButtonHandlerAdd());
                btnRemove.addActionListener(new ButtonHandlerRemove());
                btnDisplayPlants.addActionListener(new ButtonHandlerDisplay());
                btnClear.addActionListener(new ButtonHandlerClear());
                btnSort.addActionListener(new ButtonHandlerSort());
                btnFilter.addActionListener(new ButtonHandlerFilter());
                plantPanel3.add(btnAdd);
                plantPanel3.add(btnRemove);
                plantPanel3.add(btnSort);
                plantPanel3.add(btnDisplayPlants);
                plantPanel3.add(btnFilter);
                plantPanel3.add(btnClear);
              
                plantSummary = new JTextArea(10,20);
                plantSummary.setBackground(Color.WHITE);
                plantSummary.setFont(new Font("Verdana",Font.PLAIN, 14));
              
                plantSummary.setEditable(false);
                plantSummary.setVisible(true);
              
             
                scrollPane = new JScrollPane(plantSummary);
                scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                plantPanel4.add(scrollPane, BorderLayout.SOUTH);
                appMenu = new JMenuBar();
                fileMenu = new JMenu("File");
                open = new JMenuItem("Open");
                save = new JMenuItem("Save");
                fileMenu.add(open);
                fileMenu.add(save);
                appMenu.add(fileMenu);
                setJMenuBar(appMenu);
                save.addActionListener(new FileMenuSaveFilter());
                open.addActionListener(new FileMenuOpenFilter());
                add(plantPanel3);
                add(plantPanel4);
                setSize(900, 600);
              
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setVisible(true);
               
            } catch(Exception e) {
                System.out.println(e);
            }
          
        }
      
        public static void main(String[] args) {
            new PlantGUIDriverFinalAssignment();
        }
      
        private void addPlant() {
       //Add a plant that is specified by the user  

            String plantName = txtName.getText();          
            String plantColor = txtColor.getText();          
            String plantID = txtPlantID.getText();
            Plant thePlant = new Plant(plantColor, plantID, plantName);
            plantList.add(thePlant);
          
   }
      
        private void addFlower() {
       //Add a plant that is specified by the user
       String flowerName;
       String flowerColor;
       String flowerID;
       boolean scentType;
       String theScent;
              
       boolean isThorny;              
                flowerName = txtName.getText();
                flowerColor = txtColor.getText();
                flowerID = txtPlantID.getText();
                isThorny = hasThorns.isSelected();             
                scentType = smellsNice.isSelected();
                if (smellsNice.isSelected()) {
                    theScent = smellsNice.getText();
                } else {
                    theScent = "No Scent";
                }
                Flower theFlower = new Flower(flowerColor, flowerID, flowerName, theScent, isThorny);
                plantList.add(theFlower);
              

   }
  
        private void addFungus() {
       //Add a plant that is specified by the user
       String fungusName;
       String fungusColor;
       String fungusID;
      
       boolean isItPoisonous;            
              
                fungusName = txtName.getText();              
                fungusColor = txtColor.getText();           
                fungusID = txtPlantID.getText();
                isItPoisonous = isPoisonous.isSelected();
              

                Fungus newFungus = new Fungus(fungusColor, fungusID, fungusName, isItPoisonous);
                plantList.add(newFungus);
              

        }
      
        private void addWeed() {
       //Add a plant that is specified by the user
       String weedName;
       String weedColor;
       String weedID;
      
       boolean isItEdible;
      
       boolean isItMedicinal;
      
       boolean isItPoisonous;  
    
                weedName = txtName.getText();
                weedColor = txtColor.getText();
                weedID = txtPlantID.getText();

                isItEdible = isEdible.isSelected();             
                isItMedicinal = isMedicinal.isSelected();
                isItPoisonous = isPoisonous.isSelected();
                Weed theWeed = new Weed(weedColor, weedID, weedName, isItEdible, isItMedicinal, isItPoisonous);
                plantList.add(theWeed);
              

   }
      
        private void addHerb() {
                //Add Herb Based off of these properties
                String herbName, herbColor, herbID, isGreatFlavor;
                boolean isItMedicinal, isItSeasonal;
              
                herbName = txtName.getText();
                herbColor = txtColor.getText();
                herbID = txtPlantID.getText();
              
                if (isNicelyFlavored.isSelected()) {
                    isGreatFlavor = "Excellent and exquisite";
                } else {
                    isGreatFlavor = "Flavor isn't nice";
                }
              
                isItMedicinal = isMedicinal.isSelected();
                isItSeasonal = isSeasonal.isSelected();
                Herb theHerb = new Herb(herbColor, herbID, herbName, isGreatFlavor, isItMedicinal, isItSeasonal);
                plantList.add(theHerb);
              
              
        }
      
        private void sortPlants() {
            //Instructions does not specify to use any sort Algorithm, so I will use default ArrayList sort
                // Sorting
            plantSummary.setText("");
            Collections.sort(plantList, new Comparator<Plant>() {
      
            @Override
            public int compare(Plant plant2, Plant plant1)
            {

                return plant2.getName().compareTo(plant1.getName());
              
            }
            });
        for (Plant thePlant : plantList) {
                plantSummary.append(thePlant.toString() + " ");
            }
              
              
   }
      
        private void filterPlants() {
                plantSummary.setText("");
                String plantName = JOptionPane.showInputDialog(null, "Please enter the first character or part of a String of Plant to search for them");
          
       for (Plant thePlant : plantList) {
           if(thePlant.getName().charAt(0) == plantName.charAt(0)) {
                                plantSummary.append(thePlant.toString() + " ");
               JOptionPane.showMessageDialog(null, "Please see the text Box for plants that begin with the first character of the sequence!");
                              
           }
       }
        }
      
        private void savePlantsToFile () throws IOException {
       File plantFile = new File("plantFile.txt");
       FileOutputStream plantStream = new FileOutputStream(plantFile);
       PrintWriter plantOutStream = new PrintWriter(plantStream);
       for (Plant thePlant : plantList) {
           plantOutStream.println(thePlant.toString());
       }
       plantOutStream.close();
   }
      
        private void readPlantsFromFile() throws FileNotFoundException {
       Scanner plantInput = new Scanner (new File ("plantInputData.txt"));
       try {
           while (plantInput.hasNext()) {
              
               Plant newPlant = new Plant(plantInput.next(), plantInput.next(), plantInput.next());
               plantSummary.append(newPlant.toString() + " ");
           }
       plantInput.close();
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
  

    class RadioHandler implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("Plant")) {

                        isPoisonous.setEnabled(false);
                        isEdible.setEnabled(false);
                        isMedicinal.setEnabled(false);
                        isNicelyFlavored.setEnabled(false);
                        isSeasonal.setEnabled(false);
                        hasThorns.setEnabled(false);
                        smellsNice.setEnabled(false);

            } else if (e.getActionCommand().equals("Fungus")) {
                        isPoisonous.setEnabled(true);
                        isEdible.setEnabled(false);
                        isMedicinal.setEnabled(false);
                        isNicelyFlavored.setEnabled(false);
                        isSeasonal.setEnabled(false);
                        hasThorns.setEnabled(false);
                        smellsNice.setEnabled(false);
            } else if (e.getActionCommand().equals("Weed")) {
                        isPoisonous.setEnabled(true);
                        isEdible.setEnabled(true);
                        isMedicinal.setEnabled(true);
                        isNicelyFlavored.setEnabled(false);
                        isSeasonal.setEnabled(false);
                        hasThorns.setEnabled(false);
                        smellsNice.setEnabled(false);
            } else if (e.getActionCommand().equals("Flower")) {
                        hasThorns.setEnabled(true);
                        smellsNice.setEnabled(true);
                        isPoisonous.setEnabled(false);
                        isMedicinal.setEnabled(false);
                        isSeasonal.setEnabled(false);
                        isNicelyFlavored.setEnabled(false);
                        isEdible.setEnabled(false);
            } else if (e.getActionCommand().equals("Herb")) {
                        isPoisonous.setEnabled(false);
                        isEdible.setEnabled(false);
                        isMedicinal.setEnabled(true);
                        isNicelyFlavored.setEnabled(true);
                        isSeasonal.setEnabled(true);
                        hasThorns.setEnabled(false);
                        smellsNice.setEnabled(false);
            }
        }

    }
  
    class ButtonHandlerAdd implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
          
            System.out.println("Add Button Clicked!");
            if (e.getActionCommand().equals("Add") && rdoBtnPlant.isSelected()) {              
                addPlant();
              
            } else if (e.getActionCommand().equals("Add") && rdoBtnFlower.isSelected()) {
                addFlower();
            } else if (e.getActionCommand().equals("Add") && rdoBtnFungus.isSelected()) {
                addFungus();
            } else if (e.getActionCommand().equals("Add") && rdoBtnWeed.isSelected()) {
                addWeed();
            } else if (e.getActionCommand().equals("Add") && rdoBtnHerb.isSelected()) {
                addHerb();
            }
         
        }
    }
  
    class ButtonHandlerRemove implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Remove Button Clicked!");
            if (e.getActionCommand().equals("Remove")) {
                String plantToRemove = JOptionPane.showInputDialog(null, "Please enter the name of the Plant (regardless of type) to remove:");
                for (Plant thePlant : plantList) {
                    if (thePlant.getName().equals(plantToRemove)) {
                        plantList.remove(thePlant);
                        JOptionPane.showMessageDialog (null, "Plant " + thePlant.getName() + " has been removed!");
                    }
                }
             
            }         
                      
        }
    }
  
    class ButtonHandlerDisplay implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            plantSummary.setText("");
            for (Plant thePlant : plantList) {
                plantSummary.append(thePlant.toString() + " ");
            }
        }
    }
  
    class ButtonHandlerClear implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            plantSummary.setText("");
        }
    }
  
    class ButtonHandlerSort implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            sortPlants();
        }
    }
  
    class ButtonHandlerFilter implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            filterPlants();
        }
    }
  
    class FileMenuSaveFilter implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                savePlantsToFile();
            } catch (IOException ex) {
                Logger.getLogger(PlantGUIDriverFinalAssignment.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
  
    class FileMenuOpenFilter implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                readPlantsFromFile();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(PlantGUIDriverFinalAssignment.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}

Plant.java

import java.util.*;
public class Plant {

   private String id;
   private String name;
   private String color;
  
   public Plant() {
       this.id = "";
       this.name = "";
       this.color = "";
   }
  
   public Plant(String plantColor, String plantID, String plantName) {
       this.id = plantID;
       this.color = plantColor;
       this.name = plantName;
   }
  
   public void setID(String plantID) {
       this.id = plantID;
   }
  
   public void setColor(String plantColor) {
       this.color = plantColor;
   }
  
   public void setName(String plantName) {
       this.name = plantName;
   }
  
   public String getName() {
       return name;
   }
  
   public String getColor() {
       return color;
   }
  
   public String getID() {
       return id;
   }
  
   public String toString() {
       return "This plant's name is " + this.getName() + " with a color of: " + this.getColor() +
               " with a unique ID of: " + this.getID();
   }
  
   @Override
   public boolean equals(Object otherPlant) {
       if (otherPlant == null) {
           return false;
       }
      
       if (!Plant.class.isAssignableFrom(otherPlant.getClass())) {
            return false;
        }
      
       final Plant other = (Plant) otherPlant;
      
       if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if (!(this.color.equals(other.color))) {
            return false;
        }
      
        if (!(this.id.equals(other.id))) {
           return false;
        }
      
        return true;
   }
  
}

Fungus.java


public class Fungus extends Plant{
  
   private boolean isPoisonous;
  
   public Fungus(String fungusColor, String fungusID, String fungusName, boolean isPoisonous) {
       super(fungusColor, fungusID, fungusName);
       this.isPoisonous = isPoisonous;
   }
  
      
   public void setIsPoisonous(boolean isPoisonous) {
       this.isPoisonous = isPoisonous;
   }
  
   public boolean getIsPoisonous(){
       return isPoisonous;
   }
  
   public String toString() {
       return "This fungus as sampled is " + this.getColor() + " in color " + " with an ID of " + this.getID() +
               " and a name of " + this.getName() + " and it's poisonous = " + this.getIsPoisonous();
   }
  
   @Override
   public boolean equals(Object otherFungus) {
      
       if (otherFungus == null) {
           return false;
       }
       if (!Fungus.class.isAssignableFrom(otherFungus.getClass())) {
           return false;
       }
      
       Fungus other = (Fungus) otherFungus;
      
       if (!(this.getColor().equals(other.getColor()))) {
           return false;
       }
      
       if (!(this.getID().equals(other.getID()))) {
           return false;
          
       }
      
       if (!(this.getName().equals(other.getName()))) {
           return false;
       }
      
       if (this.isPoisonous != other.isPoisonous) {
           return false;
       }
      
       return true;
   }
  
}

weed.java

import java.util.*;
public class Weed extends Plant {
   private boolean isEdible, isMedicinal, isPoisonous;
  
  
   public Weed(String weedColor, String weedID, String weedName, boolean isEdible, boolean isMedicinal, boolean isPoisonous) {
       super(weedColor, weedID, weedName);
       this.isEdible = isEdible;
       this.isMedicinal = isMedicinal;
       this.isPoisonous = isPoisonous;
   }
  
   public void setIsEdible(boolean isEdible) {
       this.isEdible = isEdible;
   }
  
   public boolean getIsEdible() {
       return isEdible;
   }
  
   public void setIsMedicinal(boolean isMedicinal) {
       this.isMedicinal = isMedicinal;
   }
  
   public boolean getIsMedicinal() {
       return isMedicinal;
   }
  
   public void setIsPoisonous(boolean isPoisonous) {
       this.isPoisonous = isPoisonous;
   }
  
   public boolean getIsPoisonous() {
       return isPoisonous;
   }
  
   public String toString() {
       return "This weed is of " + this.getColor() + " color and is called " + this.getName() +
               " with an ID of " + this.getID() + " it is edible = " + this.getIsEdible() + " and it is Poisonous " + this.getIsPoisonous() +
               " and it is medicinal " + this.getIsMedicinal();
   }
  
   @Override
   public boolean equals(Object otherWeed) {
       if (otherWeed == null) {
           return false;
       }
      
       if (!(Weed.class.isAssignableFrom(otherWeed.getClass()))) {
           return false;
       }
      
       Weed other = (Weed) otherWeed;
      
       if (!(this.getID().equals(other.getID()))) {
           return false;
       }
      
       if (!(this.getName().equals(other.getName()))) {
           return false;
       }
      
       if (!(this.getColor().equals(other.getColor()))) {
           return false;
       }
      
       if (this.isEdible != other.isEdible) {
           return false;
       }
      
       if (this.isMedicinal != other.isMedicinal) {
           return false;
       }
      
       if (this.isPoisonous != other.isPoisonous) {
           return false;
       }
      
       return true;
      
      
   }
}

note: due to limited character i cant able to post Flower.java and Herb.java files

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