diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 7a4bf35..4f08829 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -6,6 +6,7 @@
+
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 43c1af2..4f5f0e1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,6 +2,7 @@
+
4.0.0
io.zipcodewilmington
@@ -21,5 +22,23 @@
-
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.4.2
+ test
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.10.1
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.4.2
+ test
+
+
\ No newline at end of file
diff --git a/sneaker.json b/sneaker.json
new file mode 100644
index 0000000..0bd49d8
--- /dev/null
+++ b/sneaker.json
@@ -0,0 +1,28 @@
+[ {
+ "id" : 1,
+ "name" : "Step Daddy",
+ "brand" : "NYRP",
+ "sport" : "Casual",
+ "size" : 10.5,
+ "qty" : 39,
+ "price" : 39.99,
+ "totalPrice" : 1559.6101
+}, {
+ "id" : 2,
+ "name" : "Step Momma",
+ "brand" : "NYRP",
+ "sport" : "Casual",
+ "size" : 8.5,
+ "qty" : 28,
+ "price" : 45.99,
+ "totalPrice" : 1287.7201
+}, {
+ "id" : 3,
+ "name" : "Reebles",
+ "brand" : "Yamaha",
+ "sport" : "Standing Still",
+ "size" : 10.5,
+ "qty" : 15,
+ "price" : 34.99,
+ "totalPrice" : 524.85004
+} ]
\ No newline at end of file
diff --git a/src/main/java/io/App.java b/src/main/java/io/App.java
new file mode 100644
index 0000000..89241ca
--- /dev/null
+++ b/src/main/java/io/App.java
@@ -0,0 +1,32 @@
+package io;
+import models.Inventory;
+import models.Sneaker;
+import services.SneakerService;
+import utils.CSVUtils;
+import utils.JSONUtils;
+
+import java.io.IOException;
+import java.util.Scanner;
+
+public class App {
+
+ public static void main(String... args) throws IOException {
+ App application = new App();
+ application.init();
+ CSVUtils.writeFiles();
+ JSONUtils.writeFiles();
+ }
+
+ public void init() throws IOException {
+ // (4)
+ // application logic here
+ // call methods to take user input and interface with services
+
+ //Console.initializeSampleInventory();
+ //SneakerService.csvFileSaver();
+ //CSVUtils.loadFiles();
+ JSONUtils.readFiles();
+ Console.printWelcome();
+ Console.topMenu();
+ }
+}
diff --git a/src/main/java/io/Console.java b/src/main/java/io/Console.java
new file mode 100644
index 0000000..e782620
--- /dev/null
+++ b/src/main/java/io/Console.java
@@ -0,0 +1,324 @@
+
+package io;
+import models.Inventory;
+import models.Product;
+import models.Whiskey;
+import models.Sneaker;
+import services.SneakerService;
+import services.WhiskeyService;
+import sun.nio.ch.sctp.SctpNet;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Scanner;
+
+public class Console {
+ private static Inventory inventory = new Inventory();
+ private static DecimalFormat decimalFormatter = new DecimalFormat("0.00");
+
+ public static void initializeSampleInventory(){
+ SneakerService sneakerService = inventory.getSneakerService();
+ WhiskeyService whiskeyService = inventory.getWhiskeyService();
+
+ sneakerService.create("Step Daddy", "NYRP", "Casual", 10.5f, 39, 39.99f);
+ sneakerService.create("Step Momma", "NYRP", "Casual", 8.5f, 28, 45.99f);
+ sneakerService.create("Reebles", "Yamaha", "Standing Still", 10.5f, 15, 34.99f);
+
+ whiskeyService.create("Jawn Juice", "NoDrive", 45, 50.0f, 125, 45.50f);
+ whiskeyService.create("Ewwater", "Bad Taste", 45, 45.7f, 99, 55.50f);
+ whiskeyService.create("Foolaid", "Krunk Bvg Co", 60, 80.00f, 22, 89.95f);
+ }
+
+ public static void print(String input){
+ System.out.println(input);
+ }
+ public static void printWelcome(){
+ System.out.println("" +
+ "**************************************************\n" +
+ "*** Welcome and Bienvenue ***\n" +
+ "*** to ***\n" +
+ "*** ZipCo Inventory Manager ***\n" +
+ "**************************************************");
+ }
+
+ public static void topMenu(){
+ Scanner scanner = new Scanner(System.in);
+ Integer input;
+ print("Choose a menu option (select using the option's menu number)");
+ print("Enter any other number/letter to exit program");
+ print("1. Inventory Report");
+ print("2. Edit Inventory");
+ print("3. Delete Product");
+ input = scanner.nextInt();
+
+ switch(input){
+ case 1: // Select Inventory Report
+ inventoryReportMenu();
+ break;
+
+ case 2:
+ editInventoryMenu();
+ break;
+ case 3:
+ deleteInventoryMenu();
+ default:
+ print("Exiting program");
+ }
+
+ }
+
+ public static void inventoryReportMenu(){
+ Scanner scanner = new Scanner(System.in);
+ Integer input;
+ print("Select report to generate");
+ print("1. Sneaker");
+ print("2. Whiskey");
+ print("3. All Products");
+ print("4. Go Back to Top Menu");
+
+ input = scanner.nextInt();
+ if(input >= 4){
+ topMenu();
+ } else {
+ inventoryReportOptions(input);
+ }
+ }
+
+ public static void printInventoryMenu(){
+ print("Select a Category to edit");
+ print("1. Sneakers");
+ print("2. Whiskey");
+ print("3. Return to previous menu");
+ }
+
+ public static void editInventoryMenu(){
+ Scanner scanner = new Scanner(System.in);
+ Integer input;
+ printInventoryMenu();
+ input = scanner.nextInt();
+ switch (input){
+ case 1:
+ selectSneakerMenu();
+ break;
+ case 2:
+ selectWhiskeyMenu();
+ break;
+ case 3:
+ default:
+ topMenu();
+ }
+ }
+
+ public static void inventoryReportOptions(Integer option){
+ switch(option){
+ case 1:
+ printList(inventory.getSneakerService().findAll());
+ break;
+ case 2:
+ printList(inventory.getWhiskeyService().findAll());
+ break;
+ case 3:
+ printList(inventory.getAllProductsArrayList());
+ }
+ inventoryReportMenu();
+ }
+
+ public static void selectSneakerMenu(){
+ print("Select product to edit");
+ Sneaker[] sneakerList = inventory.getSneakerService().findAll();
+ printList(sneakerList);
+ Scanner scanner = new Scanner(System.in);
+ Integer menuSelection = scanner.nextInt();
+ editSneakerMenu(sneakerList[menuSelection - 1]);
+ }
+
+ public static void selectWhiskeyMenu(){
+ print("Select product to edit");
+ Whiskey[] whiskeyList = inventory.getWhiskeyService().findAll();
+ printList(whiskeyList);
+ Scanner scanner = new Scanner(System.in);
+ Integer menuSelection = scanner.nextInt();
+ editWhiskeyMenu(whiskeyList[menuSelection - 1]);
+ }
+
+ public static void printCommonPropertyOptions(){
+ print("Select menu option number to edit property");
+ print("1: Name");
+ print("2: Brand");
+ print("3: Size");
+ print("4: Price");
+ print("5: Quantity");
+ }
+
+ public static void editSneakerMenu(Sneaker sneaker){
+ Scanner scanner = new Scanner(System.in);
+ Integer menuSelectionNumber;
+ Integer integerInput;
+ String stringInput;
+ Float floatInput;
+ print("Selected: " + sneaker.toString());
+ printCommonPropertyOptions();
+ print("6: Sport");
+ print("7: Previous menu");
+ menuSelectionNumber = scanner.nextInt();
+ switch (menuSelectionNumber){
+ case 1: //Name
+ print("Enter new name for product");
+ scanner.nextLine();
+ stringInput = scanner.nextLine();
+ sneaker.setName(stringInput);
+ editSneakerMenu(sneaker);
+ break;
+ case 2: //Brand
+ print ("Enter new brand name for product");
+ scanner.nextLine();
+ stringInput = scanner.nextLine();
+ sneaker.setBrand(stringInput);
+ editSneakerMenu(sneaker);
+ break;
+ case 3: //Size
+ print ("Enter new size for product");
+ scanner.nextLine();
+ floatInput = scanner.nextFloat();
+ sneaker.setSize(floatInput);
+ editSneakerMenu(sneaker);
+ case 4: //Price
+ print ("Enter new price for product");
+ scanner.nextLine();
+ floatInput = scanner.nextFloat();
+ sneaker.setPrice(floatInput);
+ editSneakerMenu(sneaker);
+ case 5: //Quantity
+ print ("Enter new quantity for product");
+ scanner.nextLine();
+ integerInput = scanner.nextInt();
+ sneaker.setQty(integerInput);
+ editSneakerMenu(sneaker);
+ case 6: //
+ print ("Enter new Sport for product");
+ scanner.nextLine();
+ stringInput = scanner.nextLine();
+ sneaker.setSport(stringInput);
+ editSneakerMenu(sneaker);
+ default: //Input 7 or any number not listed above
+ editInventoryMenu();
+ }
+ }
+
+ public static void editWhiskeyMenu(Whiskey whiskey){
+ Scanner scanner = new Scanner(System.in);
+ Integer menuSelectionNumber;
+ Integer integerInput;
+ String stringInput;
+ Float floatInput;
+ print("Selected: " + whiskey.toString());
+ printCommonPropertyOptions();
+ print("6: Proof");
+ print("7: Previous menu");
+ menuSelectionNumber = scanner.nextInt();
+ switch (menuSelectionNumber){
+ case 1: //Name
+ print("Enter new name for product");
+ scanner.nextLine();
+ stringInput = scanner.nextLine();
+ whiskey.setName(stringInput);
+ editWhiskeyMenu(whiskey);
+ break;
+ case 2: //Brand
+ print ("Enter new brand name for product");
+ scanner.nextLine();
+ stringInput = scanner.nextLine();
+ whiskey.setBrand(stringInput);
+ editWhiskeyMenu(whiskey);
+ break;
+ case 3: //Size
+ print ("Enter new size for product");
+ scanner.nextLine();
+ floatInput = scanner.nextFloat();
+ whiskey.setSize(floatInput);
+ editWhiskeyMenu(whiskey);
+ case 4: //Price
+ print ("Enter new price for product");
+ scanner.nextLine();
+ floatInput = scanner.nextFloat();
+ whiskey.setPrice(floatInput);
+ editWhiskeyMenu(whiskey);
+ case 5: //Quantity
+ print ("Enter new quantity for product");
+ scanner.nextLine();
+ integerInput = scanner.nextInt();
+ whiskey.setQty(integerInput);
+ editWhiskeyMenu(whiskey);
+ case 6: //
+ print ("Enter new Proof for product");
+ scanner.nextLine();
+ integerInput = scanner.nextInt();
+ whiskey.setProof(integerInput);
+ editWhiskeyMenu(whiskey);
+ default: //Input 7 or any number not listed above
+ editInventoryMenu();
+ }
+ }
+
+ public static void deleteInventoryMenu(){
+ Scanner scanner = new Scanner(System.in);
+ Integer input;
+ print("Select Category to delete from");
+ print("1: Sneakers");
+ print("2: Whiskey");
+ print("3: Return to previous menu");
+ input = scanner.nextInt();
+ Product[] productList;
+ switch(input){
+ case 1:
+ productList = inventory.getSneakerService().findAll();
+ deleteProductMenu(productList);
+ case 2:
+ productList = inventory.getWhiskeyService().findAll();
+ deleteProductMenu(productList);
+ default: //Input 3 or any number not listed above
+ topMenu();
+ }
+
+ }
+
+ public static void deleteProductMenu(Product[] productList){
+ Scanner scanner = new Scanner(System.in);
+ Integer input;
+ print("Select product to delete");
+ print("AT LEAST ONE PRODUCT OF EACH CATEGORY MUST REMAIN. THIS IS A BUSINESS, PEOPLE");
+ print("0: Return to previous menu");
+
+ if(productList.length < 2)
+ topMenu();
+
+ printList(productList);
+ input = scanner.nextInt();
+ if(input == 0){
+ deleteInventoryMenu();
+ } else {
+ --input;
+ input = input < productList.length ? input : productList.length -1;
+ if(productList[input] instanceof Sneaker){
+ inventory.getSneakerService().delete(productList[input].getId());
+ } else {
+ inventory.getWhiskeyService().delete(productList[input].getId());
+ }
+ deleteInventoryMenu();
+ }
+
+ }
+
+ public static void printList(Product[] list){
+ ArrayList aList = new ArrayList<>(Arrays.asList(list));
+ String productType = "";
+ Integer listNumber = 0;
+ for(Product element: aList){
+ String price = decimalFormatter.format(element.getTotalPrice());
+ productType = element instanceof Whiskey ? "Whiskey: " : "Sneaker: ";
+ print(++listNumber + ": " + productType + element.getName() + " qty:" + element.getQty() + " total $" + price);
+ }
+ }
+
+}
diff --git a/src/main/java/models/Inventory.java b/src/main/java/models/Inventory.java
new file mode 100644
index 0000000..b282f9c
--- /dev/null
+++ b/src/main/java/models/Inventory.java
@@ -0,0 +1,85 @@
+package models;
+
+import services.SneakerService;
+import services.WhiskeyService;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+
+public class Inventory {
+ private SneakerService sneakerService = new SneakerService();
+ private WhiskeyService whiskeyService = new WhiskeyService();
+/*Method to return the total number of Sneakers in Inventory
+Method to return the total number of Whiskeys in Inventory
+Method to return the sum of both
+Method to return total $ amount of Sneakers, total $ amount of Whiskey, and the overall total
+*/
+ public SneakerService getSneakerService(){
+ return this.sneakerService;
+ }
+
+ public WhiskeyService getWhiskeyService(){
+ return this.whiskeyService;
+ }
+ public Integer sneakersInStock(){
+ Sneaker[] allSneakers = this.sneakerService.findAll();
+ Integer count = 0;
+
+ for(Sneaker element: allSneakers){
+ count += element.getQty();
+ }
+ return count;
+ }
+
+ public Integer whiskeyInStock(){
+ Whiskey[] allWhiskey = this.whiskeyService.findAll();
+ Integer count = 0;
+
+ for(Whiskey element: allWhiskey){
+ count += element.getQty();
+ }
+ return count;
+ }
+
+ public Integer totalItemsInStock(){
+ return this.sneakersInStock() + this.whiskeyInStock();
+ }
+
+ public Float totalSneakersValue(){
+ Sneaker[] allSneakers = this.sneakerService.findAll();
+ Float totalValue = 0.00f;
+ for(Sneaker element: allSneakers){
+ totalValue += element.getPrice() * element.getQty();
+ }
+
+ return totalValue;
+ }
+
+ public Float totalWhiskeyValue(){
+ Whiskey[] allWhiskey = this.whiskeyService.findAll();
+ Float totalValue = 0.00f;
+ for(Whiskey element: allWhiskey){
+ totalValue += element.getPrice() * element.getQty();
+ }
+
+ return totalValue;
+ }
+
+ public Float totalInventoryValue(){
+ return totalSneakersValue() + totalWhiskeyValue();
+ }
+
+ public Product[] getAllProductsArrayList(){
+ ArrayList masterList = new ArrayList<>();
+ Sneaker[] sneakerList = sneakerService.findAll();
+ Whiskey[] whiskeyList = whiskeyService.findAll();
+
+ for(Product element: sneakerList)
+ masterList.add(element);
+
+ for(Product element: whiskeyList)
+ masterList.add(element);
+
+ return masterList.toArray(new Product[0]);
+ }
+}
diff --git a/src/main/java/models/Product.java b/src/main/java/models/Product.java
new file mode 100644
index 0000000..22403c8
--- /dev/null
+++ b/src/main/java/models/Product.java
@@ -0,0 +1,16 @@
+package models;
+
+public interface Product {
+ public String getName();
+ public void setName(String name);
+ public Float getPrice();
+ public void setPrice(Float name);
+ public Float getTotalPrice();
+ public int getQty();
+ public void setQty(int quantity);
+ public String getBrand();
+ public void setBrand(String name);
+ public int getId();
+ public Float getSize();
+ public void setSize(Float size);
+}
diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java
new file mode 100644
index 0000000..c256e40
--- /dev/null
+++ b/src/main/java/models/Sneaker.java
@@ -0,0 +1,103 @@
+package models;
+
+import utils.CSVUtils;
+
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class Sneaker implements Product {
+ private int id;
+ private String name;
+ private String brand;
+ private String sport;
+ private float size;
+ private int qty;
+ private float price;
+
+
+ public Sneaker(int id, String name, String brand, String sport, float size, int qty, float price) {
+ this.id = id;
+ this.name = name;
+ this.brand = brand;
+ this.sport = sport;
+ this.qty = qty;
+ this.price = price;
+ this.size = size;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getBrand() {
+ return brand;
+ }
+
+ public void setBrand(String brand) {
+ this.brand = brand;
+ }
+
+ public String getSport() {
+ return sport;
+ }
+
+ public void setSport(String sport) {
+ this.sport = sport;
+ }
+
+ public Float getSize() {
+ return size;
+ }
+
+ public void setSize(Float size) {
+ this.size = size;
+ }
+
+ public int getQty() {
+ return qty;
+ }
+
+ public void setQty(int qty) {
+ this.qty = qty;
+ }
+
+ public Float getPrice() {
+ return price;
+ }
+
+ public Float getTotalPrice(){
+ return getQty() * getPrice();
+ }
+
+ public void setPrice(Float price) {
+ this.price = price;
+ }
+
+ @Override
+ public String toString(){
+ String readout = "Name:" + getName();
+ readout += " Brand:" + getBrand();
+ readout += " Sport:" + getSport();
+ readout += " Size:" + getSize();
+ readout += " Price:$" + getPrice();
+ readout += " Quantity:" + getQty();
+
+ return readout;
+ }
+
+
+}
diff --git a/src/main/java/models/Whiskey.java b/src/main/java/models/Whiskey.java
new file mode 100644
index 0000000..87049c6
--- /dev/null
+++ b/src/main/java/models/Whiskey.java
@@ -0,0 +1,93 @@
+package models;
+
+public class Whiskey implements Product{
+ private int id;
+ private String name;
+ private String brand;
+ private int proof;
+ private Float size;
+ private int qty;
+ private Float price;
+
+ public Whiskey(int id, String name, String brand, int proof, Float size, int qty, Float price){
+ this.id = id;
+ this.name = name;
+ this.brand = brand;
+ this.proof = proof;
+ this.size = size;
+ this.qty = qty;
+ this.price = price;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getBrand() {
+ return brand;
+ }
+
+ public void setBrand(String brand) {
+ this.brand = brand;
+ }
+
+ public int getProof() {
+ return proof;
+ }
+
+ public void setProof(int proof) {
+ this.proof = proof;
+ }
+
+ public Float getSize() {
+ return size;
+ }
+
+ public void setSize(Float size) {
+ this.size = size;
+ }
+
+ public int getQty() {
+ return qty;
+ }
+
+ public void setQty(int qty) {
+ this.qty = qty;
+ }
+
+ public Float getPrice() {
+ return price;
+ }
+
+ public Float getTotalPrice(){
+ return getPrice() * getQty();
+ }
+
+ public void setPrice(Float price) {
+ this.price = price;
+ }
+
+ @Override
+ public String toString(){
+ String readout = "Name:" + getName();
+ readout += " Brand:" + getBrand();
+ readout += " Proof:" + getProof();
+ readout += " Size:" + getSize();
+ readout += " Price:$" + getPrice();
+ readout += " Quantity:" + getQty();
+
+ return readout;
+ }
+}
diff --git a/src/main/java/services/SneakerService.java b/src/main/java/services/SneakerService.java
new file mode 100644
index 0000000..0bd4d00
--- /dev/null
+++ b/src/main/java/services/SneakerService.java
@@ -0,0 +1,120 @@
+package services;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.sun.deploy.net.MessageHeader;
+import models.Sneaker;
+import utils.CSVUtils;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class SneakerService {
+ private static int nextId = 1; // (1)
+ private static List inventory = new ArrayList<>();
+ public Sneaker create(String name, String brand, String sport, float size, int quantity, float price) {
+ Sneaker createdSneaker = new Sneaker(nextId++, name, brand, sport, size, quantity, price);
+ inventory.add(createdSneaker);
+ return createdSneaker;
+ }
+ //read
+ public Sneaker findSneaker(int id) {
+ // should take an int and return an object with that id, if exists
+ for(Sneaker element : inventory){
+ if(element.getId() == id){
+ return element;
+ }
+ }
+ return null;
+ }
+
+ //read all
+ public Sneaker[] findAll() {
+ // should return a basic array copy of the ArrayList
+ return inventory.toArray(new Sneaker[0]);
+ }
+
+ //delete
+ public boolean delete(int id) {
+ // should remove the object with this id from the ArrayList if exists and return true.
+ // Otherwise return false
+ for(Sneaker element: inventory){
+ if(element.getId() == id){
+ inventory.remove(element);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static void csvFileSaver() throws IOException {
+ String csvFile = "/Users/zach/Desktop/Sneaker.csv";
+ FileWriter writer = new FileWriter(csvFile);
+
+ CSVUtils.writeLine(writer, new ArrayList(Arrays.asList(String.valueOf(nextId)))); // (2)
+
+ for (Sneaker s : inventory) {
+ List list = new ArrayList<>();
+ list.add(String.valueOf(s.getId()));
+ list.add(s.getName());
+ list.add(s.getBrand());
+ list.add(s.getSport());
+ list.add(String.valueOf(s.getSize()));
+ list.add(String.valueOf(s.getQty()));
+ list.add(String.valueOf(s.getPrice()));
+
+ CSVUtils.writeLine(writer, list);
+ }
+
+
+ writer.flush();
+ writer.close();
+ }
+
+ public static void loadData(){
+ // (1)
+ String csvFile = "/Users/zach/Desktop/Sneaker.csv";
+ String line = "";
+ String csvSplitBy = ",";
+
+ // (2)
+ try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
+ nextId = Integer.parseInt(br.readLine()); // (3)
+
+ while ((line = br.readLine()) != null) {
+ // split line with comma
+ String[] beer = line.split(csvSplitBy);
+
+ // (4)
+ int id = Integer.parseInt(beer[0]);
+ String name = beer[1];
+ String brand = beer[2];
+ String sport = beer[3];
+ float size = Float.parseFloat(beer[4]);
+ int qty = Integer.parseInt(beer[5]);
+ float price = Float.parseFloat(beer[6]);
+
+ // (5)
+ inventory.add(new Sneaker(id, name, brand, sport, size, qty, price));
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void writeJSON() throws IOException {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
+ writer.writeValue(new File("sneaker.json"), inventory);
+ }
+
+ public static void readJSON() throws IOException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ inventory = objectMapper.readValue(new File("sneaker.json"), new TypeReference>(){});
+
+ }
+}
diff --git a/src/main/java/services/WhiskeyService.java b/src/main/java/services/WhiskeyService.java
new file mode 100644
index 0000000..73c495f
--- /dev/null
+++ b/src/main/java/services/WhiskeyService.java
@@ -0,0 +1,115 @@
+package services;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import models.Sneaker;
+import models.Whiskey;
+import utils.CSVUtils;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class WhiskeyService {
+ private static int nextId = 1;
+ private static List inventory = new ArrayList<>();
+ public Whiskey create(String name, String brand, int proof, float size, int quantity, float price) {
+ Whiskey createdWhiskey = new Whiskey(nextId++, name, brand, proof, size, quantity, price);
+ inventory.add(createdWhiskey);
+ return createdWhiskey;
+ }
+
+ public Whiskey findWhiskey(int id) {
+ for(Whiskey element : inventory){
+ if(element.getId() == id){
+ return element;
+ }
+ }
+ return null;
+ }
+
+ public Whiskey[] findAll() {
+ // should return a basic array copy of the ArrayList
+ return inventory.toArray(new Whiskey[0]);
+ }
+
+ public boolean delete(int id) {
+ for(Whiskey element: inventory){
+ if(element.getId() == id){
+ inventory.remove(element);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static void csvFileSaver() throws IOException {
+ String csvFile = "/Users/zach/Desktop/Whiskey.csv";
+ FileWriter writer = new FileWriter(csvFile);
+
+ CSVUtils.writeLine(writer, new ArrayList(Arrays.asList(String.valueOf(nextId)))); // (2)
+
+ for (Whiskey s : inventory) {
+ List list = new ArrayList<>();
+ list.add(String.valueOf(s.getId()));
+ list.add(s.getName());
+ list.add(s.getBrand());
+ list.add(String.valueOf(s.getProof()));
+ list.add(String.valueOf(s.getSize()));
+ list.add(String.valueOf(s.getQty()));
+ list.add(String.valueOf(s.getPrice()));
+
+ CSVUtils.writeLine(writer, list);
+ }
+
+
+ writer.flush();
+ writer.close();
+ }
+
+ public static void loadData(){
+ // (1)
+ String csvFile = "/Users/zach/Desktop/Whiskey.csv";
+ String line = "";
+ String csvSplitBy = ",";
+
+ // (2)
+ try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
+ nextId = Integer.parseInt(br.readLine()); // (3)
+
+ while ((line = br.readLine()) != null) {
+ // split line with comma
+ String[] beer = line.split(csvSplitBy);
+
+ // (4)
+ int id = Integer.parseInt(beer[0]);
+ String name = beer[1];
+ String brand = beer[2];
+ int proof = Integer.parseInt(beer[3]);
+ float size = Float.parseFloat(beer[4]);
+ int qty = Integer.parseInt(beer[5]);
+ float price = Float.parseFloat(beer[6]);
+
+ // (5)
+ inventory.add(new Whiskey(id, name, brand, proof, size, qty, price));
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void writeJSON() throws IOException {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
+ writer.writeValue(new File("whiskey.json"), inventory);
+ }
+
+ public static void readJSON() throws IOException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ inventory = objectMapper.readValue(new File("sneaker.json"), new TypeReference>(){});
+
+ }
+}
diff --git a/src/main/java/utils/CSVUtils.java b/src/main/java/utils/CSVUtils.java
new file mode 100644
index 0000000..bee4bf9
--- /dev/null
+++ b/src/main/java/utils/CSVUtils.java
@@ -0,0 +1,42 @@
+package utils;
+
+import models.Sneaker;
+import services.SneakerService;
+import services.WhiskeyService;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
+public class CSVUtils {
+ private static final char DEFAULT_SEPARATOR = ','; // (1)
+
+ // (2)
+ public static void writeLine(Writer w, List values) throws IOException {
+ boolean first = true;
+
+ StringBuilder sb = new StringBuilder();
+
+ // (3)
+ for (String value : values) {
+ if (!first) {
+ sb.append(DEFAULT_SEPARATOR);
+ }
+ sb.append(value);
+ first = false;
+ }
+ sb.append("\n");
+
+ w.append(sb.toString()); // (4)
+ }
+
+ public static void writeFiles() throws IOException {
+ SneakerService.csvFileSaver();
+ WhiskeyService.csvFileSaver();
+ }
+
+ public static void loadFiles(){
+ SneakerService.loadData();
+ WhiskeyService.loadData();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/utils/JSONUtils.java b/src/main/java/utils/JSONUtils.java
new file mode 100644
index 0000000..80bb7ea
--- /dev/null
+++ b/src/main/java/utils/JSONUtils.java
@@ -0,0 +1,18 @@
+package utils;
+
+import services.SneakerService;
+import services.WhiskeyService;
+
+import java.io.IOException;
+
+public class JSONUtils {
+ public static void writeFiles() throws IOException {
+ SneakerService.writeJSON();
+ WhiskeyService.writeJSON();
+ }
+
+ public static void readFiles() throws IOException {
+ SneakerService.readJSON();
+ WhiskeyService.readJSON();
+ }
+}
diff --git a/src/test/java/models/InventoryTest.java b/src/test/java/models/InventoryTest.java
new file mode 100644
index 0000000..4a6feb8
--- /dev/null
+++ b/src/test/java/models/InventoryTest.java
@@ -0,0 +1,119 @@
+package models;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import services.SneakerService;
+import services.WhiskeyService;
+
+public class InventoryTest {
+ @Test
+ public void totalSneakersTest(){
+ Inventory inventory = new Inventory();
+ SneakerService sneakerService = inventory.getSneakerService();
+
+ Sneaker testSneaker = sneakerService.create("These Jawns", "JawnEx", "Jawning",
+ 20.5f, 12, 400.12f);
+ Sneaker testSneaker2 = sneakerService.create("Them Kicks", "Footstank", "Cripwalking",
+ 5.0f, 200, 199.99f);
+
+ Integer expected = 212;
+
+ Integer actual = inventory.sneakersInStock();
+
+ Assertions.assertEquals(actual, expected);
+ }
+
+ @Test
+ public void totalWhiskeyTest(){
+ Inventory inventory = new Inventory();
+ WhiskeyService whiskeyService = inventory.getWhiskeyService();
+
+ Whiskey testWhiskey = whiskeyService.create("Ewww Juice", "Get Help", 50,
+ 20.5f, 125, 100.00f);
+ Whiskey testWhiskey2 = whiskeyService.create("Gross Water", "Insolent Quail", 45,
+ 5.0f, 200, 199.99f);
+
+ Integer expected = 325;
+ Integer actual = inventory.whiskeyInStock();
+
+ Assertions.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void totalStockTest(){
+ Inventory inventory = new Inventory();
+ SneakerService sneakerService = inventory.getSneakerService();
+ WhiskeyService whiskeyService = inventory.getWhiskeyService();
+
+ Sneaker testSneaker = sneakerService.create("These Jawns", "JawnEx", "Jawning",
+ 20.5f, 12, 400.12f);
+ Sneaker testSneaker2 = sneakerService.create("Them Kicks", "Footstank", "Cripwalking",
+ 5.0f, 200, 199.99f);
+
+ Whiskey testWhiskey = whiskeyService.create("Ewww Juice", "Get Help", 50,
+ 20.5f, 125, 100.00f);
+ Whiskey testWhiskey2 = whiskeyService.create("Gross Water", "Insolent Quail", 45,
+ 5.0f, 200, 199.99f);
+
+ Integer expected = 537;
+
+ Integer actual = inventory.totalItemsInStock();
+
+ Assertions.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void totalSneakersValueTest(){
+ Inventory inventory = new Inventory();
+ SneakerService sneakerService = inventory.getSneakerService();
+
+ Sneaker testSneaker = sneakerService.create("These Jawns", "JawnEx", "Jawning",
+ 20.5f, 12, 400.12f);
+ Sneaker testSneaker2 = sneakerService.create("Them Kicks", "Footstank", "Cripwalking",
+ 5.0f, 200, 199.99f);
+
+ Float expected = 44799.44f;
+
+ Float actual = inventory.totalSneakersValue();
+
+ Assertions.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void totalWhiskeyValueTest(){
+ Inventory inventory = new Inventory();
+ WhiskeyService whiskeyService = inventory.getWhiskeyService();
+
+ Whiskey testWhiskey = whiskeyService.create("Ewww Juice", "Get Help", 50,
+ 20.5f, 125, 100.00f);
+ Whiskey testWhiskey2 = whiskeyService.create("Gross Water", "Insolent Quail", 45,
+ 5.0f, 200, 199.99f);
+
+ Float expected = 52498.00f;
+ Float actual = inventory.totalWhiskeyValue();
+
+ Assertions.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void totalInventoryValueTest(){
+ Inventory inventory = new Inventory();
+ SneakerService sneakerService = inventory.getSneakerService();
+ WhiskeyService whiskeyService = inventory.getWhiskeyService();
+
+ Sneaker testSneaker = sneakerService.create("These Jawns", "JawnEx", "Jawning",
+ 20.5f, 12, 400.12f);
+ Sneaker testSneaker2 = sneakerService.create("Them Kicks", "Footstank", "Cripwalking",
+ 5.0f, 200, 199.99f);
+ Whiskey testWhiskey = whiskeyService.create("Ewww Juice", "Get Help", 50,
+ 20.5f, 125, 100.00f);
+ Whiskey testWhiskey2 = whiskeyService.create("Gross Water", "Insolent Quail", 45,
+ 5.0f, 200, 199.99f);
+
+ Float expected = 97297.44f;
+
+ Float actual = inventory.totalInventoryValue();
+
+ Assertions.assertEquals(expected, actual);
+ }
+}
diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java
new file mode 100644
index 0000000..0668a2a
--- /dev/null
+++ b/src/test/java/models/SneakerTest.java
@@ -0,0 +1,33 @@
+package models;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+ public class SneakerTest {
+
+ @Test // (1)
+ public void constructorTest(){
+
+ // (2)
+ int expectedId = 6;
+ String expectedName = "Stan Smith";
+ String expectedBrand = "Adidas";
+ String expectedSport = "Tennnis";
+ int expectedQty = 10;
+ float expectedPrice = 80.00f;
+ float expectedSize = 10.5f;
+
+ // (3)
+ Sneaker testSneaker = new Sneaker(expectedId, expectedName, expectedBrand,
+ expectedSport, expectedSize, expectedQty, expectedPrice);
+
+ // (4)
+ Assertions.assertEquals(expectedId, testSneaker.getId());
+ Assertions.assertEquals(expectedName, testSneaker.getName());
+ Assertions.assertEquals(expectedBrand, testSneaker.getBrand());
+ Assertions.assertEquals(expectedSport, testSneaker.getSport());
+ Assertions.assertEquals(expectedQty, testSneaker.getQty());
+ Assertions.assertEquals(expectedPrice, testSneaker.getPrice());
+ }
+ }
+
diff --git a/src/test/java/models/WhiskeyTest.java b/src/test/java/models/WhiskeyTest.java
new file mode 100644
index 0000000..6a6e283
--- /dev/null
+++ b/src/test/java/models/WhiskeyTest.java
@@ -0,0 +1,31 @@
+package models;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class WhiskeyTest {
+ @Test // (1)
+ public void constructorTest(){
+
+ // (2)
+ int expectedId = 6;
+ String expectedName = "Occifer";
+ String expectedBrand = "GitLit Inc";
+ int expectedQty = 10;
+ float expectedSize = 48.00f;
+ int expectedProof = 40;
+ float expectedPrice = 80.00f;
+
+ // (3)
+ Whiskey testWhiskey = new Whiskey(expectedId, expectedName, expectedBrand,
+ expectedProof, expectedSize, expectedQty,expectedPrice);
+
+ // (4)
+ Assertions.assertEquals(expectedId, testWhiskey.getId());
+ Assertions.assertEquals(expectedName, testWhiskey.getName());
+ Assertions.assertEquals(expectedBrand, testWhiskey.getBrand());
+ Assertions.assertEquals(expectedProof, testWhiskey.getProof());
+ Assertions.assertEquals(expectedQty, testWhiskey.getQty());
+ Assertions.assertEquals(expectedPrice, testWhiskey.getPrice());
+ }
+}
diff --git a/src/test/java/services/SneakerServiceTest.java b/src/test/java/services/SneakerServiceTest.java
new file mode 100644
index 0000000..e84cff7
--- /dev/null
+++ b/src/test/java/services/SneakerServiceTest.java
@@ -0,0 +1,90 @@
+package services;
+
+import models.Sneaker;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SneakerServiceTest {
+ @Test
+ public void createTest(){
+
+ // (1)
+ String expectedName = "Stan Smith";
+ String expectedBrand = "Adidas";
+ String expectedSport = "Tennis";
+ float expectedSize = 10.5f;
+ int expectedQty = 10;
+ float expectedPrice = 80.00f;
+
+ // (2)
+ SneakerService sneakerService = new SneakerService();
+ Sneaker testSneaker = sneakerService.create(expectedName, expectedBrand,
+ expectedSport, expectedSize, expectedQty, expectedPrice);
+
+ // (3)
+ int actualId = testSneaker.getId();
+ String actualName = testSneaker.getName();
+ String actualBrand = testSneaker.getBrand();
+ String actualSport = testSneaker.getSport();
+ double actualSize = testSneaker.getSize();
+ int actualQty = testSneaker.getQty();
+ float actualPrice = testSneaker.getPrice();
+
+ // (4)
+ Assertions.assertEquals(Integer.class.getName(), new Integer(actualId).getClass().getName());
+ Assertions.assertEquals(expectedName, actualName);
+ Assertions.assertEquals(expectedBrand, actualBrand);
+ Assertions.assertEquals(expectedSport, actualSport);
+ Assertions.assertEquals(expectedSize, actualSize);
+ Assertions.assertEquals(expectedQty, actualQty);
+ Assertions.assertEquals(expectedPrice, actualPrice);
+
+ }
+
+ @Test
+ public void findSneakerTest(){
+ SneakerService sneakerService = new SneakerService();
+ Sneaker testSneaker = sneakerService.create("La Lights", "Reebok", "BasketballAtNight",
+ 13.5f, 15, 79.99f);
+ Object expected = null;
+ Object expected2 = testSneaker;
+ Object actual = sneakerService.findSneaker(2);
+ Object actual2 = sneakerService.findSneaker(1);
+
+ Assertions.assertEquals(expected, actual);
+ Assertions.assertEquals(expected2, actual2);
+ }
+
+ @Test
+ public void findAllSneakerTest(){
+ SneakerService sneakerService = new SneakerService();
+ Sneaker testSneaker = sneakerService.create("These Jawns", "JawnEx", "Jawning",
+ 20.5f, 12, 400.12f);
+ Sneaker testSneaker2 = sneakerService.create("Them Kicks", "Footstank", "Cripwalking",
+ 5.0f, 200, 199.99f);
+
+ Sneaker[] expected = {testSneaker, testSneaker2};
+
+ Sneaker[] actual = sneakerService.findAll();
+
+ Assertions.assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteSneakerTest(){
+ SneakerService sneakerService = new SneakerService();
+ Sneaker testSneaker = sneakerService.create("These Jawns", "JawnEx", "Jawning",
+ 20.5f, 12, 400.12f);
+ Sneaker testSneaker2 = sneakerService.create("Them Kicks", "Footstank", "Cripwalking",
+ 5.0f, 200, 199.99f);
+
+ Boolean expected = true;
+ Boolean expected2 = false;
+
+ Boolean actual = sneakerService.delete(1);
+ Boolean actual2 = sneakerService.delete(5);
+
+ Assertions.assertEquals(expected, actual);
+ Assertions.assertEquals(expected2, actual2);
+ }
+}
diff --git a/src/test/java/services/WhiskeyServiceTest.java b/src/test/java/services/WhiskeyServiceTest.java
new file mode 100644
index 0000000..5343958
--- /dev/null
+++ b/src/test/java/services/WhiskeyServiceTest.java
@@ -0,0 +1,90 @@
+package services;
+
+import models.Whiskey;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class WhiskeyServiceTest {
+ @Test
+ public void createTest() {
+
+ // (1)
+ String expectedName = "Turkey Sipps";
+ String expectedBrand = "Snargaluks";
+ int expectedProof = 40;
+ float expectedSize = 18.7f;
+ int expectedQty = 10;
+ float expectedPrice = 80.00f;
+
+ // (2)
+ WhiskeyService whiskeyService = new WhiskeyService();
+ Whiskey testWhiskey = whiskeyService.create(expectedName, expectedBrand,
+ expectedProof, expectedSize, expectedQty, expectedPrice);
+
+ // (3)
+ int actualId = testWhiskey.getId();
+ String actualName = testWhiskey.getName();
+ String actualBrand = testWhiskey.getBrand();
+ int actualProof = testWhiskey.getProof();
+ double actualSize = testWhiskey.getSize();
+ int actualQty = testWhiskey.getQty();
+ float actualPrice = testWhiskey.getPrice();
+
+ // (4)
+ Assertions.assertEquals(Integer.class.getName(), new Integer(actualId).getClass().getName());
+ Assertions.assertEquals(expectedName, actualName);
+ Assertions.assertEquals(expectedBrand, actualBrand);
+ Assertions.assertEquals(expectedProof, actualProof);
+ Assertions.assertEquals(expectedSize, actualSize);
+ Assertions.assertEquals(expectedQty, actualQty);
+ Assertions.assertEquals(expectedPrice, actualPrice);
+
+ }
+
+ @Test
+ public void findSneakerTest() {
+ WhiskeyService whiskeyService = new WhiskeyService();
+ Whiskey testWhiskey = whiskeyService.create("Fred's Dirty Whiskey", "Don't Drink",
+ 45, 55.0f, 1000, 20.99f);
+ Object expected = null;
+ Object expected2 = testWhiskey;
+ Object actual = whiskeyService.findWhiskey(2);
+ Object actual2 = whiskeyService.findWhiskey(1);
+
+ Assertions.assertEquals(expected, actual);
+ Assertions.assertEquals(expected2, actual2);
+ }
+
+ @Test
+ public void findAllWhiskeyTest() {
+ WhiskeyService whiskeyService = new WhiskeyService();
+ Whiskey testWhiskey = whiskeyService.create("Ewww Juice", "Get Help", 50,
+ 20.5f, 12, 100.00f);
+ Whiskey testWhiskey2 = whiskeyService.create("Them Kicks", "Footstank", 45,
+ 5.0f, 200, 199.99f);
+
+ Whiskey[] expected = {testWhiskey, testWhiskey2};
+
+ Whiskey[] actual = whiskeyService.findAll();
+
+ Assertions.assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteWhiskeyTest() {
+ WhiskeyService whiskeyService = new WhiskeyService();
+ Whiskey testWhiskey = whiskeyService.create("Ewww Juice", "Get Help", 50,
+ 20.5f, 12, 100.00f);
+ Whiskey testWhiskey2 = whiskeyService.create("Them Kicks", "Footstank", 45,
+ 5.0f, 200, 199.99f);
+
+ Boolean expected = true;
+ Boolean expected2 = false;
+
+ Boolean actual = whiskeyService.delete(1);
+ Boolean actual2 = whiskeyService.delete(5);
+
+ Assertions.assertEquals(expected, actual);
+ Assertions.assertEquals(expected2, actual2);
+ }
+}
diff --git a/whiskey.json b/whiskey.json
new file mode 100644
index 0000000..b540cd0
--- /dev/null
+++ b/whiskey.json
@@ -0,0 +1,28 @@
+[ {
+ "id" : 1,
+ "name" : "Jawn Juice",
+ "brand" : "NoDrive",
+ "proof" : 45,
+ "size" : 50.0,
+ "qty" : 125,
+ "price" : 45.5,
+ "totalPrice" : 5687.5
+}, {
+ "id" : 2,
+ "name" : "Ewwater",
+ "brand" : "Bad Taste",
+ "proof" : 45,
+ "size" : 45.7,
+ "qty" : 99,
+ "price" : 55.5,
+ "totalPrice" : 5494.5
+}, {
+ "id" : 3,
+ "name" : "Foolaid",
+ "brand" : "Krunk Bvg Co",
+ "proof" : 60,
+ "size" : 80.0,
+ "qty" : 22,
+ "price" : 89.95,
+ "totalPrice" : 1978.8999
+} ]
\ No newline at end of file