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

Below I have the code listed for my flowerpack. The last thing I need to be able

ID: 3861232 • Letter: B

Question

Below I have the code listed for my flowerpack. The last thing I need to be able to do is analyze information from my flower pack according to the following instructions:

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.

No GUI is required for this program.

This is the analysis code I have from a different flowerpack program, I note when it starts and ends. The program starts with the plantdriver.

I need to incorporate this feature into my program given the instructions listed here. Thank you.

//Analysis code example

String[] keyWords = {"ar", "ne", "um", "ll", "r", "u", "dragon"};
  
Integer[] result;
  
private void analysisReport()
{
plantPack.size();
  
workPanel.removeAll();
  
JTextArea txtResult = new JTextArea();
  
ArrayList<Integer[]> arr = new ArrayList<Integer[]>();
  
for(int i = 0; i < plantPack.size(); i++)
{
result = new Integer[keyWords.length];
  
for(int j = 0; j < keyWords.length; j++)
{
result[j] = analyze(plantPack.get(i).getName().trim(), keyWords[j].trim(), 0);
}
  
arr.add(result.clone());
}
  
for(int i = 0; i < plantPack.size(); i++)
{
txtResult.append(plantPack.get(i).getName());
  
result = arr.get(i);
  
for(int j = 0; j < result.length; j++)
{
txtResult.append(" " + String.valueOf(result[j]));
}
  
txtResult.append(" ");
}
  
workPanel.add(txtResult);
  
guiFrame.repaint();
  
guiFrame.revalidate();
}
  
private int analyze(String flowerName, String keyWord, int count)
{
if(flowerName.length() == 0)
{
return count;
}
  
if(flowerName.length() < keyWord.length())
{
return count;
}
  
if(flowerName.contains(keyWord))
{
count++;
  
flowerName = flowerName.replaceFirst(keyWord, "");
  
return analyze(flowerName, keyWord, count);
}
  
return count;
  
}

//end analysis code example

Here is the code I have:

//PlantDriver

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Scanner;

