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

The below codes add, display, sort and filter user inputed items such as flowers

ID: 3834042 • Letter: T

Question

The below codes add, display, sort and filter user inputed items such as flowers, weeds,herbs and fungus. The question below will be highlighted in bold where the existing code needs altered.

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

cal user interface implemented. This GUI MUST be unique but can be the same as you've previously used.

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

You must have a graphical user interface implemented. This GUI MUST be unique

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)

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 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.

=========================================

Main code

import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Final {
public static void main(String[] args) {
try {
List flowerPack = new LinkedList<>();
Scanner input = new Scanner(System.in);
int choice;
String name, color, ID;
boolean poisonous, edible, medicinal, smell, thorns, flavor, seasonal;
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 plants to file");
System.out.println("6. Load plants 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, Herb 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:
input.nextLine();
System.out.print("Enter the name of the file to save plants: ");
name = input.nextLine();
FileWriter fw = new FileWriter(name);
for(Plant plant: flowerPack)
{
fw.write(plant.toString());
fw.write(" ");
}
fw.close();
break;
case 6:
input.nextLine();
System.out.print("Enter the name of the file to read plants: ");
name = input.nextLine();
FileReader fr = new FileReader(name);
Scanner fileScanner = new Scanner(fr);
while(fileScanner.hasNextLine())
{
String line = fileScanner.nextLine();
String[] data = line.split(",");
String flowertype = data[0];
if (flowertype.equalsIgnoreCase("Flower")) {
name = data[1];
ID = data[2];
color = data[3];
thorns = data[4].equals("true");
smell = data[5].equals("true");
flowerPack.add(new Flower(name, ID, color, thorns, smell));
} else if (flowertype.equalsIgnoreCase("Fungus")) {
name = data[1];
ID = data[2];
color = data[3];
poisonous = data[4].equals("true");
flowerPack.add(new Fungus(name, ID, color, poisonous));
} else if (flowertype.equalsIgnoreCase("Weed")) {
name = data[1];
ID = data[2];
color = data[3];
poisonous = data[4].equals("true");
edible = data[5].equals("true");
medicinal = data[6].equals("true");
flowerPack.add(new Weed(name, ID, color, poisonous, edible, medicinal));

}
}
fr.close();
fileScanner.close();
break;
case 7:
input.close();
System.exit(0);
}

}
} catch (Exception e) {
System.out.println(e);
}
}

}

============================

Plant

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;
}
  
public String toString()
{
return name + "," + ID;
}
}

===========================

class Herb extends Plant{

String Color;
boolean Flavor;
boolean Medicinal;
boolean Seasonal;

public Herb(String name, String ID, String Color, boolean Flavor, boolean Medicinal, boolean Seasonal)
{
super (name, ID);
this.Color = Color;
this.Flavor = Flavor;
this.Medicinal = Medicinal;
this.Seasonal = Seasonal;
}

public String toStrin()
{
return "Herb," +super.toString() + "," + Flavor + "," + Medicinal + "," + Seasonal;
}
}

====================

Weed

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;
}
public String toString()
{
return "weed," + super.toString() + "," + Color + "," + Poisonous + "," + Edible + "," + Medicinal;
}
}

======================

Fungus

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;
}
  
public String toString()
{
return "fungus," + super.toString() + "," + Color + "," + Poisonous;
}
}

============================

Flower

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;
}
  
public String toString()
{
return "flower," + super.toString() + "," + color + "," + thorns + "," + smell;
}
}

Explanation / Answer

