Skip to content

Commit

Permalink
Ascii Table
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffinsonDarmawan committed Apr 14, 2024
1 parent c16de10 commit a7e65bb
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 17 deletions.
85 changes: 68 additions & 17 deletions src/main/java/florizz/core/Ui.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package florizz.core;

import com.github.freva.asciitable.AsciiTable;
import com.github.freva.asciitable.Column;
import com.github.freva.asciitable.HorizontalAlign;
import florizz.objects.Bouquet;
import florizz.objects.Flower;
import florizz.objects.TableData;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;

Expand All @@ -28,7 +34,7 @@ public void printIntroMessage(){
" |_| |_|\\___/|_| |_/___/___|\n" +
"\n";
System.out.println("Hello from\n" + logo);
System.out.println("Type `help`, to view a list of valid commands!");
System.out.println("Type `help`, to view a table of valid commands!");
}

/**
Expand Down Expand Up @@ -119,25 +125,61 @@ public void printFullBouquet(Bouquet bouquet) {
}

/**
* print all available command
* print all available commands
*/
public void printHelpMessage() {
lastCommand = "OTHERS";
System.out.println("Here are the list of commands you can use:");
System.out.println("1. new <bouquetName> - Add a bouquet");
System.out.println("2. delete <bouquetName> - Delete a bouquets");
System.out.println("3. mybouquets - List current saved bouquets");
System.out.println("4. info <flowerName> - Provide information on chosen flower");
System.out.println("5. add <flowerName> /c <colour> (optional) /q <quantity> " +
"/to <bouquetName> - add flower to a bouquet");
System.out.println("6. remove <flowerName> /c <colour> (optional) /q <quantity> " +
"/from <bouquetName> - remove flower from a bouquet");
System.out.println("7. flowers - Shows a list of flowers that can be added into mybouquets");
System.out.println("8. flowers <occasion> - Shows a list of flowers associated with said occasion");
System.out.println("9. occasion - Shows a list of occasions associated with available flowers");
System.out.println("10. save <bouquetName> - Saves a bouquet to an external <bouquetName>.txt file");
System.out.println("11. recommend - Recommends a bouquet based on the chosen occasion and colour");
System.out.println("12. bye - Exits the programme");
System.out.println("Here is the table of commands you can use:");
List<TableData> tableData = Arrays.asList(
new TableData(1, "new <bouquetName>"
, "Add a bouquet"
, "new Birthday Bouquet"),
new TableData(2, "delete <bouquetName>"
, "Delete a bouquets"
, "delete Birthday Bouquet"),
new TableData(3, "mybouquets"
, "List current saved bouquets"
, "mybouquets"),
new TableData(4, "info <flowerName>"
, "Provide information on chosen flower"
, "info Rose"),
new TableData(5, "add <flowerName> /c <colour> (optional) /q <quantity> /to <bouquetName>"
, "Sdd flower to a bouquet"
, "add Rose /c Red /q 5 /to Birthday Bouquet"),
new TableData(6, "remove <flowerName> /c <colour> (optional) /q <quantity> /from <bouquetName>"
, "Remove flower from a bouquet"
, "remove Rose /c Red /q 5 /from Birthday Bouquet"),
new TableData(7, "flowers"
, "Shows a list of flowers that can be added into mybouquets"
, "flowers"),
new TableData(8, "flowers <occasion>"
, "Shows a list of flowers associated with said occasion"
, "flowers Valentines"),
new TableData(9, "occasion"
, "Shows a list of occasions associated with available flowers"
, "occasion"),
new TableData(10, "save <bouquetName>"
, "Saves a bouquet to an external <bouquetName>.txt file"
, "save Birthday Bouquet"),
new TableData(11, "recommend"
, "Recommends a bouquet based on the chosen occasion and colour"
, "recommend"),
new TableData(12, "compare <1st flowerName> /vs/ <2nd flowerName>"
, "Show information regarding two flowers side-by-side for comparison"
, "compare Rose vs Lily"),
new TableData(13, "bye"
, "Exits the programme"
, "bye")
);
System.out.println(AsciiTable.getTable(tableData, Arrays.asList(
new Column().header("No.").dataAlign(HorizontalAlign.CENTER)
.with((TableData data) -> Integer.toString(data.getId())),
new Column().header("Command").dataAlign(HorizontalAlign.LEFT).maxWidth(58)
.with(TableData::getCommand),
new Column().header("Explanation").dataAlign(HorizontalAlign.LEFT).maxWidth(40)
.with(TableData::getExplanation),
new Column().header("Example").dataAlign(HorizontalAlign.LEFT)
.with(TableData::getExample))));
printBreakLine();
}

Expand Down Expand Up @@ -487,6 +529,15 @@ public void printGetFlowerColour(ArrayList<Flower> flowers, String flowerName){
System.out.println("Type the colour you want to add into the bouquet, or 'cancel' to return to the main menu.");
}

public void printCompareFlowers(ArrayList<Flower> firstFilteredFlowers, ArrayList<Flower> secondFilteredFlowers) {
System.out.println("Here is the comparison between the two flowers:");
System.out.println("First flower: " + firstFilteredFlowers.get(0).getNameAndColour());
System.out.println("Second flower: " + secondFilteredFlowers.get(0).getNameAndColour());
System.out.println("Price: $" + firstFilteredFlowers.get(0).getPrice() + " vs $" + secondFilteredFlowers.get(0).getPrice());
System.out.println("Meanings: " + firstFilteredFlowers.get(0).getMeanings() + " vs " + secondFilteredFlowers.get(0).getMeanings());
printBreakLine();
}

/**
* Prints a message indicating that the command has been canceled and the user is returning to the main menu.
*/
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/florizz/objects/TableData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package florizz.objects;

public class TableData {
private int id;
private String command;
private String explanation;
private String example;
private String flowerName;
private String flowerOccasion;
private String flowerPrice;
private String flowerColor;
private String flowerMeaning;

public TableData(int id, String command, String explanation, String example) {
this.id = id;
this.command = command;
this.explanation = explanation;
this.example = example;
}

public TableData(String flowerName, String flowerOccasion, String flowerPrice
, String flowerColor, String flowerMeaning) {
this.flowerName = flowerName;
this.flowerOccasion = flowerOccasion;
this.flowerPrice = flowerPrice;
this.flowerColor = flowerColor;
this.flowerMeaning = flowerMeaning;
}

public int getId() {
return id;
}

public String getCommand() {
return command;
}

public String getExplanation() {
return explanation;
}

public String getExample() {
return example;
}
}

0 comments on commit a7e65bb

Please sign in to comment.