public class PlantDriver {
public static void main(String[] args) throws IOException {
new PlantDriver();
}
public PlantDriver() throws IOException {
Scanner input = new Scanner(System.in);
LinkedList<Plant> plantPack = new LinkedList<Plant>();
System.out.println("Welcome to my Plant pack interface.");
System.out.println("Please select a number from the options below");
System.out.println("");
while (true) {
// Give the user a list of their options
System.out.println("1: Add a plant item to the pack.");
System.out.println("2: Add a flower item to the pack.");
System.out.println("3: Add a fungus item to the pack.");
System.out.println("4: Add a weed item to the pack.");
System.out.println("5: Add a herb item to the pack.");
System.out.println("6: Remove a plant item (regardless of its type)from the pack.");
System.out.println("7: Search for a plant by name.");
System.out.println("8: Display the plants in the pack.");
System.out.println("9: Filter plant pack by incomplete name");
System.out.println("10: Print Plants from the pack to a file!");
System.out.println("11: Read Plants from a file that is already created and output them");
System.out.println("0: Exit the flower pack interface.");
// Get the user input
int userChoice = input.nextInt();
switch (userChoice) {
case 1:
addPlant(plantPack);
break;
case 2:
addFlower(plantPack);
break;
case 3:
addFungus(plantPack);
break;
case 4:
addWeed(plantPack);
break;
case 5:
addHerb(plantPack);
break;
case 6:
removePlant(plantPack);
break;
case 7:
searchPlants(plantPack);
break;
case 8:
displayPlants(plantPack);
break;
case 9:
filterPlants(plantPack);
break;
case 10:
savePlantsToFile(plantPack);
break;
case 11:
readPlantsFromFile();
break;
case 0:
System.out.println("Thank you for using the plant pack interface. See you again soon!");
System.exit(0);
}
}
}
private void addPlant(LinkedList<Plant> plantPack) {
// Add a plant that is specified by the user
String plantName;
String plantColor;
String plantID;
Scanner plantInput = new Scanner(System.in);
System.out.println("Please enter the name of a plant type to add:");
plantName = plantInput.nextLine();
System.out.println("What is the color of the plant you would like to add?: ");
plantColor = plantInput.nextLine();
System.out.println("What is the ID of the plant?: ");
plantID = plantInput.nextLine();
Plant thePlant = new Plant(plantColor, plantID, plantName);
plantPack.add(thePlant);
  
}
private void addFlower(LinkedList<Plant> plantPack) {
// Add a plant that is specified by the user
String flowerName;
String flowerColor;
String flowerID;
String scentType;
String isItThorny;
boolean isThorny;
Scanner flowerInput = new Scanner(System.in);
System.out.println("Please enter the name of a flower type to add:");
flowerName = flowerInput.nextLine();
System.out.println("What is the color of the flower you would like to add?: ");
flowerColor = flowerInput.nextLine();
System.out.println("What is the ID of the flower?: ");
flowerID = flowerInput.nextLine();
System.out.println("Is the flower a thorny kind of flower? (Please answer yes or no with y or n only");
isItThorny = flowerInput.nextLine();
if (isItThorny.equalsIgnoreCase("y")) {
isThorny = true;
} else {
isThorny = false;
}
System.out.println("Please describe the scent of the flower: ");
scentType = flowerInput.nextLine();
Flower theFlower = new Flower(flowerColor, flowerID, flowerName, scentType, isThorny);
plantPack.add(theFlower);
}
private void addFungus(LinkedList<Plant> plantPack) {
// Add a plant that is specified by the user
String fungusName;
String fungusColor;
String fungusID;
String isItPoisnous;
boolean isPoisonous;
Scanner fungusInput = new Scanner(System.in);
System.out.println("Please enter the name of a fungus type to add:");
fungusName = fungusInput.nextLine();
System.out.println("What is the color of the fungus you would like to add?: ");
fungusColor = fungusInput.nextLine();
System.out.println("What is the ID of the fungus?: ");
fungusID = fungusInput.nextLine();
System.out.println("Is the fungus a poisonous kind of fungus? (Please answer yes or no with y or n only");
isItPoisnous = fungusInput.nextLine();
if (isItPoisnous.equalsIgnoreCase("y")) {
isPoisonous = true;
} else {
isPoisonous = false;
}
Fungus newFungus = new Fungus(fungusColor, fungusID, fungusName, isPoisonous);
plantPack.add(newFungus);
}
private void addWeed(LinkedList<Plant> plantPack) {
// Add a plant that is specified by the user
String weedName;
String weedColor;
String weedID;
String isItEdible;
boolean isEdible;
String isItMedicinal;
boolean isMedicinal;
String isItPoisnous;
boolean isPoisonous;
Scanner weedInput = new Scanner(System.in);
System.out.println("Please enter the name of a weed type to add:");
weedName = weedInput.nextLine();
System.out.println("What is the color of the weed you would like to add?: ");
weedColor = weedInput.nextLine();
System.out.println("What is the ID of the weed?: ");
weedID = weedInput.nextLine();
System.out.println("Is the weed an edible kind of weed? (Please answer yes or no with y or n only");
isItEdible = weedInput.nextLine();
if (isItEdible.equalsIgnoreCase("y")) {
isEdible = true;
} else {
isEdible = false;
}
System.out.println("Is the weed a medicinal kind of weed? (Please answer yes or no with y or n only");
isItMedicinal = weedInput.nextLine();
if (isItMedicinal.equalsIgnoreCase("y")) {
isMedicinal = true;
} else {
isMedicinal = false;
}
System.out.println("Is the weed a poisonous kind of weed? (Please answer yes or no with y or n only");
isItPoisnous = weedInput.nextLine();
if (isItPoisnous.equalsIgnoreCase("y")) {
isPoisonous = true;
} else {
isPoisonous = false;
}
Plant thePlant = new Weed(weedColor, weedID, weedName, isEdible, isMedicinal, isPoisonous);
plantPack.add(thePlant);
}
private void addHerb(LinkedList<Plant> plantPack) {
// Add a plant that is specified by the user
String herbName;
String herbColor;
String herbID;
String herbFlavor;
String isItMedicinal;
boolean isMedicinal;
String isItSeasonal;
boolean isSeasonal;
Scanner herbInput = new Scanner(System.in);
System.out.println("Please enter the name of a herb type to add:");
herbName = herbInput.nextLine();
System.out.println("What is the color of the herb you would like to add?: ");
herbColor = herbInput.nextLine();
System.out.println("What is the ID of the herb?: ");
herbID = herbInput.nextLine();
System.out.println("What is the flavor of the herb?: ");
herbFlavor = herbInput.nextLine();
System.out.println("Is the herb a medicinal kind of herb? (Please answer yes or no with y or n only");
isItMedicinal = herbInput.nextLine();
if (isItMedicinal.equalsIgnoreCase("y")) {
isMedicinal = true;
} else {
isMedicinal = false;
}
System.out.println("Is the herb a seasonal herb? (Please answer yes or no with y or n only");
isItSeasonal = herbInput.nextLine();
if (isItSeasonal.equalsIgnoreCase("y")) {
isSeasonal = true;
} else {
isSeasonal = false;
}
Plant thePlant = new Herb(herbColor, herbID, herbName, herbFlavor, isMedicinal, isSeasonal);
plantPack.add(thePlant);
}
private void removePlant(LinkedList<Plant> plantPack) {
// Remove a plant that is specified by the user
String plantName;
Scanner plantInput = new Scanner(System.in);
System.out.println(
"Please enter the name of the plant (regardless of the type (e.g. Plant, Flower, Fungus, Weed) that you would like to remove: ");
plantName = plantInput.nextLine();
for (Plant thePlant : plantPack) {
if (thePlant.getName().equals(plantName)) {
plantPack.remove(thePlant);
}
}
}
private void searchPlants(LinkedList<Plant> plantPack) {
String plantName;
Scanner plantInput = new Scanner(System.in);
System.out.println(
"Please enter the name of the plant (regardless of the type (e.g. Plant, Flower, Fungus, Weed, Herb) that you would like to search: ");
plantName = plantInput.nextLine();
int index = -1;
for (int i = 0; i < plantPack.size(); i++) { // done in O(n) time This
// is a linear search
if (plantName.equalsIgnoreCase(plantPack.get(i).getName())) {
index = i;
break;
}
}
if (index != -1) {
System.out.println("The search element : " + plantName + " was found");
} else {
System.out.println("The search element was not found in the LinkedList.");
}
}
private void displayPlants(LinkedList<Plant> plantPack) {
for (Plant thePlant : plantPack) {
System.out.println(thePlant.toString());
}
}
private void filterPlants(LinkedList<Plant> plantPack) {
// TODO Filter plant
String plantName;
Scanner plantInput = new Scanner(System.in);
System.out.println("Enter the name of a plant to search by first character?");
plantName = plantInput.nextLine();
for (Plant thePlant : plantPack) {
if (thePlant.getName().charAt(0) == plantName.charAt(0)) {
System.out.println("Flowers based on the first character: " + thePlant.toString());
}
}
}
private void savePlantsToFile(LinkedList<Plant> plantPack) throws IOException {
File plantFile = new File("plantFile.txt");
FileOutputStream plantStream = new FileOutputStream(plantFile);
PrintWriter plantOutStream = new PrintWriter(plantStream);
for (Plant thePlant : plantPack) {
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());
System.out.println(newPlant.toString());
}
plantInput.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

//Plant

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

//Flower

class Flower extends Plant {
private boolean hasThorns;
private String smell;
public Flower(String flowerColor, String flowerID, String flowerName, String smell, boolean hasThorns) {
super(flowerColor, flowerID, flowerName);
this.hasThorns = hasThorns;
this.smell = smell;
}
public void setSmell(String flowerSmell) {
this.smell = flowerSmell;
}
public void setThorns(boolean isThorny) {
this.hasThorns = isThorny;
}
public String getSmell() {
return smell;
}
public boolean getIsThorny() {
return hasThorns;
}
public String toString() {
return "This flower is colored: " + super.getColor() + " with a name of " + super.getName() + " and an ID of "
+ super.getID() + " the smell is " + this.smell + " and it is thorny = " + this.hasThorns;
}
@Override
public boolean equals(Object otherFlower) {
if (otherFlower == null) {
return false;
}
if (!Flower.class.isAssignableFrom(otherFlower.getClass())) {
return false;
}
Flower other = (Flower) otherFlower;
if (!(this.getName().equals(other.getName()))) {
return false;
}
if (!(this.getColor().equals(other.getColor()))) {
return false;
}
if ((this.getSmell() != (other.getSmell()))) {
return false;
}
if (!(this.getID().equals(other.getID()))) {
return false;
}
if (this.getIsThorny() != other.getIsThorny()) {
return false;
}
return true;
}
}

//Fungus

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

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;

}
}