import java.io.*;
import java.util.*;
import javax.swing.*;
public class group {
public static void main(String args) throws IOException {
Scanner input = new Scanner(System.in);
ArrayList&lt;plant&gt; plantPack = new ArrayList&lt;plant&gt;();
System.out.println(&quot;Welcome to my plant pack application.&quot;);
System.out.println(&quot;Please select a options below&quot;);
System.out.println(&quot;&quot;);
while (true) {
System.out.println(&quot;1: Add .&quot;);
System.out.println(&quot;2: Remove.&quot;);
System.out.println(&quot;3: Search .&quot;);
System.out.println(&quot;4: Display .&quot;);
System.out.println(&quot;5: Filter .&quot;);
System.out.println(&quot;6: Add/Load a plant file. &quot;);
System.out.println(&quot;0: Exit .&quot;);
System.out.print(&quot;Enter the option: &quot;);
int userChoice = input.nextInt();
switch (userChoice) {
case 1:
add(plantPack);
break;
case 2:
remove(plantPack);
break;
case 3:
search(plantPack);
break;
case 4:
display(plantPack);
break;
case 5:
filter(plantPack);
break;
case 6:
saveLoad(plantPack);
break;
case 0:
System.out
.println(&quot;Thank you for using the flower
pack interface. See you again soon!&quot;);
System.exit(0);
}
}
}
/*** @param plantPack
*/
public static void add(ArrayList&lt;plant&gt; plantPack) {
String iD;
String name;
String color;
String smell;
String thorns;
String poisonous; String
String
String
String edible;
medicinal;
flavor;
seasonal; Scanner scan = new Scanner(System.in);
plant test = new plant();
System.out.println(&quot;Hello please make a selection. &quot;);
System.out.println(&quot;Option 1: Add flower &quot;);
System.out.println(&quot;Option 2: Add Fungus &quot;);
System.out.println(&quot;Option 3: Add Weed &quot;);
System.out.print(&quot;Answer:&quot;);
int ans = scan.nextInt(); flower.&quot;); switch (ans) {
case 1:
System.out.print(&quot; Please enter your ID number for your
iD = scan.next();
System.out.print(&quot; Please enter the name of your flower. &quot;);
name = scan.next();
System.out.print(&quot; Please enter the color of your color. &quot;);
color = scan.next();
System.out.print(&quot; Is there any thorns? (Yes/No) &quot;);
thorns = scan.next();
System.out.print(&quot; Is there a smell? (Yes/No) &quot;);
smell = scan.next();
flower newFlower = new flower(iD, name, color, thorns, smell);
plantPack.add(newFlower);
System.out.println();
break;
case 2:
System.out.print(&quot; Please enter your ID number for your flower.&quot;); iD = scan.next();
System.out.print(&quot; Please enter the name of your Fungus. &quot;);
name = scan.next();
System.out.print(&quot; Please enter the color of your Fungus. &quot;);
color = scan.next();
System.out.print(&quot; Is it poisonous? (Yes/No) &quot;);
poisonous = scan.next();
fungus newFungus = new fungus(iD, name, color, poisonous);
plantPack.add(newFungus);
System.out.println();
break;
case 3:
System.out.print(&quot; Please enter your ID number for your ID.&quot;);
iD = scan.next(); System.out.print(&quot; Please enter the name of your weed. &quot;);
name = scan.next();
System.out.print(&quot; Please enter the color of your weed. &quot;);
color = scan.next();
System.out.print(&quot; Is it poisonous? (Yes/No) &quot;);
poisonous = scan.next();
System.out.print(&quot; Is it edible? (Yes/No) &quot;);
edible = scan.next();
System.out.print(&quot; Is it used for medicinal? (Yes/No) &quot;);
medicinal = scan.next();
weed newWeed = new weed(iD, name, color, poisonous, edible,
medicinal);
plantPack.add(newWeed);
System.out.println();
break;
case 4:
System.out.print(&quot; Please enter your ID number for your ID.&quot;);
iD = scan.next();
System.out.print(&quot; Please enter the name of your herb. &quot;);
name = scan.next();
System.out.print(&quot; Please enter the color of your herb. &quot;);
color = scan.next();
System.out.print(&quot;Flavour : &quot;);
flavor = scan.next();
System.out.print(&quot; Is it used for medicinal? (Yes/No) &quot;);
medicinal = scan.next();
System.out.print(&quot; Is it
seasonal = scan.next(); seasonal? (Yes/No) &quot;); herb h = new herb(iD, name, color, flavor, medicinal,
seasonal);
plantPack.add(h);
System.out.println();
} break; }
private static void remove(ArrayList&lt;plant&gt; plantPack) {
Scanner scan = new Scanner(System.in);
String s;
System.out
remove. &quot;); .println(&quot; Please enter the plant name you would like to
System.out.print(&quot; Ans:&quot;);
s = scan.next(); for (int i = 0; i &lt; plantPack.size(); i++) {
plant remove = plantPack.get(i);
if (remove.getName().equalsIgnoreCase(s)) {
plantPack.remove(i);
break;
}
}
}
private static void display(ArrayList&lt;plant&gt; plantPack) {
System.out.println();
for (int i = 0; i &lt; plantPack.size(); i++) {
System.out.println(plantPack.get(i)); } }
System.out.println(); public static void search(ArrayList&lt;plant&gt; plantPack) {
Scanner scan = new Scanner(System.in);
System.out
.println(&quot; Please search for the plant you would to
search for. &quot;);
System.out.print(&quot; Ans:&quot;);
String stringAns = scan.next();
boolean FlagAns = false;
for (int i = 0; i &lt; plantPack.size(); i++) {
plant newPlantPack = plantPack.get(i);
if (newPlantPack.getName().equalsIgnoreCase(stringAns)) {
FlagAns = true;
break;
}
}
if (FlagAns) {
System.out.println(&quot; Yes! &quot; + stringAns
+ &quot; is in the pack of plants.&quot;);
} else {
System.out.println(&quot; Sorry! &quot; + stringAns
+ &quot; is not in the pack of plants.&quot;);
}
}
public static void filter(ArrayList&lt;plant&gt; plantPack) {
Scanner scan = new Scanner(System.in);
String keyWord;
boolean checkAns = false;
System.out
like to search for.&quot;);
System.out .println(&quot; Please enter the character or word your would .println(&quot; This application will search through the list
for your result. &quot;);
System.out.print(&quot; Ans:&quot;);
keyWord = scan.nextLine();
for (int i = 0; i &lt; plantPack.size(); i++) {
plant newPlantPack = plantPack.get(i);
if (newPlantPack.getName().contains(keyWord)) {
System.out.println();
System.out.println(&quot; &quot; + newPlantPack.getName());
checkAns = true;
}
}
if (checkAns == false) {
System.out
.println(&quot; Sorry user, but are database could not
any results.&quot;);
}
if (checkAns == true) {
System.out.println(&quot; Above is the queer of results we
located.&quot;); }
System.out.println(&quot;&quot;); }
public static void saveLoad(ArrayList&lt;plant&gt; plantPack) throws IOException
{ Scanner scan = new Scanner(System.in);
System.out.println(&quot; Option 1: Would like to SAVE your file? &quot;);
System.out.println(&quot; Option 2: Would like to LOAD a file? &quot;);
System.out.print(&quot; answer:&quot;);
int i = scan.nextInt();
plant testjr = new plant();
if (i == 1) {
File file = new File(&quot;plantFile.txt &quot;);
FileOutputStream outFileStream = new FileOutputStream(file);
PrintWriter outStream = new PrintWriter(outFileStream);
for (int x = 0; x &lt; plantPack.size(); x++) {
outStream.println(plantPack.get(x));
}
System.out.println();
System.out .println(&quot; File created.....PLEASE check your
desktop for plantFile.txt.&quot;);
System.out.println();
outStream.close();
}
if (i == 2) { medicinal; String iD, name, color, smell, thorns, poisonous, edible, JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showOpenDialog(null) ==
JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
Scanner input = new Scanner(file);
while (input.hasNext()) {
String test = input.nextLine();
StringTokenizer st = new StringTokenizer(test);
int count = st.countTokens();
if (count == 4)// fungus object
{
iD = st.nextToken();
name = st.nextToken();
color = st.nextToken();
poisonous = st.nextToken();
fungus newFungus = new fungus(iD, name,
color, poisonous);
plantPack.add(newFungus);
}
if (count == 5)// flower object
{
iD = st.nextToken();
name = st.nextToken();
color = st.nextToken();
thorns = st.nextToken();
smell = st.nextToken();
flower newFlower = new flower(iD, name, color, thorns,
} smell);
plantPack.add(newFlower); if (count == 6) {// weed object
iD = st.nextToken();
name = st.nextToken();
color = st.nextToken();
poisonous = st.nextToken();
edible = st.nextToken();
medicinal = st.nextToken();
weed newWeed = new weed(iD, name, color, poisonous, edible, medicinal);
plantPack.add(newWeed);
}
}
System.out.println(&quot; File has beeen uploaded.&quot;);
System.out.println();
input.close();
}
System.out.println(); }
}

