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

After dinner with Alexander and Elizabeth we notice that Alexander is mixing som

ID: 3860664 • Letter: A

Question

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 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 has 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 flowerPack = new ArrayList(); 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 flowerPack) { // TODO: Add a flower that is specified by the user } private void removeFlower(ArrayList flowerPack) { // TODO: Remove a flower that is specified by the user } private void searchFlowers(ArrayList flowerPack) { // TODO: Search for a user specified flower } private void displayFlowers(ArrayList flowerPack) { // TODO: Display flowers using any technique you like } private void filterFlowers (ArrayList 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. } public class Flower { // Declare // attributes here private String name; private String color; private String presenceOfThorns; private String smell; public Flower() { super(); name = ""; color = ""; presenceOfThorns = ""; smell = ""; } // Create an // overridden constructor here //Create accessors and // mutators for your triats. public String getName() { return name; } public void setName(String name) { this.name = name; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public String getPresenceOfThorns() { return presenceOfThorns; } public void setPresenceOfThorns(String presenceOfThorns) { this.presenceOfThorns = presenceOfThorns; } public String getSmell() { return smell; } public void setSmell(String smell) { this.smell = smell; } @Override public String toString() { return "Flower [name=" + name + ", color=" + color + ", presenceOfThorns=" + presenceOfThorns + ", smell=" + smell + "]"; } } ================================================================== import java.util.ArrayList; import java.util.Iterator; 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 flowerPack = new ArrayList(); 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 flowerPack) { // TODO: Add a flower that is specified by the user Scanner input = new Scanner(System.in); Flower flower = new Flower(); System.out.println("Enter color"); flower.setColor(input.next()); System.out.println("Enter name"); flower.setName(input.next()); System.out.println("Enter Presence Of Thorns"); flower.setPresenceOfThorns(input.next()); System.out.println("Enter smell"); flower.setSmell(input.next()); flowerPack.add(flower); } private void removeFlower(ArrayList flowerPack) { // TODO: Remove // a flower that is specified by the user Scanner input = new Scanner(System.in); System.out.println("Enter Flower Values to be removed"); Flower flower = new Flower(); System.out.println("Enter color"); flower.setColor(input.next()); System.out.println("Enter name"); flower.setName(input.next()); System.out.println("Enter Presence Of Thorns"); flower.setPresenceOfThorns(input.next()); System.out.println("Enter smell"); flower.setSmell(input.next()); Iterator itr = flowerPack.iterator(); int i = 0; while (itr.hasNext()) { Flower tmp = itr.next(); if (tmp.getSmell().equals(flower.getSmell()) && tmp.getColor().equals(flower.getColor()) && tmp.getName().equals(flower.getName()) && tmp.getPresenceOfThorns().equals( flower.getPresenceOfThorns())) { flowerPack.remove(i); } i++; } } private void searchFlowers(ArrayList flowerPack) { // TODO: Search // for a user specified flower Scanner input = new Scanner(System.in); System.out.println("Enter Flower Values to be serached.."); Flower flower = new Flower(); System.out.println("Enter color"); flower.setColor(input.next()); System.out.println("Enter name"); flower.setName(input.next()); System.out.println("Enter Presence Of Thorns"); flower.setPresenceOfThorns(input.next()); System.out.println("Enter smell"); flower.setSmell(input.next()); Iterator itr = flowerPack.iterator(); int i = 0; while (itr.hasNext()) { Flower tmp = itr.next(); if (tmp.getSmell().equals(flower.getSmell()) && tmp.getColor().equals(flower.getColor()) && tmp.getName().equals(flower.getName()) && tmp.getPresenceOfThorns().equals( flower.getPresenceOfThorns())) { System.out.println("Flower which you mentioned is found"); } i++; } } private void displayFlowers(ArrayList flowerPack) { // TODO: // Display flowers using any technique you like Iterator itr = flowerPack.iterator(); while (itr.hasNext()) { System.out.println(((Flower) itr.next()).toString()); } } private void filterFlowers(ArrayList flowerPack) { // // TODO Filter flower results // for a user specified flower Scanner input = new Scanner(System.in); String val = input.next(); Iterator itr = flowerPack.iterator(); int i = 0; while (itr.hasNext()) { Flower tmp = itr.next(); if (tmp.getName().indexOf(val) >= 0) { System.out.println("Found Flower" + tmp.toString()); } } } } why is this code not compiling it says -Xlint:unchecked for details. I am using textpad to code it.

Explanation / Answer

There is no big problem in your code. Your code is not able to convert object type into Flower type inside methods

Flower tmp = itr.next();

In this line. You just need to typecast it as

Flower tmp = (Flower)itr.next();

Below is the complete working code

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.ArrayList;
import java.util.Iterator;
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 flowerPack = new ArrayList();
       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 flowerPack)
   {
       // TODO: Add a flower that is specified by the user
       Scanner input = new Scanner(System.in);
       Flower flower = new Flower();
       System.out.println("Enter color");
       flower.setColor(input.next());
       System.out.println("Enter name");
       flower.setName(input.next());
       System.out.println("Enter Presence Of Thorns");
       flower.setPresenceOfThorns(input.next());
       System.out.println("Enter smell");
       flower.setSmell(input.next());
       flowerPack.add(flower);
       }
   private void removeFlower(ArrayList flowerPack)
   {
       // TODO: Remove // a flower that is specified by the user
       Scanner input = new Scanner(System.in);
       System.out.println("Enter Flower Values to be removed");
       Flower flower = new Flower();
       System.out.println("Enter color");
       flower.setColor(input.next());
       System.out.println("Enter name");
       flower.setName(input.next());
       System.out.println("Enter Presence Of Thorns");
       flower.setPresenceOfThorns(input.next());
       System.out.println("Enter smell");
       flower.setSmell(input.next());
       Iterator itr = flowerPack.iterator();
       int i = 0;
       while (itr.hasNext()) {
           Flower tmp = (Flower)itr.next();
           if (tmp.getSmell().equals(flower.getSmell()) && tmp.getColor().equals(flower.getColor()) && tmp.getName().equals(flower.getName()) && tmp.getPresenceOfThorns().equals( flower.getPresenceOfThorns()))
           {
               flowerPack.remove(i);
               }
           i++;
           }
       }
   private void searchFlowers(ArrayList flowerPack) {
       // TODO: Search // for a user specified flower
       Scanner input = new Scanner(System.in);
       System.out.println("Enter Flower Values to be serached..");
       Flower flower = new Flower();
       System.out.println("Enter color");
       flower.setColor(input.next());
       System.out.println("Enter name");
       flower.setName(input.next());
       System.out.println("Enter Presence Of Thorns");
       flower.setPresenceOfThorns(input.next());
       System.out.println("Enter smell");
       flower.setSmell(input.next());
       Iterator itr = flowerPack.iterator();
       int i = 0;
       while (itr.hasNext())
       {
           Flower tmp = (Flower)itr.next();
           if (tmp.getSmell().equals(flower.getSmell()) && tmp.getColor().equals(flower.getColor()) && tmp.getName().equals(flower.getName()) && tmp.getPresenceOfThorns().equals( flower.getPresenceOfThorns()))
           {
               System.out.println("Flower which you mentioned is found");
               }
           i++;
           }
       }
   private void displayFlowers(ArrayList flowerPack) {
       // TODO: // Display flowers using any technique you like
       Iterator itr = flowerPack.iterator();
       while (itr.hasNext())
       {
           System.out.println(((Flower) itr.next()).toString());
           }
       }
   private void filterFlowers(ArrayList flowerPack) {
       // // TODO Filter flower results // for a user specified flower
       Scanner input = new Scanner(System.in);
       String val = input.next();
       Iterator itr = flowerPack.iterator();
       int i = 0;
       while (itr.hasNext())
       {
           Flower tmp = (Flower)itr.next();
           if (tmp.getName().indexOf(val) >= 0)
           {
               System.out.println("Found Flower" + tmp.toString());
               }
           }
       }
   }

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class Flower {
       // Declare // attributes here
       private String name;
       private String color;
       private String presenceOfThorns;
       private String smell;
       public Flower()
       {
           super();
           name = "";
           color = "";
           presenceOfThorns = "";
           smell = "";
       }
       // Create an // overridden constructor here
       //Create accessors and // mutators for your triats.
       public String getName()
       { return name;
       }
       public void setName(String name) { this.name = name; }
       public String getColor() { return color; }
       public void setColor(String color) { this.color = color; }
       public String getPresenceOfThorns() { return presenceOfThorns; }
       public void setPresenceOfThorns(String presenceOfThorns)
       { this.presenceOfThorns = presenceOfThorns; }
       public String getSmell() { return smell; }
       public void setSmell(String smell) { this.smell = smell; }
       @Override
       public String toString()
       {
           return "Flower [name=" + name + ", color=" + color + ", presenceOfThorns=" + presenceOfThorns + ", smell=" + smell + "]";
           }
       }
      

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