After a huge success selling our flower packs to local shops we’ve acquired enou
ID: 3854410 • Letter: A
Question
After a huge success selling our flower packs to local shops we’ve acquired enough money to replace all of our items and had plenty left over to leave Alexander and Elizabeth so they can hire a doctor to travel in and hopefully help Elizabeth recover. Things have been happening very quickly and we haven’t had much time to process what we’ve accomplished, so here’s a little recap of everything we’ve done since we started our journey.
Created a basic flower pack that can add, display and remove (using arrays)
Searched through the flower pack.
Sorted the flower pack.
Created a flower object to hold attributes of each flower.
Upgraded our flower pack (to now use an ArrayList)
Filter the flower pack based on a partial search.
Upgraded our flower pack (to now hold multiple different types of plants)
Saved and Loaded information to/from a file.
*This list does not include information or tasks specific to labs
Several days after we’ve left and continued the journey we began so long ago we come to another small town that looks like a great place to stay for the night. The first thing we do, and have always done, is look for an inn. After we find what looks like the best inn we’ve ever seen and reserve our room we head to the tavern to socialize and hopefully find someone who catches our eye. After sitting at the bar for a bit a nice older lady comes up to us and starts a simple conversation. During this, we discover she is the owner of the small flower shop on the corner (what are the chances!). We politely tell her about the system we’ve developed, but sadly she isn’t interested. The bartender overhears our conversation and when the lady leaves he comes over to ask us more about our system.
The next morning we wake up in our room and look to our night stand where there is a candle that apparently burned the entire night and is hanging on to the last bit of light it can produce. Below the candle we notice a contract with what could only be construed as our signature on the bottom. What did we agree to last night??
After reading the contract it appears we’ve agreed to create a flower pack for the bartender to use. The bartender hopes to take our system, make copies and sell as many as he can to rebuild the home he lost in a fire a long time ago. There is a drawing on the first page with what appears to be some sort of interface, but it can’t be interpreted in any meaningful way.
Here’s our task for the week, since violating a contract results in death, we have no option but to finish.
Create an interface for the user to display, add, remove, sort, and filter our flower pack.You should use all of the following at least once in your interface
Stage
Button
Label
TextField
CheckBox
Layout (you can use any layout found in the lecture or book)
Menu
MenuItem
Load and Save file is not required for this assignment
The flower pack should hold flowers, weeds, fungus, and now herbs. All should be a subclass of a plant class.
Each subclass shares certain qualities (ID, Name, and Color)
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: Assignment5.java, flower.java, fungus.java, plant.java, herb.java and weed.java
Explanation / Answer
Solution: See the code below:
1. Plant class: Plant.java
----------------------------------------------------
package flowerpack;
/**
* Plant class
*
*/
public class Plant {
protected int id; //id of plant
protected String name; //name of plant
protected String color; //color of plant
/**
* Constructor
* @param id
* @param name
* @param color
*/
public Plant(int id, String name, String color) {
this.id = id;
this.name = name;
this.color = color;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the color
*/
public String getColor() {
return color;
}
/**
* @param color the color to set
*/
public void setColor(String color) {
this.color = color;
}
}
-----------------------------------------
2. Flower class: Flower.java
--------------------------------------------
package flowerpack;
/**
* Flower class
*
*/
public class Flower extends Plant {
private boolean Thorns; //whether flower contains thorns
private String Smell; //smell of flower
/**
* Constructor
* @param id
* @param name
* @param color
* @param thorns
* @param smell
*/
public Flower(int id, String name, String color, boolean thorns, String smell) {
super(id, name, color);
Thorns = thorns;
Smell = smell;
}
/**
* @return the thorns
*/
public boolean isThorns() {
return Thorns;
}
/**
* @param thorns the thorns to set
*/
public void setThorns(boolean thorns) {
Thorns = thorns;
}
/**
* @return the smell
*/
public String getSmell() {
return Smell;
}
/**
* @param smell the smell to set
*/
public void setSmell(String smell) {
Smell = smell;
}
}
-------------------------------------------------
3. Fungus class: Fungus.java
----------------------------------------------
package flowerpack;
/**
* Fungus class
*
*/
public class Fungus extends Plant {
private boolean Poisonous; //whether fungus is poisonous or not
/**
* @param id
* @param name
* @param color
* @param poisonous
*/
public Fungus(int id, String name, String color, boolean poisonous) {
super(id, name, color);
Poisonous = poisonous;
}
/**
* @return the poisonous
*/
public boolean isPoisonous() {
return Poisonous;
}
/**
* @param poisonous the poisonous to set
*/
public void setPoisonous(boolean poisonous) {
Poisonous = poisonous;
}
}
-----------------------------------------
4. Weed class: Weed.java
-----------------------------------------
package flowerpack;
/**
* Weed class
*
*/
public class Weed extends Plant {
private boolean Poisonous; //whether weed is poisonous or not
private boolean Edible; //whether weed is edible or not
private boolean Medicinal; //whether weed is medicinal or not
/**
* Constructor
* @param id
* @param name
* @param color
* @param poisonous
* @param edible
* @param medicinal
*/
public Weed(int id, String name, String color, boolean poisonous, boolean edible, boolean medicinal) {
super(id, name, color);
Poisonous = poisonous;
Edible = edible;
Medicinal = medicinal;
}
/**
* @return the poisonous
*/
public boolean isPoisonous() {
return Poisonous;
}
/**
* @param poisonous the poisonous to set
*/
public void setPoisonous(boolean poisonous) {
Poisonous = poisonous;
}
/**
* @return the edible
*/
public boolean isEdible() {
return Edible;
}
/**
* @param edible the edible to set
*/
public void setEdible(boolean edible) {
Edible = edible;
}
/**
* @return the medicinal
*/
public boolean isMedicinal() {
return Medicinal;
}
/**
* @param medicinal the medicinal to set
*/
public void setMedicinal(boolean medicinal) {
Medicinal = medicinal;
}
}
---------------------------------------------
5. Herb class: Herb.java
------------------------------------------
package flowerpack;
/**
* Herb class
*
*/
public class Herb extends Plant {
private String Flovor; //flavor of herb
private boolean Medicinal; //whether herb is medicinal or not
private boolean Seasonal; //whether herb is seasonal or not
/**
* Constructor
* @param id
* @param name
* @param color
* @param flovor
* @param medicinal
* @param seasonal
*/
public Herb(int id, String name, String color, String flovor, boolean medicinal, boolean seasonal) {
super(id, name, color);
Flovor = flovor;
Medicinal = medicinal;
Seasonal = seasonal;
}
/**
* @return the flovor
*/
public String getFlovor() {
return Flovor;
}
/**
* @param flovor the flovor to set
*/
public void setFlovor(String flovor) {
Flovor = flovor;
}
/**
* @return the medicinal
*/
public boolean isMedicinal() {
return Medicinal;
}
/**
* @param medicinal the medicinal to set
*/
public void setMedicinal(boolean medicinal) {
Medicinal = medicinal;
}
/**
* @return the seasonal
*/
public boolean isSeasonal() {
return Seasonal;
}
/**
* @param seasonal the seasonal to set
*/
public void setSeasonal(boolean seasonal) {
Seasonal = seasonal;
}
}
------------------------------
6. FlowerPack class: FlowerPack.java
---------------------------------
package flowerpack;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* FlowerPack class
*
*/
public class FlowerPack {
private ArrayList<Plant> flowerPack; //pack of different plants
/**
* Default constructor
*/
public FlowerPack() {
flowerPack = new ArrayList<Plant>();
}
/**
* adds a plant to pack
* @param plant
*/
public void add(Plant plant)
{
flowerPack.add(plant);
}
/**
* removes a plant from pack
* @param index
* @return
*/
public Plant remove(int index)
{
return flowerPack.remove(index);
}
/**
* sorts flower pack based on plant names
*/
public void sort()
{
flowerPack.sort(new Comparator<Plant>() {
@Override
public int compare(Plant o1, Plant o2) {
// TODO Auto-generated method stub
return o1.getName().compareTo(o2.getName());
}
});
}
/**
* filters plant based on a start index and end index
* @param start
* @param end
* @return
*/
public List<Plant> filter(int start, int end)
{
return flowerPack.subList(start, end);
}
/**
* displays contents of flower pack
*/
public void display()
{
Iterator<Plant> iterator=flowerPack.iterator();
while(iterator.hasNext())
{
Plant plant=(Plant)iterator.next();
System.out.println(plant.getName());
}
}
/**
* returns whether flower pack has plants or not
* @return
*/
public boolean hasPlants()
{
return (!flowerPack.isEmpty());
}
}
-------------------------------------
7. Assignment5 class: Assignment5.java
---------------------------------------
package flowerpack;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* Assignment5 class
*/
public class Assignment5 extends Application {
@Override
public void start(Stage primaryStage) {
FlowerPack flowerPack=new FlowerPack();
HBox hb=new HBox();
hb.setPadding(new Insets(15, 12, 15, 12));
hb.setSpacing(10);
Button displayButton = new Button();
displayButton.setText("Display");
displayButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(flowerPack.hasPlants())
{
flowerPack.display();
}
else
{
System.out.println("No plants to display!!!");
}
}
});
Button addButton = new Button();
addButton.setText("Add Plant");
addButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Click to add a plant");
}
});
hb.getChildren().addAll(displayButton,addButton);
StackPane root = new StackPane();
root.getChildren().add(hb);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
---------------------------------------
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.