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

After a long and tedious journey of helping Alexander and Elizabeth we feel we’v

ID: 3824274 • Letter: A

Question

After a long and tedious journey of helping Alexander and Elizabeth we feel we’ve done our part in helping and plan to get on the road in the morning. Our bags were packed and set at the edge of the bed waiting for us to awake, but when we wake up our bags are missing! It seems thieves came in through the open window last night and stole our belongings. Before we can get back on the road we need to gather some money in order to purchase new equipment. To help raise money we have talked to a local shop owner and he mentioned that he liked Alexander’s flower pack, but would like it to hold more than just flowers. The new flower pack should hold plants which can be flowers, fungus or weed.

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

Each subclass shares certain qualities (ID and Name)

Flower traits include (Color, Thorns, and Smell)

Fungus traits include (Color and Poisonous)

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

All items should be able to be displayed.

Be able to add, remove, search and filter these plants – by name.

Submit 5 files: Mid.java, flower.java, fungus.java, plant.java and weed.java

Explanation / Answer


import java.util.*;
//Plant.java
class Plant{
String name;
int id;
String color;
Plant(){
}
void SetID(int id)
{
  this.id = id;
}
int GetID()
{
return this.id;
}
void SetName(String name)
{
  this.name = name;
}
void SetColor(String color)
{
this.color = name;
}
public void Show(){
System.out.println("ID:"+id+" Name:"+name+" Color:"+color);
}
}
//Flower.java
class Flower extends Plant{
  
String thorns;
String smell;
void SetSmell(String smell)
{
this.smell = smell;
}
void SetThorns(String thorn)
{
this.thorns = thorn;
}
public void Show(){
super.Show();   
System.out.println("thorns:"+thorns+"Smell:"+smell);
}
  
}
//Fungus.java
class Fungus extends Plant{
  
boolean poisonous;
void SetPoisonous(boolean poisonous)
{
this.poisonous = poisonous;
}
public void Show(){
super.Show();   
System.out.println("poisonous:"+poisonous);
}
  
}
//Weed.java
class Weed extends Plant{
  
boolean poisonous;
String edible;
String medicinal;
void SetPoisonous(boolean poisonous)
{
this.poisonous = poisonous;
}
void SetEdible(String edible)
{
this.edible = edible;
}
void SetMedicinal(String medicinal)
{
this.medicinal = medicinal;
}
public void Show(){
super.Show();   
System.out.println("poisnous:"+poisonous+"edible:"+edible+"medicinal:"+medicinal);
}
  
}
//Mid.java
public class Mid{
  
static LinkedList <Plant> plants;
  
public static Plant SearchPlant(int id)
{
for(Plant p:plants){   
if ( p.GetID() == id ) {
return p;   
}
}
return null;
}
  
public static void main(String []args){
plants=new LinkedList <Plant>();
boolean continueChoice = false;
Scanner scanner = new Scanner(System.in);
int choice = 0;
do {
try{
System.out.println("Choose Plant:1. Flower 2. Fungus 3.Weed Enter Option:");
int plantCh = scanner.nextInt();
if ( plantCh < 1 || plantCh > 3 )
{
System.out.println("Wrong Choice Entered! Try Again");
continue;
}
System.out.println("Choose Operation:1. Add 2. Remove 3. Search 4. Show Enter Option:");
int op = scanner.nextInt();   
switch(op)
{
case 1://Add
int id;
System.out.println("Enter ID:");
id = scanner.nextInt();
scanner.nextLine(); //This is needed to pick up the new line   
  
System.out.println("Enter Name:");
String name = scanner.nextLine();
System.out.println("Enter Color:");
String color = scanner.nextLine();
  
Plant p = null;
if ( plantCh == 1 )
{
p = new Flower();
System.out.println("Enter thorns:");
String thorns = scanner.nextLine();
((Flower)p).SetThorns(thorns);
// p.SetThorns(thorns);
System.out.println("Enter Smell:");
String smell = scanner.nextLine();
((Flower)p).SetSmell(smell);
  
}
else if(plantCh == 2 )
{ p = new Fungus();
System.out.println("Enter poisnous:");
boolean poison = scanner.nextBoolean();
((Fungus)p).SetPoisonous(poison);
  
  
}
else {
p = new Weed();
System.out.println("Enter poisnous:");
boolean poison = scanner.nextBoolean();
((Weed)p).SetPoisonous(poison);
  
System.out.println("Enter Edible:");
String edible = scanner.nextLine();   
((Weed)p).SetEdible(edible);
  
System.out.println("Enter Medicinal:");
String medicinal = scanner.nextLine();   
((Weed)p).SetMedicinal(medicinal);
}
p.SetID(id);
p.SetName(name);
p.SetColor(color);   
plants.add(p);
  
break;
case 2://Remove
{
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
Plant plantOBJ = SearchPlant(id);
if ( plantOBJ != null ) {
plants.remove(plantOBJ);
System.out.println("Flower ID: "+id+"removed");
}
else
{
System.out.println("Flower ID: "+id+"not found");
}
}
break;
case 3://Search
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
if ( SearchPlant(id) != null ) {
System.out.println("Flower ID: "+id+"found");
}
else
{
System.out.println("Flower ID: "+id+"not found");
}   
  
break;
  
case 4://Show
{
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
Plant plantObj = SearchPlant(id);
if ( SearchPlant(id) != null) {
plantObj.Show();
}
else
{
System.out.println("Flower ID: "+id+"not found");
}   
}
break;
  
  
default:
System.out.println("Wrong choice");
  
}
System.out.print("Do you want to continue (true or false): ");
continueChoice = scanner.nextBoolean();
}
catch(Exception e)
{
e.printStackTrace();
}
}
while(continueChoice);
}
}

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