Question
Now that weve helped out our friend and his sister they have invited us over for dinner to talk about what improvements can be made.
Now that weve helped out our friend and his sister they have invited us over for dinner to talk about what improvements can be made. We find out many things about the young boy, we even find out that his name is Alexander and his sisters name is Elizabeth. Elizabeth tells us a about the day of her accident when she was climbing a tree and a branch broke causing her to fall to the ground giving her these near fatal wounds leaving her bed-ridden. Finally, we start talking about the improvements they would like made to make Elizabeths life a little happier. Alexander finds himself searching through his pack for specific traits of a flower. Some days Elizabeth wants only red flowers or only flowers with thorns as she likes to peel them off. Surely we can help them out! Create a flower object that has specific traits (name, color, presence of thorns and smell) These flower objects must be able to stay in his pack (Use an array of length 25) Be able to add, remove and search these flowers by name and traits (We can drop the sorting for now)
Using the same code as assignment 1 you can make your changes. I have included some base code for your convenience (This has 2 classes: Assignment2 and Flower). Submit 2 files: Assignment2.java and Flower.java
import java.util.Scanner;
public class Assignment2 { public static void main(String[] args) { new Assignment2(); }
// This will act as our program switchboard public Assignment2() { Scanner input = new Scanner(System.in); Flower[] flowerPack = new Flower[25]; System.out.println("Welcome to my flower 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 an item to the pack."); System.out.println("2: Remove an item from the pack."); System.out.println("3: Search for a flower."); System.out.println("4: Display the flowers in the pack."); System.out.println("0: Exit the flower pack interfact."); // Get the user input int userChoice = input.nextInt(); switch (userChoice) { case 1: addFlower(flowerPack); break; case 2: removeFlower(flowerPack); break; case 3: searchFlowers(flowerPack); break; case 4: displayFlowers(flowerPack); break; case 0: System.out .println("Thank you for using the flower pack interface. See you again soon!"); System.exit(0); } } } private void addFlower(Flower flowerPack[]) { // TODO: Add a flower that is specified by the user } private void removeFlower(Flower flowerPack[]) { // TODO: Remove a flower that is specified by the user } private void searchFlowers(Flower flowerPack[]) { // TODO: Search for a user specified flower } private void displayFlowers(Flower flowerPack[]) { // TODO: Display only the unique flowers along with a count of any // duplicates /* * For example it should say Roses - 7 Daffodils - 3 Violets - 5 */ } } // This should be in its own file public class Flower { // Declare attributes here public Flower(){ } // Create an overridden constructor here //Create accessors and mutators for your traits. }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started