flower.java

public class flower extends plant {
private String thorns;
private String smell;
private String id;
private String name;
public flower() {
}
public flower(String ID, String name, String color, String thorns,
String smell) {
super(ID, name, color);
this.thorns = thorns;
this.smell = smell;
id = ID;
this.name = name;
} public void setThorns(String thorns) {
this.thorns = thorns;
}
public void setSmell(String smell) {
this.smell = smell;
}
public String getThorns() {
return thorns;
}
public String getSmell() {
return smell;
}
public String toString() {
return id + &quot; &quot; + name + &quot; &quot; + getColor() + &quot; &quot; + thorns + &quot; &quot; +
smell;
}
}

fungus.java

public class fungus extends plant {
private String poisonous;
private String id;
private String name;
public fungus() {
}
/**
*
* @param ID
* @param name
* @param color
* @param poisonous
*/
public fungus(String ID, String name, String color, String poisonous) {
super(ID, name,color);
this.poisonous = poisonous;
id = ID;
this.name = name;
}
/***
*
* @param poisonous
*/
public void setPoisonous(String poisonous) {
this.poisonous = poisonous;
}
public String getPoisonous() {
return poisonous;
}
public String toString() {
return id + &quot; &quot; + name + &quot; &quot; + getColor() + &quot; &quot; + poisonous;
}
}