//Herb

class Herb extends Plant {
private String flavor;
private boolean isMedicinal, isSeasonal;   
public Herb(String herbColor, String herbID, String herbName, String flavor, boolean isMedicinal, boolean isSeasonal) {
super(herbColor, herbID, herbName);
this.flavor = flavor;
this.isMedicinal = isMedicinal;
this.isSeasonal = isSeasonal;}
public void setHerbFlavor(String herbFlavor) {
this.flavor = herbFlavor;}
public String getHerbFlavor() {
return flavor;}
public void setMedicinalProperty(boolean isMedicinal) {
this.isMedicinal = isMedicinal;}
public boolean getMedicinalProperty() {
return isMedicinal;}
public void setSeasonalProperty(boolean isSeasonal) {
this.isSeasonal = isSeasonal;}
public boolean getSeasonalProperty() {
return isSeasonal;}
public String toString() {
return "This herb is of " + this.getColor() + " color and is called " + this.getName() +
" with an ID of " + this.getID() + " with a " + this.getHerbFlavor() + " flavor and " + " with a seasonal property of "
+ this.getSeasonalProperty() + " and a Medicinal Property of " + this.getMedicinalProperty();
}
@Override
public boolean equals(Object otherHerb) {
if(otherHerb == null) {
return false;
}
if(!Herb.class.isAssignableFrom(otherHerb.getClass())) {
return false;
}
Herb other = (Herb) otherHerb;
if (!this.flavor.equals(other.flavor)) {
return false;
}
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.isMedicinal != other.isMedicinal) {
return false;
}
if (this.isSeasonal != other.isSeasonal) {
return false;
}
return true;
}
}

