Question

After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a...

After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth which eases her pain and helps her sleep. Once the medicine is administered we begin small talk with Alexander. During the conversation he tells us the story about how his mother and father were hopelessly in love and were lucky enough to die side by side protecting the things they loved most, their children.

In the middle of the story we become distracted by Elizabeth trying to request something, but we can't make out what she wants because her medicine has kicked in. After a few moments we determine she is requesting a flower, but we can't understand the entire name, just the start. Instantly we remember that we know how to search through our flower pack while only using partial names. We instantly turn around and start working on yet another improvement to the flower pack.

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 ArrayList)

Be able to add, display and remove flowers

Implement a partial search (Searching for 'r' should return all flowers with an 'r' in their name, and the same goes for any partial search). This is commonly known as a filter.

As a new addition a rubric has been added to blackboard for the assignment.

Using the same code as assignment 2 you can make your changes. I have included some base code for your convenience (This is 2 classes, Assignment3 and Flower).

Submit 2 files: Assignment3.java and flower.java

import java.util.ArrayList;

import java.util.Scanner;

public class Assignment3 {

                        public static void main(String[] args) {

                                                new Assignment3();

                        }

                        // This will act as our program switchboard

                        public Assignment3() {

                                                Scanner input = new Scanner(System.in);

                                                ArrayList<Flower> flowerPack = new ArrayList<Flower>();

                                                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("5: Filter flower pack by incomplete name");

                                                                        System.out.println("0: Exit the flower pack interface.");

                                                                        // 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 5:

                                                                                                filterFlowers(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(ArrayList<Flower> flowerPack) {

                                                // TODO: Add a flower that is specified by the user

                        }

                        private void removeFlower(ArrayList<Flower> flowerPack) {

                                                // TODO: Remove a flower that is specified by the user

                        }

                        private void searchFlowers(ArrayList<Flower> flowerPack) {

                                                // TODO: Search for a user specified flower

                        }

                        private void displayFlowers(ArrayList<Flower> flowerPack) {

                                                // TODO: Display flowers using any technique you like

                        }

                       

                        private void filterFlowers (ArrayList<Flower> flowerPack) {

                                                // TODO Filter flower results

                                               

                        }

}

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

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi Friend, Please find my implementation.

Please let me know in case of any issue.

############### Flower.java ############

// This should be in its own file

public class Flower {

   // Declare attributes here

   private String name;

   private String color;

   private boolean isThrown;

   private String smell;

   public Flower(){

       name = "";

       color = "";

       isThrown = false;

       smell = "";

   }

   // Create an overridden constructor here

   public Flower(String name, String color, boolean isThrown, String smell) {

       this.name = name;

       this.color = color;

       this.isThrown = isThrown;

       this.smell = smell;

   }

   //Create accessors and mutators for your triats.

  

   public String getName() {

       return name;

   }

   public String getColor() {

       return color;

   }

   public boolean isThrown() {

       return isThrown;

   }

   public String getSmell() {

       return smell;

   }

   public void setName(String name) {

       this.name = name;

   }

   public void setColor(String color) {

       this.color = color;

   }

   public void setThrown(boolean isThrown) {

       this.isThrown = isThrown;

   }

   public void setSmell(String smell) {

       this.smell = smell;

   }

}

################ Assignment3.java #############

import java.util.ArrayList;

import java.util.Scanner;

public class Assignment3 {

   private static Scanner input = new Scanner(System.in);

   public static void main(String[] args) {

       new Assignment3();

   }

   // This will act as our program switchboard

   public Assignment3() {

       ArrayList<Flower> flowerPack = new ArrayList<Flower>();

       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("5: Filter flower pack by incomplete name");

           System.out.println("0: Exit the flower pack interface.");

           // 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 5:

               filterFlowers(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(ArrayList<Flower> flowerPack) {

       // taking user input

       boolean isThrown = false;

       System.out.print("Enter name of flower: ");

       String name = input.nextLine();

       System.out.print("Enter color: ");

       String color = input.next();

       System.out.print("Enter smell: ");

       String smell = input.next();

       System.out.print("Is this flower has thrown(y/n) : ");

       char t = Character.toLowerCase(input.next().charAt(0));

       if(t == 'y')

           isThrown = true;

       // creating new Flower object

       Flower f = new Flower(name, color, isThrown, smell);

       // adding in linked list

       flowerPack.add(f);

   }

   private void removeFlower(ArrayList<Flower> flowerPack) {

       // taking user input

       System.out.print("Enter name of flower to be romoved: ");

       String name = input.nextLine();

       for(int i=0; i<flowerPack.size(); i++){

           if(flowerPack.get(i).getName().equalsIgnoreCase(name)){

               flowerPack.remove(i);

               break;

           }

       }

   }

   private void searchFlowers(ArrayList<Flower> flowerPack) {

       // taking user input

       System.out.print("Enter name of flower to be search: ");

       String name = input.nextLine();

       for(int i=0; i<flowerPack.size(); i++){

           if(flowerPack.get(i).getName().equalsIgnoreCase(name)){

               Flower f = flowerPack.get(i);

               System.out.println("Flower "+name+" is available at index "+i);

               System.out.println("Details of flower: ");

               System.out.println("Name: "+f.getName()+", Color: "+f.getColor()+

                       ", isThrown: "+f.isThrown()+", Smell: "+f.getSmell());

               break;

           }

       }

   }

   private void displayFlowers(ArrayList<Flower> flowerPack) {

       for(int i=0; i<flowerPack.size(); i++){

           Flower f = flowerPack.get(i);

           System.out.println("Name: "+f.getName()+", Color: "+f.getColor()+

                   ", isThrown: "+f.isThrown()+", Smell: "+f.getSmell());

           System.out.println();

       }

   }

   private void filterFlowers (ArrayList<Flower> flowerPack) {

       // taking user input

       System.out.print("Enter WORD for partial search: ");

       String name = input.next();

      

       // creating list to store searched item

       ArrayList<Flower> partialSearch = new ArrayList<>();

      

       for(int i=0; i<flowerPack.size(); i++){

           if(flowerPack.get(i).getName().contains(name)){

               partialSearch.add(flowerPack.get(i));

           }

       }

      

       System.out.println("Flowers details containg "+name+" in name: ");

       for(Flower f : partialSearch){

           System.out.println("Name: "+f.getName()+", Color: "+f.getColor()+

                   ", isThrown: "+f.isThrown()+", Smell: "+f.getSmell());

           System.out.println();

       }

   }

}

Add a comment
Know the answer?
Add Answer to:
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Original question: I need a program that simulates a flower pack with the traits listed below:...

    Original question: I need a program that simulates a flower pack with the traits listed below: - You must use a LinkedList for storage (not an Arrray list). - 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 -...

  • Java Programming Question

    After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • Let's fix the displayMenu() method! First, edit the method to do the following: We want to...

    Let's fix the displayMenu() method! First, edit the method to do the following: We want to also allow the user to quit. Include a "Quit" option in the print statements! Have it get the user input from within the method itself and return an int based on the user's choice. (Make sure to also edit the method header and how it is called back in the main() method!) What is the method's return type now?                  ...

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

  • Java - Car Dealership Hey, so i am having a little trouble with my code, so...

    Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...

  • This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

    Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...

  • Hello, i need help with this homework: Code provided: public class DirectedWeightedExampleSlide18 { public static void...

    Hello, i need help with this homework: Code provided: public class DirectedWeightedExampleSlide18 { public static void main(String[] args) { int currentVertex, userChoice; Scanner input = new Scanner(System.in); // create graph using your WeightedGraph based on author's Graph WeightedGraph myGraph = new WeightedGraph(4); // add labels myGraph.setLabel(0,"Spot zero"); myGraph.setLabel(1,"Spot one"); myGraph.setLabel(2,"Spot two"); myGraph.setLabel(3,"Spot three"); // Add each edge (this directed Graph has 5 edges, // so we add 5 edges) myGraph.addEdge(0,2,9); myGraph.addEdge(1,0,7); myGraph.addEdge(2,3,12); myGraph.addEdge(3,0,15); myGraph.addEdge(3,1,6); // let's pretend we are on...

  • must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int...

    must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...

  • please help fill out the class menu create a prototype that will display information about housing...

    please help fill out the class menu create a prototype that will display information about housing data1. In this prototype you will use dynamic array data structures to store the data and compute metrics. For the requirements of the prototype, your client has given you a list of metrics and operations. The user interface will be a menu that displays this list and prompts the user to choose which option to execute.You will create two classes. First you will create...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT