After dinner with Alexander and Elizabeth we notice that Ale

After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that 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 thing that 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 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 is 2 classes, Assignment3 and Flower.

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.

}

CODE TO MODIFY FROM ASSIGNMENT 2 (2 classes Assignment 2 and flower)

package Assignment2;

/**

* • He can only carry 25 flowers as adding any more causes many of them to

become crushed.

* • He should be able to add and remove flowers by using their name.

* • He needs to be able to search for a specific type of flower in his pack

in case his sister has a special request.

* • He needs to be able to sort flowers by their names alphabetically in

ascending order (A-Z)

* • He needs to show how many of each flower he has in his pack.

*/

import java.util.*;

public class Assignment2 {

Scanner input = new Scanner(System.in);

public static void main(String[] args){

new Assignment2();

}

// This will act as our program switchboard

public Assignment2(){

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 interface.\");

// Get the user input

int userInt = input.nextInt();

input.nextLine();

switch(userInt){

case 1:

addFlower(flowerPack);

break;

case 2:

removeFlower(flowerPack);

break;

/*case 3:

sortFlowers(flowerPack);

searchFlowers(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);

default:

System.out.println(\"Invalid input\");

break;

}

}

}

private void addFlower(Flower flowerPack[]) {

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

String flowerName;

String flowerColor;

int num;

boolean flowerThorns;

boolean flowerSmell;

System.out.print(\"Please enter the name of your flower: \");

flowerName = input.nextLine();

System.out.print(\"What color is the flower? \");

flowerColor = input.nextLine();

while(true){

System.out.println(\"Does the flower have thorns?\ 1: Yes\ 2: No\");

num = input.nextInt();

if(num == 1)

{

flowerThorns = true;

break;

}

else if(num == 2)

{

flowerThorns = false;

break;

}

else

{

System.out.println(\"Invalid try again\");

}

}

while(true){

System.out.println(\"Does the flower have a smell?\ 1: Yes\ 2: No\");

num = input.nextInt();

if(num == 1)

{

flowerSmell = true;

break;

}

else if(num == 2)

{

flowerSmell = false;

break;

}

else

{

System.out.println(\"Invalid try again\");

}

}

for(int x = 0; x < flowerPack.length; x++)

{

if(flowerPack[x] == null)

{

flowerPack[x] = new Flower(flowerName, flowerColor,

flowerThorns, flowerSmell);

break;

}

else if((x == flowerPack.length-1) && flowerPack[x] != null)

{

System.out.println(\"Your flower pack is full!\");

System.out.println();

System.out.println();

}

}

}

private void removeFlower(Flower flowerPack[]) {

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

String strUser = \" \";

int intUser = 0;

int user;

boolean found = false;

System.out.print(\"How would you like to remove a flower?\ 1: Name\ 2: Color\ 3: Presence of thorns\ 4: Presence of Smell\ \");

user = input.nextInt();

if(user == 1)

{

System.out.print(\"What is the name of the flower you would like to delete?\" );

input.nextLine();

strUser = input.nextLine();

for(int x = 0; x < flowerPack.length; x++)

{

if(flowerPack[x] != null)

{

if(strUser.equalsIgnoreCase(flowerPack[x].getName()))

{

flowerPack[x] = null;

found = true;

}

}

}

}

else if(user == 2)

{

System.out.print(\"What color is the flower you would like to delete? \");

input.nextLine();

strUser = input.nextLine();

for(int x = 0; x < flowerPack.length; x++)

{

if(flowerPack[x] != null)

{

if(strUser.equalsIgnoreCase(flowerPack[x].getColor()))

{

flowerPack[x] = null;

found = true;

}

}

}

}

else if(user == 3)

{

System.out.print(\"Would you like to delete flowers with or without thorns?\ 1: Delete WITH thorns\ 2: Delete WITHOUT thorns\ \");

input.nextLine();

intUser = input.nextInt();

if(intUser == 1)

{

for(int x = 0; x

{

if(flowerPack[x] != null)

{

if(flowerPack[x].hasThorns() == true)

{

flowerPack[x] = null;

found = true;

}

}

}

}

else if(intUser == 2)

{

for(int x = 0; x

{

if(flowerPack[x] != null)

{

if(flowerPack[x].hasThorns() == false)

{

flowerPack[x] = null;

found = true;

}

}

}

}

else

System.out.println(\"Invalid, no flower has been removed\");

}

else if(user == 4)

{

System.out.print(\"Would you like to flowers with or without smell?\ 1: Delete WITH smell\ 2: Delete WITHOUT smell\ \");

input.nextLine();

intUser = input.nextInt();

if(intUser == 1)

{

for(int x = 0; x

{

if(flowerPack[x] != null)

{

if(flowerPack[x].hasSmell() == true)

{

flowerPack[x] = null;

found = true;

}

}

}

}

else if(intUser == 2)

{

for(int x = 0; x

{

if(flowerPack[x] != null)

{

if(flowerPack[x].hasSmell() == false)

{

flowerPack[x] = null;

found = true;

}

}

}

}

else

System.out.println(\"Invalid, no flower has been removed\");

}

else

{

System.out.println(\"Invalid, no flower has been removed\");

}

if(found)

{

System.out.println(\"Flower has been removed\");

System.out.println();

System.out.println();

}

else

{

System.out.println(\"Flower not found\");

System.out.println();

System.out.println();

}

}

/*private void sortFlowers(String flowerPack[]) {

// TODO: Sort the flowers in the pack (No need to display them here) -

Use Selection or Insertion sorts

// NOTE: Special care is needed when dealing with strings! research the

compareTo() method with strings

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

{

if(flowerPack[i] == null)

break;

for(int j = i+1; j < flowerPack.length; j++)

{

if(flowerPack[j] != null && flowerPack[i] != null){

if(flowerPack[j].compareToIgnoreCase(flowerPack[i])<0)

{

String temp = flowerPack[i];

flowerPack[i] = flowerPack[j];

flowerPack[j] = temp;

}

}

}

}

System.out.println(\"Your flowers have been sorted\");

System.out.println();

System.out.println();

}*/

private void searchFlowers(Flower flowerPack[]) {

// TODO: Search for a user specified flower

String strUser = \" \";

int intUser = 0;

int user;

boolean found = false;

int count = 0;

System.out.print(\"How would you like to search for a flower?\ 1: Name\ 2: Color\ 3: Presence of thorns\ 4: Presence of Smell\ \");

user = input.nextInt();

if(user == 1)

{

System.out.print(\"What is the name of the flower you would like to search for? \");

input.nextLine();

strUser = input.nextLine();

for(int x = 0; x < flowerPack.length; x++)

{

if(flowerPack[x] != null)

{

if(strUser.equalsIgnoreCase(flowerPack[x].getName()))

{

found = true;

count++;

}

}

}

}

else if(user == 2)

{

System.out.print(\"What color is the flower you would like to search for? \");

input.nextLine();

strUser = input.nextLine();

for(int x = 0; x < flowerPack.length; x++)

{

if(flowerPack[x] != null)

{

if(strUser.equalsIgnoreCase(flowerPack[x].getColor()))

{

found = true;

count++;

}

}

}

}

else if(user == 3)

{

System.out.print(\"Would you like to search for flowers with or without thorns?\ 1: WITH thorns\ 2: WITHOUT thorns\ \");

input.nextLine();

intUser = input.nextInt();

if(intUser == 1)

{

for(int x = 0; x

{

if(flowerPack[x] != null)

{

if(flowerPack[x].hasThorns() == true)

{

found = true;

count++;

}

}

}

}

else if(intUser == 2)

{

for(int x = 0; x

{

if(flowerPack[x] != null)

{

if(flowerPack[x].hasThorns() == false)

{

found = true;

count++;

}

}

}

}

else

System.out.println(\"Invalid search terminated\");

}

else if(user == 4)

{

System.out.print(\"Would you like to search for flowers with or without smell?\ 1: WITH smell\ 2: WITHOUT smell\ \");

input.nextLine();

intUser = input.nextInt();

if(intUser == 1)

{

for(int x = 0; x

{

if(flowerPack[x] != null)

{

if(flowerPack[x].hasSmell() == true)

{

found = true;

count++;

}

}

}

}

else if(intUser == 2)

{

for(int x = 0; x

{

if(flowerPack[x] != null)

{

if(flowerPack[x].hasSmell() == false)

{

found = true;

count++;

}

}

}

}

else

System.out.println(\"Invalid search terminated\");

}

else

{

System.out.println(\"Invalid search terminated\");

}

if(found)

{

System.out.println(\"We have found \" +count+ \" flowers that match your search\");

System.out.println();

System.out.println();

}

else

{

System.out.println(\"Your flower has not been found\");

System.out.println();

System.out.println();

}

}

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

* */

boolean [] checked = new boolean[flowerPack.length];

for(int x = 0; x < flowerPack.length; x++)

{

int count = 0;

if(flowerPack[x] == null)

{

break;

}

for(int j = x; j < flowerPack.length; j++)

if(flowerPack[j] != null)

if(flowerPack[j].getName().equalsIgnoreCase(flowerPack[x].getName()))

{

count ++;

if(j!=x)

checked[j] = true;

}

if(!checked[x])

System.out.println(flowerPack[x].getName()+\" - \"+count);

}

System.out.println();

}

}

package Assignment2;

public class Flower

{

private String name;

private String color;

private boolean thorns;

private boolean smell;

public Flower()

{

}

public Flower(String name, String color, boolean thorns, boolean smell)

{

this.name = name;

this.color = color;

this.thorns = thorns;

this.smell = smell;

}

public void setName(String name)

{

this.name = name;

}

public String getName()

{

return this.name;

}

public void setColor(String color)

{

this.color = color;

}

public String getColor()

{

return this.color;

}

public void setThorns(boolean thorns)

{

this.thorns = thorns;

}

public boolean hasThorns()

{

return this.thorns;

}

public void setSmell(boolean smell)

{

this.smell = smell;

}

public boolean hasSmell()

{

return this.smell;

}

public String toString()

{

return name+\" \"+color+\" \"+thorns+\" \"+smell;

}

}

Solution

public class Flower {
// Declare attributes here
private String name;
private String presenceofthorns;
private String color;
private String smell;

public Flower(){
name=\"\";   
presenceofthorns=\"\";
color=\"\";
smell=\"\";
}

// overridden constructor here
public Flower(String name, String color, String smell, String presenceofthorns){
name=name;   
presenceofthorns=presenceofthorns;
color=color;
smell=smell;
}
//Create accessors and mutators for your triats.
public String getName() { return name; }
public String getColor() { return color; }
public String getSmell() { return smell; }
public String getPresenceofthorns() { return presenceofthorns; }

public void setName(String name) { this.name = name; }
public void setColor(String color) { this.color = color; }
public void setSmell(String smell) { this.smell = smell; }
public void setPresenceofthorns(String presenceofthorns)   
{ this.presenceofthorns = presenceofthorns; }
}

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) {
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter the flower name\");
String name = scan.next();

System.out.println(\"Enter the flower Color\");
String Color=scan.next();

System.out.println(\"Enter the flower Smell\");
String Smell=scan.next();

System.out.println(\"Enter True or False if has thorns (yes/no)\");
String HasThorns=scan.next();
flowerPack.add(new Flower(name,Color,Smell, HasThorns));

  
}
private void removeFlower(ArrayList flowerPack) {
System.out.println(\"Enter the flower name\");
Scanner scan = new Scanner(System.in);
if(flowerPack.contains(scan))
flowerPack.remove();
  
}
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

}
}

After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O
After dinner with Alexander and Elizabeth we notice that Alexander is mixing some herbs as a medication for Elizabeth that eases her pain and helps her sleep. O

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site