Explanation / Answer

Here is the sample codes segment as per the given scenerio, please go through it throughly:-

//===codes used to create the main program which follows this open-create-query structure =====

public class Plantation

{

String directory="index";

public static void main(String[] args)

{

// Name of the directory that holds the index

String directory="index";

// Instantiate a new Plants tool

MyPlants Plants = new MyPlants();

// open the directory

Plants.openIndex(directory, true);

// add a few documents

Plants.addDoc("Details about various plants");

Plants.addDoc("configuration of the various plants");

Plants.addDoc("Plants Databases...features and their characteristics");

// Close the index

Plants.closeIndex();

// Now, search for some term

String query[] = {"Plants"};

Plants.search(query);

}

}

//=======Thses codes used to create the index============

public void openIndex(String directory, boolean newIndex) {

try {

// Link the directory on the FileSystem to the application

index = FSDirectory.open(new File(directory));

// Check whether the index has already been locked

// (or not properly closed).

if (IndexWriter.isLocked(index))

IndexWriter.unlock(index);

if (writer == null)

// Link the repository to the IndexWriter

writer = new IndexWriter(index, analyzer, newIndex,

IndexWriter.MaxFieldLength.LIMITED);

} catch (Exception e) {

System.out.println("Got an Exception: " + e.getMessage());

}

}

public void closeIndex() {

try {

writer.optimize();

writer.close();

} catch (Exception e) {

System.out.println("Got an Exception: " + e.getMessage());

}

}

//=======Thses codes used to adding documents into created index============

public void addDoc(String Value) {

try {

// Instantiate a new document

Document doc = new Document();

// Put the value in a field name content

Field f = new Field("content", value, Field.Store.YES,

Field.Index.ANALYZED);

// Add the field to the document

doc.add(f);

// And add the document to the index

writer.addDocument(doc);

} catch (Exception e) {

System.out.println("Got an Exception: " + e.getMessage());

}

}

//=======Thses codes used to searching the index ============

public void search(String[] args) {

// Nothing given? Search for "Plants".

String querystr = args.length > 0 ? args[0] : "Plants";

try {

// Instantiate a query parser

QueryParser parser = new QueryParser(Version.Plants_30, "content",

analyzer);

// Parse

Query q = parser.parse(querystr);

// We look for top-10 results

int hitsPerPage = 10;

// Instantiate a searcher

IndexSearcher searcher = new IndexSearcher(index, true);

// Ranker

TopScoreDocCollector collector = TopScoreDocCollector.create(

hitsPerPage, true);

// Search!

searcher.search(q, collector);

// Retrieve the top-10 documents

ScoreDoc[] hits = collector.topDocs().scoreDocs;

// Display results

System.out.println("Found " + hits.length + " hits.");

for (int i = 0; i < hits.length; ++i) {

int docId = hits[i].doc;

Document d = searcher.doc(docId);

System.out.println((i + 1) + ". " + d.get("content"));

}

// Close the searcher

searcher.close();

} catch (Exception e) {

System.out.println("Got an Exception: " + e.getMessage());

}

}

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