Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2324S2#19 from Ijaaz01/MohamedIjaaz-F…
Browse files Browse the repository at this point in the history
…lowerCommand

Add flower command and flower dictionary
  • Loading branch information
Ijaaz01 authored Mar 17, 2024
2 parents 9316550 + bed65cc commit b586916
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/florizz/command/FlowerCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package florizz.command;

import florizz.core.FlorizzException;
import florizz.core.Ui;
import florizz.objects.Bouquet;

import java.util.ArrayList;

public class FlowerCommand extends Command{
private String occasion;

public FlowerCommand(String occasion) {
this.occasion = occasion;
}

@Override
public boolean execute(ArrayList<Bouquet> bouquetList, Ui ui) throws FlorizzException {
if (occasion.isBlank()) {
ui.printAllDictFlowerName();
} else {
ui.printOccasionFlower(occasion);
}
return true;
}
}
2 changes: 2 additions & 0 deletions src/main/java/florizz/core/Florizz.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class Florizz {
* Main entry-point for the java.florizz.core.Florizz application.
*/
public static void main(String[] args) {
// Adds flowers to the dict (temporary use)
FlowerDictionary.startup();
ArrayList<Bouquet> tempBouquetList = new ArrayList<>();
boolean isRunning = true;
Ui ui = new Ui();
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/florizz/core/FlowerDictionary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package florizz.core;

import java.util.ArrayList;
import florizz.objects.Flower;

/**
* A class that contains a dictionary of preset flowers
*/
public class FlowerDictionary {
private static ArrayList<Flower> flowerDict = new ArrayList<Flower>();

/**
* Adds a new flower to the flower dictionary
*
* @param name Name of flower to be added
* @param colour Colour of flower to be added
* @param occasion Occasion that the flower is bought for
*/
public static void add(String name, String colour, String occasion) {
flowerDict.add(new Flower(name, colour, occasion));
}

/**
* Adds flowers to the dictionary when florizz starts up (temporary)
*/
public static void startup() {
add("Orchid", "White", "Wedding");
add("Rose", "Red", "Valentines");
add("Lily", "White", "Funeral");
add("Daisy", "White", "Valentines");
add("Babys Breath", "White", "Wedding");
add("Chrysanthemum", "White", "Funeral");
}

/**
* Returns the size of flower dictionary
*
* @return The size as an int
*/
public static int size() {
return flowerDict.size();
}

/**
* Gets the flower at the selected index in the flower dictionary
*
* @param i Index to get flower from
* @return The flower object at index i
*/
public static Flower get(int i) {
return flowerDict.get(i);
}
}
7 changes: 7 additions & 0 deletions src/main/java/florizz/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static Command parse (String input) throws FlorizzException{
return new ExitCommand();
case ("help"):
return new HelpCommand();
case ("flower"):
return handleFlowerCommand(input);
default:
throw new FlorizzException("Unidentified input, type help to get a list of all commands!");
}
Expand All @@ -31,4 +33,9 @@ private static DeleteBouquetCommand handleDeleteBouquet(String input){
return new DeleteBouquetCommand(new Bouquet(bouquetToDelete));
}

private static FlowerCommand handleFlowerCommand(String input) {
String occasion = (input.length() == 6) ? " " : input.substring(input.indexOf(" ") + 1);
return new FlowerCommand(occasion);
}

}
16 changes: 16 additions & 0 deletions src/main/java/florizz/core/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,21 @@ public void printExitMessage() {
printBreakLine();
}

public void printAllDictFlowerName() {
System.out.println("Here are all te flowers you can add: ");
for (int i = 0; i < FlowerDictionary.size(); i++) {
System.out.println(FlowerDictionary.get(i).getFlowerName());
}
printBreakLine();
}

public void printOccasionFlower(String targetOccasion) {
System.out.println("Here are all the flowers related to " + targetOccasion.toLowerCase() + ": ");
for (int i = 0; i < FlowerDictionary.size(); i++) {
if (FlowerDictionary.get(i).getOccasion().equalsIgnoreCase(targetOccasion)) {
System.out.println(FlowerDictionary.get(i).getFlowerName());
}
}
printBreakLine();
}
}
4 changes: 4 additions & 0 deletions src/main/java/florizz/objects/Flower.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public String getFlowerName() {
return name;
}

public String getOccasion() {
return occasion;
}

@Override
public String toString() {
return ("Name: " + name + "\n" + "Colour: " + colour + "\n" + "Occasion: " + occasion + "\n");
Expand Down

0 comments on commit b586916

Please sign in to comment.