Now that we\'ve managed to weave our way through the North Woods safely and are
ID: 3832412 • Letter: N
Question
Now that we've managed to weave our way through the North Woods safely and are one step closer to Thanto, our destination. After a night spent on the far side of the woods we wake up to the sound of rushing water. We quickly open our eyes and notice the Fraus River not 20 feet from where we lay. The river must have been expanding throughout the night in an attempt to swallow us whole. As we are standing on our ever shrinking piece of land we notice a homemade raft with a single passenger. After screaming and waving for a short amount of time we get the captain of this raft to paddle towards us.
After some quick deliberations the captain agrees that he can take us on his trip across the ever widening river. As always, there is a bit of a snag in our free ride. Our ride isn't exactly free, so we've got to do some work to earn the ride. What we need to do in order to earn our ride is increase the storage capacity and efficiency of our flower pack.
This new version of flower pack should share some of the traits of our old one, with a minor adjustment.
You must use a LinkedList for storage.
You must be able to display, add, remove, sort, filter, and 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) – 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 7 files: Final.java, flower.java, fungus.java, plant.java, weed.java, herb.java and node.java
There is ABSOLUTELY NO GUI required
Explanation / Answer
[12:07 AM, 5/4/2017] +91 85005 05910: 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 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;
}
}
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;
}
}
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;
}
}
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<Plant> flowerPack = new LinkedList<>();
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. 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 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
[12:08 AM, 5/4/2017] +91 85005 05910: 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 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;
}
}
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;
}
}
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;
}
}
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<Plant> flowerPack = new LinkedList<>();
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. 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 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
[12:09 AM, 5/4/2017] +91 85005 05910: 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 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;
}
}
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;
}
}
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;
}
}
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<Plant> flowerPack = new LinkedList<>();
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. 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 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:
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);
}
}
}
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 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;
}
}
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;
}
}
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;
}
}
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<Plant> flowerPack = new LinkedList<>();
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. 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 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:
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);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.