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

Flower pack should hold plants which can be flowers, fungus or weed. Please crea

ID: 3852965 • Letter: F

Question

Flower pack should hold plants which can be flowers, fungus or weed.

Please create a plant class that has three child classes (fungus, flower and weed).

Each subclass should share certain qualities (Name and ID)

Flower traits should include (Thorns, Color, and Smell)

Fungus traits should include (Poisonous and Color)

Weed traits include (Poisonus, Color, Medicinal and Edible)

Should be able to display all items.

Needs to be able to add, remove, search and filter these plants by name.

Submit 5 files related to this project: xx Midterm.java, xx fungus.java, xx flower.java, xx plant.java and xx weed.java

Explanation / Answer

//Plant.java
public class Plant {
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;
}

}
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;
}

}
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;
}

}
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;
}

}


// FlowerPack.java
import java.util.ArrayList;
import java.util.Scanner;

public class FlowerPack {
public static void main(String[] args) {
try{
ArrayList <Plant> 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. 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? <Flower / Fungus / 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: System.exit(0);
}
}
}catch(Exception e)
{
System.out.println(e);
}
}


}

/*
output:

1. Add plants
2. Remove plants
3. Search plants
4. Filter plants
5. Quit
Enter your choice: 1
You want to add Flower, Fungus or Weed? <Flower / Fungus / Weed> Weed
Enter name : newWeed
Enter ID : 45
Enter color : green
Is it Poisonous? y
Is it Edible? y
Is it Medicinal? y
1. Add plants
2. Remove plants
3. Search plants
4. Filter plants
5. Quit
Enter your choice: 1
You want to add Flower, Fungus or Weed? <Flower / Fungus / Weed> Weed
Enter name : newWeed
Enter ID : 12
Enter color : red
Is it Poisonous? n
Is it Edible? n
Is it Medicinal? y
1. Add plants
2. Remove plants
3. Search plants
4. Filter plants
5. Quit
Enter your choice: 1
You want to add Flower, Fungus or Weed? <Flower / Fungus / Weed> Flower
Enter name : newflower
Enter ID : 23
Enter color : black
Has thorns? y
Has smell? y
1. Add plants
2. Remove plants
3. Search plants
4. Filter plants
5. Quit
Enter your choice: 3
Enter the name of the plant you want to search : newflower
plant found sucessfully
1. Add plants
2. Remove plants
3. Search plants
4. Filter plants
5. Quit
Enter your choice: 4
Enter the name of the plant you want to filter: newWeed
Name: newWeed   ID: 45
Name: newWeed   ID: 12
1. Add plants
2. Remove plants
3. Search plants
4. Filter plants
5. Quit
Enter your choice: 5

*/

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