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

Now that we\'ve helped apparently everyone on the planet make some money except

ID: 3829597 • Letter: N

Question

Now that we've helped apparently everyone on the planet make some money except ourselves it's time to move on. As we're leaving town a courier runs up to us to deliver a letter. It reads:

Dear Friends,

I hope this letter finds you well and in good spirits. The doctor has arrived and has begun treating Elizabeth for what he proclaims as a 'vicious infection'. Many of the plants that I've collected using your flower pack have gone to great use. Elizabeth was able to wiggle her toes this morning and regained a tingling sensation not long after... IT’S WORKING!

We truly appreciate all that you've done, and extend an open offer for you to stay with us whenever you would like. Although all of our birth family is gone, we truly consider you our only family.

Thanks again,

Alexander and Elizabeth

After hearing this great news we continue on our way. We can see our destination, the city of Thanto, off in the distance, but know that the toughest part of our journey still lies ahead. We have two major obstacles that could cause us anguish, but as always, we have a plan. Or at least we think we do. The first obstacle we must traverse is the North Woods and the second is Fraus River. First things first: we must find an escort through the North Woods if we want to make it through alive. The woods are dangerous and constantly painful as the air is dense and corrosive making breathing difficult.

As darkness approaches and we make our way towards the woods we notice a small fire burning not too far away at the forest edge. We head towards the camp and notice a middle aged woman sitting by the fire. After a brief introduction we find out that she plans to make her way through the woods tonight and knows the path of least resistance, but refuses to take us along. She refuses to give us her real name, only a nickname, Epi.

After some bargaining we convince Epi to take us along, under specific circumstances though. Epi wants to use our flower pack on the way through the woods to collect many different types of plants to determine which ones are causing the horrid state of the forest. After we make it through the forest with all of these plants she wants to run some tests on these plants. She believes it's a common element between these plants that is causing these issues. She would like us to determine a way to find all of these common elements.

The idea Epi has is that the name of the plant is determining how potent the poison is. She believes that the higher frequency of a letter in the name, the higher the potency.

Using our existing flower pack we must add the following feature:

Using recursion (no loops!) you must count the number of times a specific character, or set of characters appears in the name of each plant in your pack. We will call this 'analyzing' for the sake of future terminology. Examples are provided on the last page.

The following features are also required but should only be slightly changed from previous requirements.

You must have a graphical user interface implemented. This GUI MUST be unique but can be the same as you've previously used.

You must be able to display, add, remove, sort, filter, and now analyze information from our flower pack.

The flower pack should hold flowers, weeds, fungus, and herbs. All should be a subclass of a plant class.

Each subclass shares certain qualities (ID, Name, and Color) – in plant class

Flower traits include (Thorns and Smell)

Fungus traits include (Poisonous)

Weed traits include (Poisonous, Edible and Medicinal)

Herb traits include (Flavor, Medicinal, Seasonal)

Submit 6 files: Assignment6.java, flower.java, fungus.java, plant.java, weed.java, and herb.java

Analysis Examples

how you display the results is up to you

Analyze 3 different strings such as “ar”, “ne”, and “um” – which strings is up to you and does not require user input

Analysis

"ar"

"ne"

"um"

"ll"

"r"

"u"

"dragon"

Name

Amaranthus

1

0

0

0

1

1

0

Anemone

0

2

0

0

0

0

0

Buplerum

0

0

1

0

1

2

0

Calla Lilly

0

0

0

2

0

0

0

Poinsettia

0

0

0

0

0

0

0

Ranunculus

0

0

0

0

0

3

0

Snapdragon

0

0

0

0

1

0

1

Analysis can be case sensitive, if you so desire. Remember - you MUST use recursion to solve this problem. Meaning – not a single loop should be called when doing these calculations. You CAN use a loop when you want to move from analyzing one flower to the next, but your loop CANNOT be used when analyzing a specific flower.

Analysis

"ar"

"ne"

"um"

"ll"

"r"

"u"

"dragon"

Name

Amaranthus

1

0

0

0

1

1

0

Anemone

0

2

0

0

0

0

0

Buplerum

0

0

1

0

1

2

0

Calla Lilly

0

0

0

2

0

0

0

Poinsettia

0

0

0

0

