Here is my code
import java.util.Scanner; public class Assignment2 { public static void main(String[] args) { new Assignment2(); } // This will act as our program switchboard public Assignment2() { Flower[] flowerPack = new Flower[25]; Scanner input = new Scanner(System.in); 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[]) { Scanner scan = new Scanner(System.in); Flower flowerClass = new Flower(); System.out.println(); System.out.println( " Please enter your flower type? i.e. type of flower, color, presence of thorns, smell " ); System.out.println( " Please be mindful that you may only insert 25 flower types. " ); System.out.print( " Type of flower? : "); flowerClass.setFlower(scan.next()); System.out.print( " Color? : "); flowerClass.setColorFlower(scan.next()); System.out.print( " Thorns Presented? : "); flowerClass.setThornAvailable(scan.next()); System.out.print( " Smell? : "); flowerClass.setFlowerSmell(scan.next()); for(int i = 0; i < flowerPack.length; i++) { if(flowerPack[i] == null) { flowerPack[i] = new Flower(); break; } } for(int x = 0; x < flowerPack.length; x++) if( (x + 1) % 5 == 0) { System.out.println(" " + flowerPack[x] + " "); } else { System.out.print( " " + flowerPack[x] + " "); } } private void removeFlower(Flower flowerPack[]) { Scanner scan = new Scanner(System.in); System.out.print( " Please enter a flower you would like to remove. "); String deleteflower = scan.nextLine(); int i; for(i = 0; i < flowerPack.length; i++) { if( deleteflower.equals(flowerPack[i]) ) { flowerPack[i] = null; } } } private void searchFlowers(Flower flowerPack[]) { Scanner scan = new Scanner(System.in); System.out.print( " Please enter the flower you would like to search for."); String key = scan.next(); boolean found = false; for(int y = 0; y < flowerPack.length; y++) { if( key.equals(flowerPack[y]) ) { found = true; } } if(found) { System.out.println( key + " is in the batch0 of flowers."); System.out.println(""); } else { System.out.println(" No results found."); System.out.println(""); } } private void displayFlowers(Flower flowerPack[]) { } } //Here is my class public class Flower { String flowerName; String colorFlower; String thornAvailable; String flowerSmell; Flower(){ } public void setFlower(String flower) { flowerName = flower; } public void setColorFlower(String color) { colorFlower = color; } public void setThornAvailable(String thorn) { thornAvailable = thorn; } public void setFlowerSmell(String smell ) { flowerSmell= smell; } public String getFlower() { return flowerName; } public String getcolor() { return colorFlower; } public String getthorn() { return thornAvailable; } public String getsmell() { return flowerSmell; } }
Here is my output.
1: Add an item to the pack.
2: Remove an item from the pack.
3: Search for a flower.
4: Display the flowers in the pack.
0: Exit the flower pack interfact.
1
Please enter your flower type? i.e. type of flower, color, presence of thorns, smell
Please be mindful that you may only insert 25 flower types.
Type of flower? : rose
Color? : rose
Thorns Presented? : yes
Smell? : no
Flower@35bab2 null null null null
null null null null null
null null null null null
null null null null null
null null null null null
1: Add an item to the pack.
2: Remove an item from the pack.
3: Search for a flower.
4: Display the flowers in the pack.
0: Exit the flower pack interfact.
I'm been working on this for awhile. I'm so tried I must have over looked something. I know it something easy. Can someone help me?