diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..791bd0f
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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..4c1f783 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,5 +21,31 @@
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.4.2
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.4.2
+ test
+
+
+ junit
+ junit
+ RELEASE
+ test
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.10.1
+
+
+
\ No newline at end of file
diff --git a/src/main/SneakerList.csv b/src/main/SneakerList.csv
new file mode 100644
index 0000000..6cf79c3
--- /dev/null
+++ b/src/main/SneakerList.csv
@@ -0,0 +1,13 @@
+14
+1,Matt,Nike,Tennis,1,100.0
+2,Dunks,Nike,Skating,1,50.0
+3,Matt,Nike,Tennis,1,100.0
+4,Dunks,Nike,Skate,1,100.0
+5,Dunks,Nike,Skate,1,100.0
+7,Dunks,Nike,Skate,1,100.0
+8,Air,Jordan,Basketball,1,100.0
+9,Matt,Matt,Soccer,1,100.0
+10,Assan,Sandals,Crawling,1,100.0
+11,Dunks,Nike,Skate,1,100.0
+12,Jordyn,Maya,Soccer,1,50.0
+13,Thursday,Project,Lets,1,200.0
diff --git a/src/main/java/IO/App.java b/src/main/java/IO/App.java
new file mode 100644
index 0000000..a413bd0
--- /dev/null
+++ b/src/main/java/IO/App.java
@@ -0,0 +1,92 @@
+package IO;
+
+import Models.Sneaker;
+import Services.SneakerService;
+
+import java.io.IOException;
+import java.util.Scanner;
+
+import static java.lang.System.exit;
+import static java.lang.System.in;
+
+public class App {
+ Scanner scanner = new Scanner(in);
+
+ private SneakerService ss = new SneakerService();
+
+ public static void main(String... args) throws IOException {
+ App application = new App();
+ application.init();
+ }
+
+ public void init() throws IOException {
+ // (4)
+ // application logic here
+ // call methods to take user input and interface with services
+ Console.printWelcome();
+ SneakerService.loadData();
+ SneakerService.loadJSONData();
+ SneakerService.loadNextId("/Users/matthew/Projects/Product-Inventory-Lab/src/main/nextID.txt");
+ System.out.println("What would you like to do?");
+ System.out.println("1. Create new sneaker");
+ System.out.println("2. See existing inventory");
+ System.out.println("3. Find Sneaker by ID");
+ System.out.println("4. Update inventory");
+ System.out.println("5. Delete inventory");
+ System.out.println("6. Get Product Reports");
+ System.out.println("7. Exit Program\n");
+ int choice = scanner.nextInt();
+ switch(choice){
+ case 1:
+ System.out.println("Name your sneaker");
+ scanner.nextLine();
+ String name = scanner.nextLine();
+ System.out.println("Name your brand");
+ String brand = scanner.nextLine();
+ System.out.println("Name your sport");
+ String sport = scanner.nextLine();
+ System.out.println("Choose your size");
+ int size = scanner.nextInt();
+ System.out.println("Choose qty to make");
+ int qty = scanner.nextInt();
+ System.out.println("Choose a price point");
+ double price = scanner.nextDouble();
+ SneakerService.create(name, brand, sport, size, qty, price);
+ SneakerService.writeToCSV();
+ SneakerService.writeJSONData();
+ SneakerService.saveNextId("/Users/matthew/Projects/Product-Inventory-Lab/src/main/nextID.txt");
+ break;
+ case 2:
+ Sneaker[] inventory = SneakerService.findAll();
+ for (Sneaker sneaker : inventory) {
+ System.out.println("Name: " + sneaker.getName());
+ System.out.println("Brand: " + sneaker.getBrand());
+ System.out.println("Sport: " + sneaker.getSport());
+ System.out.println("Size: " + sneaker.getSize());
+ System.out.println("Quantity: " + sneaker.getQty());
+ System.out.println("Price: " + sneaker.getPrice());
+ System.out.println();
+ }
+ break;
+ case 3:
+ System.out.println("Choose ID to find");
+ int id1 = scanner.nextInt();
+ SneakerService.findSneaker(id1);
+ break;
+ case 4:
+ break;
+ case 5:
+ System.out.println("Choose an ID to delete, check existing inventory first");
+ int id2 = scanner.nextInt();
+ SneakerService.delete(id2);
+ SneakerService.writeToCSV();
+ break;
+ case 6:
+ System.out.println("Product report");
+ break;
+ case 7:
+ System.exit(0);
+ break;
+ }
+ }
+}
diff --git a/src/main/java/IO/Console.java b/src/main/java/IO/Console.java
new file mode 100644
index 0000000..ddd2e05
--- /dev/null
+++ b/src/main/java/IO/Console.java
@@ -0,0 +1,19 @@
+
+package IO;
+
+import java.util.Scanner;
+
+import static java.lang.System.in;
+
+public class Console {
+
+ public Scanner scanner = new Scanner(in);
+ public static void printWelcome(){
+ System.out.println("" +
+ "**************************************************\n"+
+ "*** Welcome and Bienvenue ***\n" +
+ "*** to ***\n" +
+ "*** ZipCo Inventory Manager ***\n" +
+ "**************************************************");
+ }
+}
diff --git a/src/main/java/Models/Sneaker.java b/src/main/java/Models/Sneaker.java
new file mode 100644
index 0000000..61dbb77
--- /dev/null
+++ b/src/main/java/Models/Sneaker.java
@@ -0,0 +1,85 @@
+package Models;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class Sneaker {
+ private int id;
+ private String name;
+ private String brand;
+ private String sport;
+ private int size;
+ private int qty;
+ private double price;
+
+ public Sneaker(){
+
+ }
+
+
+ public Sneaker(int id, String name, String brand, String sport, int size, int qty, double price){
+ this.id = id;
+ this.name = name;
+ this.brand = brand;
+ this.sport = sport;
+ 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 String getSport() {
+ return sport;
+ }
+
+ public void setSport(String sport) {
+ this.sport = sport;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ public int getQty() {
+ return qty;
+ }
+
+ public void setQty(int qty) {
+ this.qty = qty;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+}
diff --git a/src/main/java/Models/Whiskey.java b/src/main/java/Models/Whiskey.java
new file mode 100644
index 0000000..6847b50
--- /dev/null
+++ b/src/main/java/Models/Whiskey.java
@@ -0,0 +1,9 @@
+package Models;
+
+public class Whiskey {
+ private int age;
+ private String brand;
+ private String color;
+ private int ounces;
+ private float price;
+}
diff --git a/src/main/java/Services/SneakerService.java b/src/main/java/Services/SneakerService.java
new file mode 100644
index 0000000..48bf269
--- /dev/null
+++ b/src/main/java/Services/SneakerService.java
@@ -0,0 +1,142 @@
+package Services;
+
+import Models.Sneaker;
+import Utils.CSVUtils;
+import com.fasterxml.jackson.annotation.JsonProperty;
+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.*;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class SneakerService {
+ private static int nextId = 1;
+
+ @JsonProperty
+ private static List inventory = new ArrayList<>();
+
+
+ public static Sneaker create(String name, String brand, String sport, int size, int quantity, double price) {
+
+ // (2)
+ Sneaker createdSneaker = new Sneaker(nextId, name, brand, sport, size, quantity, price);
+ nextId++;
+ // (3)
+ inventory.add(createdSneaker);
+
+ // (4)
+ return createdSneaker;
+ }
+
+ public static Sneaker findSneaker(int id) {
+ // should take an int and return an object with that id, if exists
+ if (inventory.contains(id)) {
+ return inventory.get(id);
+ } else {
+ System.out.println("ID does not exist");
+ return null;
+ }
+ }
+
+ //read all
+ public static Sneaker[] findAll() {
+ // should return a basic array copy of the ArrayList
+ return inventory.toArray(new Sneaker[0]);
+ }
+
+ //delete
+ public static boolean delete(int id) {
+ // should remove the object with this id from the ArrayList if exits and return true.
+ // Otherwise return false
+ for(Sneaker sneaks : inventory){
+ if(sneaks.getId() == id){
+ inventory.remove(id);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static void writeToCSV() throws IOException {
+ String csvFile = "/Users/matthew/Projects/Product-Inventory-Lab/src/main/SneakerList.csv";
+ FileWriter writer = new FileWriter(csvFile); //(1)
+
+ CSVUtils.writeLine(writer, new ArrayList(Arrays.asList(String.valueOf(nextId)))); // (2)
+
+ for (Sneaker s : inventory) {
+ List list = new ArrayList<>(); // (3)
+ list.add(String.valueOf(s.getId()));
+ list.add(s.getName());
+ list.add(s.getBrand());
+ list.add(s.getSport());
+ list.add(String.valueOf(s.getQty()));
+ list.add(String.valueOf(s.getPrice()));
+
+ CSVUtils.writeLine(writer, list); // (4)
+ }
+
+ // (5)
+ writer.flush();
+ writer.close();
+ }
+
+ public static void loadData(){
+ // (1)
+ String csvFile = "/Users/matthew/Projects/Product-Inventory-Lab/src/main/SneakerList.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];
+ int qty = Integer.parseInt(beer[4]);
+ double price = Double.parseDouble(beer[5]);
+
+ // (5)
+ inventory.add(new Sneaker(id, name, brand, sport, 12, qty, price));
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void loadJSONData() throws IOException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ //JavaType type = objectMapper.getTypeFactory().constructCollectionType(List.class, Sneaker.class);
+ inventory = objectMapper.readValue(new File("/Users/matthew/Projects/Product-Inventory-Lab/src/main/sneaker.json"), new TypeReference>(){});
+
+ }
+
+ public static void writeJSONData() throws IOException {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
+ writer.writeValue(new File("/Users/matthew/Projects/Product-Inventory-Lab/src/main/sneaker.json"), inventory);
+ }
+
+ // Save and Load nextId Static Data with a Text File
+ public static void saveNextId(String filename) throws IOException {
+ FileWriter writer = new FileWriter(filename);
+ writer.write(String.valueOf(nextId));
+ writer.close();
+ }
+
+ public static void loadNextId(String filename) throws IOException {
+ BufferedReader reader = new BufferedReader(new FileReader(filename));
+ nextId = Integer.parseInt(reader.readLine());
+ reader.close();
+ }
+}
diff --git a/src/main/java/Services/WhiskeyService.java b/src/main/java/Services/WhiskeyService.java
new file mode 100644
index 0000000..def3cb5
--- /dev/null
+++ b/src/main/java/Services/WhiskeyService.java
@@ -0,0 +1,4 @@
+package Services;
+
+public class WhiskeyService {
+}
diff --git a/src/main/java/Utils/CSVUtils.java b/src/main/java/Utils/CSVUtils.java
new file mode 100644
index 0000000..aed50a0
--- /dev/null
+++ b/src/main/java/Utils/CSVUtils.java
@@ -0,0 +1,28 @@
+package Utils;
+
+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)
+ }
+}
diff --git a/src/main/nextID.txt b/src/main/nextID.txt
new file mode 100644
index 0000000..da2d398
--- /dev/null
+++ b/src/main/nextID.txt
@@ -0,0 +1 @@
+14
\ No newline at end of file
diff --git a/src/main/sneaker.json b/src/main/sneaker.json
new file mode 100644
index 0000000..f7b3993
--- /dev/null
+++ b/src/main/sneaker.json
@@ -0,0 +1,97 @@
+[ {
+ "id" : 1,
+ "name" : "Matt",
+ "brand" : "Nike",
+ "sport" : "Tennis",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 2,
+ "name" : "Dunks",
+ "brand" : "Nike",
+ "sport" : "Skating",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 50.0
+}, {
+ "id" : 3,
+ "name" : "Matt",
+ "brand" : "Nike",
+ "sport" : "Tennis",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 4,
+ "name" : "Dunks",
+ "brand" : "Nike",
+ "sport" : "Skate",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 5,
+ "name" : "Dunks",
+ "brand" : "Nike",
+ "sport" : "Skate",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 7,
+ "name" : "Dunks",
+ "brand" : "Nike",
+ "sport" : "Skate",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 8,
+ "name" : "Air",
+ "brand" : "Jordan",
+ "sport" : "Basketball",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 9,
+ "name" : "Matt",
+ "brand" : "Matt",
+ "sport" : "Soccer",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 10,
+ "name" : "Assan",
+ "brand" : "Sandals",
+ "sport" : "Crawling",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 11,
+ "name" : "Dunks",
+ "brand" : "Nike",
+ "sport" : "Skate",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 100.0
+}, {
+ "id" : 12,
+ "name" : "Jordyn",
+ "brand" : "Maya",
+ "sport" : "Soccer",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 50.0
+}, {
+ "id" : 13,
+ "name" : "Thursday",
+ "brand" : "Project",
+ "sport" : "Lets",
+ "size" : 12,
+ "qty" : 1,
+ "price" : 200.0
+} ]
\ No newline at end of file
diff --git a/src/test/java/ModelsTest/SneakerTest.java b/src/test/java/ModelsTest/SneakerTest.java
new file mode 100644
index 0000000..49f03ed
--- /dev/null
+++ b/src/test/java/ModelsTest/SneakerTest.java
@@ -0,0 +1,45 @@
+package ModelsTest;
+
+import Models.Sneaker;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+
+public class SneakerTest {
+
+ @Test
+ public void setNameTest() {
+ // given (1)
+ String expected = "OZWEEGO";
+
+ // when (2)
+ Sneaker testSneaker = new Sneaker(0, expected, null, null, 0, 0, 0);
+ testSneaker.setName(expected);
+
+ // then (3)
+ Assertions.assertEquals(expected, testSneaker.getName());
+ }
+
+ @Test // (1)
+ public void constructorTest(){
+
+ // (2)
+ int expectedId = 6;
+ String expectedName = "Stan Smith";
+ String expectedBrand = "Adidas";
+ String expectedSport = "Tennis";
+ int expectedQty = 10;
+ double expectedPrice = 80.00;
+
+ // (3)
+ Sneaker testSneaker = new Sneaker(expectedId, expectedName, expectedBrand,
+ expectedSport,0, 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/ModelsTest/WhiskeyTest.java b/src/test/java/ModelsTest/WhiskeyTest.java
new file mode 100644
index 0000000..0936ada
--- /dev/null
+++ b/src/test/java/ModelsTest/WhiskeyTest.java
@@ -0,0 +1,4 @@
+package ModelsTest;
+
+public class WhiskeyTest {
+}
diff --git a/src/test/java/ServicesTest/SneakerServicesTest.java b/src/test/java/ServicesTest/SneakerServicesTest.java
new file mode 100644
index 0000000..c2f3471
--- /dev/null
+++ b/src/test/java/ServicesTest/SneakerServicesTest.java
@@ -0,0 +1,44 @@
+package ServicesTest;
+
+import Models.Sneaker;
+import Services.SneakerService;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+
+public class SneakerServicesTest {
+
+ @Test
+ public void createTest() {
+
+ // (1)
+ String expectedName = "Stan Smith";
+ String expectedBrand = "Adidas";
+ String expectedSport = "Tennis";
+ int expectedSize = (int) 10.5;
+ int expectedQty = 10;
+ double expectedPrice = 80.00;
+
+ // (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();
+ int actualSize = testSneaker.getSize();
+ int actualQty = testSneaker.getQty();
+ double 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);
+ }
+}
diff --git a/src/test/java/ServicesTest/WhiskeyServicesTest.java b/src/test/java/ServicesTest/WhiskeyServicesTest.java
new file mode 100644
index 0000000..3967228
--- /dev/null
+++ b/src/test/java/ServicesTest/WhiskeyServicesTest.java
@@ -0,0 +1,4 @@
+package ServicesTest;
+
+public class WhiskeyServicesTest {
+}