0

0

0

Ranunculus

0

0

0

0

0

3

0

Snapdragon

0

0

0

0

1

0

1

Explanation / Answer

DemoClass.java:

//Driver.java
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.ArrayList;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.*;
public class DemoClass {
  
public static void main(String[] args) throws Exception {
new DemoClass();
}
  
public DemoClass() throws Exception {
Scanner input = new Scanner(System.in);
Plant newPlant = new Plant();
ArrayList<Plant> plantPack = new ArrayList<Plant>();
  
System.out.println("Welcome to my PlantPack Interface");
System.out.println("Please select a number from the options below:");
System.out.println("");
  
while(true) {
System.out.println("1: Add a Plant to the pack.");
System.out.println("2: Remove a Plant from the pack.");
System.out.println("3: Search for a Plant by Name.");
System.out.println("4: Filter PlantPack by Plant Partial Name.");
System.out.println("5: Display Plants in the PlantPack.");
System.out.println("6: Save PlantPack to a File.");
System.out.println("7: Load PlantPack from a File.");
System.out.println("0: Exit the Plant Pack interface.");
  
int userChoice = input.nextInt();
  
switch (userChoice) {
case 1:
System.out.println("Enter Plant Type: ");
System.out.println("1: Flower");
System.out.println("2: Fungus");
System.out.println("3: Weed");
  
int plantType = input.nextInt();
switch(plantType) {
case 1:
newPlant = new Flower();
addPlant(plantPack, newPlant);
break;
case 2:
newPlant = new Fungus();
addPlant(plantPack, newPlant);
break;
case 3:
newPlant = new Weed();
addPlant(plantPack, newPlant);
break;
}
  
break;
  
case 2:
removePlant(plantPack);
break;
case 3:
searchPlant(plantPack);
break;
case 4:
filterPlant(plantPack);
break;
case 5:
displayPlant(plantPack);
break;
case 6:
savePlant(plantPack);
break;
case 7:
loadPlant(plantPack);
break;
case 0:
System.out.println("Thank you for using the Plant Pack Interface. See you again soon!");
System.exit(0);
}
}
  
}
  
  
private void savePlant(ArrayList<Plant>plantPack) throws Exception {
  
try (
java.io.PrintWriter output = new java.io.PrintWriter("PlantPack.txt"); ) {
if(plantPack.isEmpty()) {
System.out.println("Pack is empty!");
System.out.println("");
} else {
for(Plant plant : plantPack) {
if(plant instanceof Flower) {
output.println(" Flower: ");
} else if(plant instanceof Fungus) {
output.println(" Fungus: ");
} else if(plant instanceof Weed) {
output.println(" Weed: ");
}
output.println(plant);
}
}
  
}
System.out.println("PlantPack Saved!");
System.out.println("");
}
  
  
private void loadPlant(ArrayList<Plant>plantPack) {
Scanner input = new Scanner(System.in);
String loadFile;
System.out.println("Enter file name including file format (ex. file.txt): ");
loadFile = input.nextLine();
  
try {
java.io.File file = new java.io.File(loadFile);
Scanner reader = new Scanner(file);
reader.useDelimiter(" ");
while(reader.hasNext()) {
System.out.println(reader.nextLine());
  
}
reader.close();
} catch(FileNotFoundException ex) {
System.out.println("File not found.");
}
  
}
  
  
private void addPlant(ArrayList<Plant>plantPack, Plant newPlant) {
Scanner input = new Scanner(System.in);
String Name, ID, Color, Smell, Thorns, Poisonous, Edible, Medicinal;
if(newPlant instanceof Flower) {
  
System.out.print("Enter Flower ID: ");
ID = input.nextLine();
System.out.print("Enter Flower Name: ");
Name = input.nextLine();
System.out.print("Enter Flower Color: ");
Color = input.nextLine();
System.out.print("How does this Flower smell? ");
Smell = input.nextLine();
System.out.print("Does this Flower have Thorns?(Yes or No): ");
Thorns = input.nextLine();
  
while(!Thorns.equalsIgnoreCase("Yes") && !Thorns.equalsIgnoreCase("No")) {
System.out.println("Please select 'Yes' or 'No', Try Again.");
Thorns = input.nextLine();
}
  
newPlant.setID(ID);
newPlant.setName(Name);
((Flower)newPlant).setColor(Color);
((Flower)newPlant).setSmell(Smell);
((Flower)newPlant).setThorns(Thorns);
  
plantPack.add(newPlant);
System.out.println("Flower Added!");
System.out.println("");
  
} else if(newPlant instanceof Fungus) {
  
System.out.print("Enter Fungus ID: ");
ID = input.nextLine();
//input.nextLine();
System.out.print("Enter Fungus Name: ");
Name = input.nextLine();
System.out.print("Enter Fungus Color: ");
Color = input.nextLine();
System.out.print("Is this Fungus Poisonous?(Yes or No): ");
Poisonous = input.nextLine();
  
while(!Poisonous.equalsIgnoreCase("Yes") && !Poisonous.equalsIgnoreCase("No")) {
System.out.println("Please select 'Yes' or 'No', Try Again.");
Poisonous = input.nextLine();
}
  
newPlant.setID(ID);
newPlant.setName(Name);
((Fungus)newPlant).setColor(Color);
((Fungus)newPlant).setPoisonous(Poisonous);
  
plantPack.add(newPlant);
System.out.println("Fungus Added!");
System.out.println("");
  
} else {
  
System.out.print("Enter Weed ID: ");
ID = input.nextLine();
System.out.print("Enter Weed Name: ");
Name = input.nextLine();
System.out.print("Enter Weed Color: ");
Color = input.nextLine();
System.out.print("Is this Weed Poisonous?(Yes or No): ");
Poisonous = input.nextLine();
  
while(!Poisonous.equalsIgnoreCase("Yes") && !Poisonous.equalsIgnoreCase("No")) {
System.out.println("Please select 'Yes' or 'No', Try Again.");
Poisonous = input.nextLine();
}
  
System.out.print("Is this Weed Edible?(Yes or No): ");
Edible = input.nextLine();
  
while(!Edible.equalsIgnoreCase("Yes") && !Edible.equalsIgnoreCase("No")) {
System.out.println("Please select 'Yes' or 'No', Try Again.");
Edible = input.nextLine();
}
  
System.out.print("Is this Weed Medicinal?(Yes or No): ");
Medicinal = input.nextLine();
  
while(!Medicinal.equalsIgnoreCase("Yes") && !Medicinal.equalsIgnoreCase("No")) {
System.out.println("Please select 'Yes' or 'No', Try Again.");
Medicinal = input.nextLine();
}
  
newPlant.setID(ID);
newPlant.setName(Name);
((Weed)newPlant).setColor(Color);
((Weed)newPlant).setPoisonous(Poisonous);
((Weed)newPlant).setEdible(Edible);
((Weed)newPlant).setMedicinal(Medicinal);
  
plantPack.add(newPlant);
System.out.println("Weed Added!");
System.out.println("");
}
}
  
private void removePlant(ArrayList<Plant>plantPack) {
Scanner input = new Scanner(System.in);
String removePlant;
boolean found = false;
if(plantPack.isEmpty()) {
System.out.println("Pack is empty!");
System.out.println("");
} else {
System.out.print("Enter name of the plant to remove: ");
removePlant = input.nextLine();
for(Plant plant : plantPack) {
if(plant.getName().equalsIgnoreCase(removePlant)) {
plantPack.remove(plant);
System.out.println("Removed " + removePlant + "!");
System.out.println("");
found = true;
break;
}
}
if(found) {
} else {
System.out.println("No Match!");
System.out.println("");
}
}
}
  
private void searchPlant(ArrayList<Plant>plantPack) {
Scanner input = new Scanner(System.in);
String searchPlant;
boolean found = false;
if(plantPack.isEmpty()) {
System.out.println("Pack is empty!");
System.out.println("");
} else {
System.out.print("Enter name of the plant to search: ");
searchPlant = input.nextLine();
for(int i = 0; i < plantPack.size(); i++) {
if(plantPack.get(i).getName().equalsIgnoreCase(searchPlant)) {
found = true;
System.out.println("Your plant " + searchPlant + " is in position "
+ (i + 1));
System.out.println("");
break;
}
}
if(!found) {
System.out.println("No Match!");
System.out.println("");
}
}
}
  
private void filterPlant(ArrayList<Plant>plantPack) {
Scanner input = new Scanner(System.in);
System.out.print("Enter partial name of plant to search: ");
String filterPlant = input.nextLine();
ArrayList<Plant> filterPack = new ArrayList<>();
boolean found = false;
if(plantPack.isEmpty()) {
System.out.println("Pack is empty!");
System.out.println("");
} else {
  
for(int i = 0; i < plantPack.size(); i++) {
Pattern pattern = Pattern.compile(filterPlant, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(plantPack.get(i).getName());
  
while(matcher.find()) {
filterPack.add(plantPack.get(i));
found = true;   //This is where your code goes wrong. You forgot to write this step.
break;
}
}
if(found) {
  
} else {
System.out.println("No Match!");
System.out.println("");
}
}
System.out.println("Plants containing " + filterPlant + " are:");
for(Plant plant: filterPack) {
if(plant instanceof Flower) {
System.out.println(" Flower: ");
} else if (plant instanceof Fungus) {
System.out.println(" Fungus: ");
} else if (plant instanceof Weed) {
System.out.println(" Weed: ");
}
System.out.println(plant);
System.out.println("");
}
}
  
private void displayPlant(ArrayList<Plant>plantPack) {
if(plantPack.isEmpty()) {
System.out.println("Pack is empty!");
System.out.println("");
} else {
for(Plant plant : plantPack) {
if(plant instanceof Flower) {
System.out.println(" Flower: ");
} else if(plant instanceof Fungus) {
System.out.println(" Fungus: ");
} else if(plant instanceof Weed) {
System.out.println(" Weed: ");
}
System.out.println(plant);
System.out.println("");
}
}
}
}

Flower.java:

//Flower.java

public class Flower extends Plant {
  
private String Color;
private String Smell;
private String Thorns;
public String getColor() {
return Color;
}
  
public void setColor(String Color) {
this.Color = Color;
}
  
public String getSmell() {
return Smell;
}
  
public void setSmell(String Smell) {
this.Smell = Smell;
}
  
public String getThorns() {
return Thorns;
}
  
public void setThorns(String Thorns) {
this.Thorns = Thorns;
}
  
public void Name() {
super.getName();
}
  
public void ID() {
super.getID();
}
  
public String toString() {
return super.toString() + " Color: " + Color + " Smell: " + Smell + " withThorns: " + Thorns;
}
}

Fungus.java:

//Fungus.java

public class Fungus extends Plant {
  
private String Color;
private String Poisonous;
  
public Fungus() {
  
}
  
public String getColor() {
return Color;
}
  
public void setColor(String Color) {
this.Color = Color;
}
  
public String getPoisonous() {
return Poisonous;
}
  
public void setPoisonous(String Poisonous) {
this.Poisonous = Poisonous;
}
  
public String toString() {
return super.toString() + " Color: " + Color + " Poisonous: " + Poisonous;
}
  
}

Plant.java:

//Plant.java
public class Plant {
  
private String Name;
private String ID;
public String getName() {
return Name;
}
  
public void setName(String Name) {
this.Name = Name;
}
  
public String getID() {
return ID;
}
  
public void setID(String ID) {
this.ID = ID;
}
  
public String toString() {
return " Name: " + Name + " ID: " + ID;
}
  
  
}

Weed.java:

//Weed.java

public class Weed extends Plant {
  
private String Color;
private String Poisonous;
private String Edible;
private String Medicinal;
  
public Weed() {
}
  
public String getColor() {
return Color;
}
  
public void setColor(String Color) {
this.Color = Color;
}
  
public String getPoisonous() {
return Poisonous;
}
  
public void setPoisonous(String Poisonous) {
this.Poisonous = Poisonous;
}
  
public String getEdible() {
return Edible;
}
  
public void setEdible(String Edible) {
this.Edible = Edible;
}
  
public String getMedicinal() {
return Medicinal;
}
  
public void setMedicinal(String Medicinal) {
this.Medicinal = Medicinal;
}
  
public String toString() {
return super.toString() + " Color: " + Color + " Poisonous: " + Poisonous + " Edible:" +
Edible + " Medicinal: " + Medicinal;
}
  
}

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