herb.java


public class herb extends plant{
private String flavor;
private String medicinal;
private String seasonal;
herb(){
}
herb(String ID, String name, String color, String f, String m, String s){
super(ID, name, color);
this.flavor =f;
this.medicinal =m;
this.seasonal=s;
}
public void setFlavor(String flavor) {
this.flavor = flavor;
}
public String getFlavor() {
return flavor;
}
public void setMedicinal(String medicinal) {
this.medicinal = medicinal;
}
public String getMedicinal() {
return medicinal;
}
public void setSeasonal(String seasonal) {
this.seasonal = seasonal;
}
public String getSeasonal() {
return seasonal;
}
}

plant.java

public class plant {
private String ID;
private String name;
private String color;
public plant() {
}
public plant(String id, String n,String c) {
ID = id;
name = n;
setColor(c);
}
public void setId(String id) {
ID = id;
}
public String getId() {
return ID;
}
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
public void setColor(String color) {
this.color = color;
}
public String getColor() {
return color;
}
}


weed.java


public class weed extends plant
{
private
private
private
private
private String
String
String
String
String poisonous;
edible;
medicinal;
id;
name; public weed()
{
} public weed(String ID, String name, String color, String poisonous, String
edible, String medicinal)
{
super(ID,name,color);
this.poisonous = poisonous;
this.edible = edible;
this.medicinal = medicinal;
id = ID;
this.name = name;
} public void setPoisonous(String poisonous)
{
this.poisonous = poisonous;
}
public void setEdible(String edible) { this.edible = edible; } public void setmedicinal(String medicinal)
{
this.medicinal = medicinal;
} public String getPoisonous()
{
return poisonous;
}
public String getEdible() {
} return edible;
public String getMedicinal() {
} return medicinal; public String toString()
{
return id + &quot; &quot; + name + &quot; &quot; +
edible + &quot; &quot; + medicinal;
}
} getColor() + &quot; &quot; + poisonous + &quot; &quot; +

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