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..0592f79 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,11 +15,24 @@
maven-compiler-plugin
3.8.1
- 1.8
- 1.8
+ 9
+ 9
-
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.4.2
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.4.2
+ test
+
+
\ No newline at end of file
diff --git a/src/main/java/App.java b/src/main/java/App.java
new file mode 100644
index 0000000..b7ec4b6
--- /dev/null
+++ b/src/main/java/App.java
@@ -0,0 +1,168 @@
+import models.Sneaker;
+import services.SneakerService;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Scanner;
+
+import static services.SneakerService.inventory;
+import static utils.CSVUtils.csvFile;
+
+public class App {
+
+ private SneakerService sneakerService = new SneakerService(); // (1)
+
+ public static void main(String... args) {
+ App application = new App(); // (2)
+ application.init(); // (3)
+ }
+
+ public void init() {
+ // (4)
+ // application logic here
+ // call methods to take user input and interface with services
+ Console.printWelcome();
+ runMainMenu();
+ }
+
+ public void runMainMenu() {
+ boolean running = true;
+ Scanner scanner = new Scanner(System.in);
+
+
+ while (running) {
+ Console.printMainMenu();
+ utils.CSVUtils.loadData();
+ utils.CSVUtils.writeSneakersToCSV(csvFile, inventory);
+ int choice = scanner.nextInt();
+ scanner.nextLine(); // Consume newline
+ switch (choice) {
+ case 1:
+ addNewItem();
+ // Create product
+ // Implement the logic to create a product and add it to inventory
+ break;
+ case 2:
+ readExistingProducts();
+ // Read existing products
+ // Implement the logic to read and display existing products
+ break;
+ case 3:
+ updateItem();
+ // Update product
+ // Implement the logic to update a product's details
+ break;
+ case 4:
+ deleteItem();
+ // Delete product
+ // Implement the logic to delete a product from inventory
+ break;
+ case 5:
+ getInventoryReport();
+ // Get reports about products
+ // Implement the logic to generate and display reports
+ break;
+ case 6:
+ System.out.println("Do you want to quit?\n" +
+ "if Yes - type [y]\n" +
+ "if No - type [n]");
+ String quit = scanner.nextLine();
+ if (quit.equalsIgnoreCase("y")) {
+ running = false;
+ }if (quit.equalsIgnoreCase("n")){
+ return;
+ }
+ break;
+ default:
+ System.out.println("Invalid choice. Please select a valid option.");
+ }
+ }
+
+ System.out.println("Exiting the program. Goodbye!");
+ scanner.close();
+ }
+
+ public void addNewItem() {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("Please give a name of this product");
+ String name = scanner.nextLine();
+ System.out.println("Please give the brand of this product");
+ String brand = scanner.nextLine();
+ System.out.println("Please tell what sport");
+ String sport = scanner.nextLine();
+ System.out.println("Please give a size");
+ double size = scanner.nextDouble();
+ System.out.println("Please give a qty ot this items");
+ int qty = scanner.nextInt();
+ System.out.println("Please give a price");
+ float price = scanner.nextFloat();
+ sneakerService.create(name, brand, sport, size, qty, price);
+ System.out.println("We add new itm to inventory");
+ }
+
+ public void updateItem() {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("If you want to update some item press [1] , return press [2]");
+ int answer1 = scanner.nextInt();
+ System.out.println("What is the ID of the item that you want to update ?");
+ int itemID = scanner.nextInt();
+ if (answer1 == 1) {
+ Sneaker temp = sneakerService.findSneaker(itemID);
+
+ System.out.println("Set new price price press [1] \n" +
+ "Set new Qty press [2] \n");
+ int choise = scanner.nextInt();
+
+ if (choise == 1) {
+ System.out.println("What is new price?");
+ float newPrice = scanner.nextFloat();
+ temp.setPrice(newPrice);
+ }
+ if (choise == 2) {
+ System.out.println("What is new Qty?");
+ int newQty = scanner.nextInt();
+ temp.setQty(newQty);
+ } else {
+ return;
+ }
+
+ }
+ }
+
+ public void getInventoryReport () {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("If you want to see the list of all items press [1] , return press [2]");
+ int answer = scanner.nextInt();
+ if (answer == 1) {
+ sneakerService.getInvetoryReport();
+ } else {
+ return;
+ }
+ }
+ public void deleteItem () {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("What item do you want to delete ? \n" +
+ "Please provide the item ID ");
+ int answer = scanner.nextInt();
+ for (Sneaker itemToDelete : sneakerService.findAll()) {
+ if (itemToDelete.getId() == answer) {
+ sneakerService.delete(itemToDelete.getId());
+ System.out.println("The item was succsefully removed");
+ }
+ else {
+ System.out.println("We dont have this ID number in our inventory list");
+ }
+ }
+ }
+
+ public void readExistingProducts () {
+ for (Sneaker s : sneakerService.findAll()){
+
+ System.out.println(s.getName());
+ }
+ }
+
+}
+
+
+
diff --git a/src/main/java/CSVUtils.java b/src/main/java/CSVUtils.java
new file mode 100644
index 0000000..09a158f
--- /dev/null
+++ b/src/main/java/CSVUtils.java
@@ -0,0 +1,88 @@
+package utils;
+
+import models.Sneaker;
+import services.SneakerService;
+
+import java.io.*;
+import java.util.List;
+
+import static services.SneakerService.inventory;
+
+public class CSVUtils {
+ private static final int HEADER_LINE = 1;
+
+ private static final char DEFAULT_SEPARATOR = ',';
+ public static final String csvFile = "/Users/dima/Projects/Product-Inventory-Lab/Sneaker.csv";
+
+ public static void writeLine(Writer w, List values) throws IOException {
+ boolean first = true;
+ StringBuilder sb = new StringBuilder();
+
+ for (String value : values) {
+ if (!first) {
+ sb.append(DEFAULT_SEPARATOR);
+ }
+ sb.append(value);
+ first = false;
+ }
+ sb.append("\n");
+ w.append(sb.toString());
+ }
+
+ public static void writeSneakersToCSV(String csvFilePath, List sneakers) {
+ try (FileWriter writer = new FileWriter(csvFilePath)) {
+ writeLine(writer, List.of("ID", "Name", "Brand", "Sport", "Size", "Quantity", "Price"));
+
+ for (Sneaker s : sneakers) {
+ List list = List.of(
+ String.valueOf(s.getId()),
+ s.getName(),
+ s.getBrand(),
+ s.getSport(),
+ String.valueOf(s.getSize()),
+ String.valueOf(s.getQty()),
+ String.valueOf(s.getPrice())
+ );
+
+ CSVUtils.writeLine(writer, list);
+ }
+ writer.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void loadData() {
+ // (1)
+ // String csvFile = csvFile;
+ String line = "";
+ String csvSplitBy = ",";
+
+ // (2)
+
+ try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
+ // Skip the header line
+ br.readLine();
+
+ SneakerService sneakerService = new SneakerService();
+ 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];
+ double size = Double.parseDouble(beer[4]);
+ int qty = Integer.parseInt(beer[5]);
+ float price = Float.parseFloat(beer[6]);
+
+ // (5)
+ sneakerService.create(name, brand, sport, size, qty, price);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/Console.java b/src/main/java/Console.java
new file mode 100644
index 0000000..91765b0
--- /dev/null
+++ b/src/main/java/Console.java
@@ -0,0 +1,38 @@
+import services.SneakerService;
+
+import java.util.Scanner;
+//package io;
+
+
+public class Console extends SneakerService {
+
+ public static void printWelcome() {
+ System.out.println("" +
+ "*****************************************************"+"\n"+
+ "*** Welcome and Bienvenue ***"+"\n"+
+ "*** to ***"+"\n"+
+ "*** ZipCo Inventory Manager ***"+"\n"+
+ "*****************************************************");
+ }
+
+
+ public static void printMainMenu() {
+ System.out.println(""+
+ "*****************************************************"+"\n"+
+ "*** Press number to make choice ***"+"\n"+
+ "*** [1] Create a new product ***"+"\n"+
+ "*** [2] Read existing products ***"+"\n"+
+ "*** [3] Update product ***"+"\n"+
+ "*** [4] Delete product ***"+"\n"+
+ "*** [5] Get reports about products ***"+"\n"+
+ "*** [6] Exit the program ***"+"\n"+
+ "*****************************************************"
+
+ );
+ }
+
+ public static void createAProduct(){
+
+ }
+
+}
diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java
new file mode 100644
index 0000000..5b78595
--- /dev/null
+++ b/src/main/java/models/Sneaker.java
@@ -0,0 +1,84 @@
+package models;
+
+public class Sneaker {
+ private int id;
+ private String name;
+ private String brand;
+ private String sport;
+ private double size;
+ private int qty;
+ private float price;
+
+ public Sneaker(int id, String name, String brand, String sport, int qty, float price){
+ this(0,null,null,null,0,0,0);
+ }
+ public Sneaker (int id,String name,String brand,String sport,double size, int qty,float price) {
+ this.id = id;
+ this.name = name;
+ this.brand = brand;
+ this.sport = sport;
+ this.size = size;
+ this.qty = qty;
+ this.price = price;
+ }
+ // Sneaker sweetAdidas = new Sneaker(6, "Stan Smith", "Adidas", "Tennis", 10.5f, 10, 80.00f)
+ 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 double getSize() {
+ return size;
+ }
+
+ public void setSize(double size) {
+ this.size = size;
+ }
+
+ public int getQty() {
+ return qty;
+ }
+
+ public void setQty(int qty) {
+ this.qty = qty;
+ }
+
+ public float getPrice() {
+ return price;
+ }
+
+ public void setPrice(float price) {
+ this.price = price;
+ }
+
+ public int getQuantity() {
+ return this.qty;
+ }
+}
diff --git a/src/main/java/models/Whiskey.java b/src/main/java/models/Whiskey.java
new file mode 100644
index 0000000..bb9e5d5
--- /dev/null
+++ b/src/main/java/models/Whiskey.java
@@ -0,0 +1,4 @@
+package models;
+
+public class Whiskey {
+}
diff --git a/src/main/java/services/SneakerService.java b/src/main/java/services/SneakerService.java
new file mode 100644
index 0000000..8ffff4c
--- /dev/null
+++ b/src/main/java/services/SneakerService.java
@@ -0,0 +1,55 @@
+package services;
+
+import models.Sneaker;
+
+import java.util.ArrayList;
+
+public class SneakerService {
+ private static int nextID = 1;
+ public static ArrayList inventory = new ArrayList<>();
+
+
+ public Sneaker create(String expectedName, String expectedBrand, String expectedSport, double expectedSize, int expectedQty, float expectedPrice) {
+ Sneaker sneaker = new Sneaker(nextID++, expectedName, expectedBrand, expectedSport, expectedSize, expectedQty, expectedPrice);
+ this.inventory.add(sneaker);
+ return sneaker;
+ }
+
+ public Sneaker findSneaker(int i) {
+ for (Sneaker s : inventory) {
+ if (s.getId() == i) {
+ return s;
+ }
+ }
+ return null;
+ }
+
+ public Sneaker[] findAll() {
+
+ return inventory.toArray(new Sneaker[0]);
+ // should return a basic array copy of the ArrayList
+ }
+
+ //delete
+ public boolean delete(int id) {
+ for (int i = 0; i < inventory.size(); i++) {
+ if (inventory.get(i).getId() == id) {
+ inventory.remove(i);
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ public void getInvetoryReport () {
+ for (Sneaker s : inventory) {
+ System.out.println("Id: " + s.getId() +"\n" + "Name: " + s.getName()+"\n" + "Qty: " + s.getQty() );
+ }
+ }
+
+ public void clear() {
+ inventory.clear();
+ }
+
+}
diff --git a/src/main/java/services/WhiskeyService.java b/src/main/java/services/WhiskeyService.java
new file mode 100644
index 0000000..bf0864a
--- /dev/null
+++ b/src/main/java/services/WhiskeyService.java
@@ -0,0 +1,20 @@
+package services;
+
+public class WhiskeyService {
+ private int id;
+ private String name;
+ private String brand;
+ private int qty;
+ private float price;
+
+ public WhiskeyService(){
+ this(0,null,null,0,0);
+ }
+ public WhiskeyService (int id,String name,String brand, int qty,float price) {
+ this.id = id;
+ this.name = name;
+ this.brand = brand;
+ this.qty = qty;
+ this.price = price;
+ }
+}
diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java
new file mode 100644
index 0000000..e225d28
--- /dev/null
+++ b/src/test/java/models/SneakerTest.java
@@ -0,0 +1,95 @@
+package models;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class SneakerTest {
+
+
+ @Test
+ public void setNameTest() {
+ // given (1)
+ String expected = "OZWEEGO";
+
+ // when (2)
+ Sneaker testSneaker = new Sneaker( 6, "Stan Smith", "Adidas", "Tennis", 10.5, 10, 80.00f);
+ testSneaker.setName(expected);
+
+ // then (3)
+ Assertions.assertEquals(expected, testSneaker.getName());
+ }
+
+
+ @Test
+ void setId() {
+ Sneaker testSneaker = new Sneaker( 6, "Stan Smith", "Adidas", "Tennis", 10.5, 10, 80.00f);
+ int expected = 2;
+ testSneaker.setId(expected);
+ Assertions.assertEquals(expected,testSneaker.getId());
+
+
+ }
+
+ @Test
+ void setName() {
+ Sneaker testSneaker = new Sneaker( 6, "Stan Smith", "Adidas", "Tennis", 10.5, 10, 80.00f);
+ String expected = "name";
+ testSneaker.setName(expected);
+ Assertions.assertEquals(expected,testSneaker.getName());
+ }
+
+ @Test
+ void setBrand() {
+ Sneaker testSneaker = new Sneaker( 6, "Stan Smith", "Adidas", "Tennis", 10.5, 10, 80.00f);
+ String expected = "Nike";
+ testSneaker.setBrand(expected);
+ Assertions.assertEquals(expected,testSneaker.getBrand());
+ }
+
+ @Test
+ void setSize() {
+ Sneaker testSneaker = new Sneaker( 6, "Stan Smith", "Adidas", "Tennis", 10.5, 10, 80.00f);
+ double expected = 11.5;
+ testSneaker.setSize(expected);
+ Assertions.assertEquals(expected,testSneaker.getSize());
+
+ }
+
+ @Test
+ void setQty() {
+ Sneaker testSneaker = new Sneaker( 6, "Stan Smith", "Adidas", "Tennis", 10.5, 10, 80.00f);
+ int expected = 22;
+ testSneaker.setQty(expected);
+ Assertions.assertEquals(expected,testSneaker.getQty());
+ }
+
+ @Test
+ void setPrice() {
+ Sneaker testSneaker = new Sneaker( 6, "Stan Smith", "Adidas", "Tennis", 10.5, 10, 80.00f);
+ float expected = 90.00f;
+ testSneaker.setPrice(expected);
+ Assertions.assertEquals(expected,testSneaker.getPrice());
+ }
+
+ @Test // (1)
+ public void constructorTest(){
+
+ // (2)
+ int expectedId = 6;
+ String expectedName = "Stan Smith";
+ String expectedBrand = "Adidas";
+ String expectedSport = "Tennis";
+ int expectedQty = 10;
+ float expectedPrice = 80.00f;
+
+ // (3)
+ Sneaker testSneaker = new Sneaker( 6, "Stan Smith", "Adidas", "Tennis", 10.5, 10, 80.00f);
+
+ // (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());}
+}
\ No newline at end of file
diff --git a/src/test/java/models/WhiskeyTest.java b/src/test/java/models/WhiskeyTest.java
new file mode 100644
index 0000000..ab32d3f
--- /dev/null
+++ b/src/test/java/models/WhiskeyTest.java
@@ -0,0 +1,7 @@
+package models;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class WhiskeyTest {
+
+}
\ No newline at end of file
diff --git a/src/test/java/services/SneakerServiceTest.java b/src/test/java/services/SneakerServiceTest.java
new file mode 100644
index 0000000..54aceb7
--- /dev/null
+++ b/src/test/java/services/SneakerServiceTest.java
@@ -0,0 +1,98 @@
+package services;
+
+import models.Sneaker;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestTemplate;
+
+public class SneakerServiceTest {
+
+ SneakerService sneakerService = new SneakerService();
+
+ @Test
+ public void createTest() {
+
+ // (1)
+ String expectedName = "Stan Smith";
+ String expectedBrand = "Adidas";
+ String expectedSport = "Tennis";
+ double expectedSize = 10.5;
+
+ 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.getQuantity();
+ 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);
+ sneakerService.clear();
+
+ }
+
+ @Test
+ public void testFind() {
+
+ // (1)
+ String expectedName = "Stan Smith";
+ String expectedBrand = "Adidas";
+ String expectedSport = "Tennis";
+ double expectedSize = 10.5;
+
+ int expectedQty = 10;
+ float expectedPrice = 80.00f;
+
+ // (2)
+ SneakerService sneakerService = new SneakerService();
+ Sneaker expected = sneakerService.create(expectedName, expectedBrand,
+ expectedSport, expectedSize, expectedQty, expectedPrice);
+
+ // (3)
+ Sneaker actual = sneakerService.findSneaker(1);
+ // actual = sneakerService.findSneaker(0);
+ Assertions.assertEquals(expected, actual);
+ sneakerService.clear();
+
+ }
+ @Test
+ public void testDelete() {
+ SneakerService s = new SneakerService();
+ Sneaker s1 = s.create("Stan Smith", "Adidas", "Tennis", 10.5,10, 80.00f );
+ Sneaker s2 = s.create( "NOTStan Smith", "NOTAdidas", "NOTTennis", 5.5,133, 55.00f );
+ boolean expectedDelete = true;
+ boolean actual = s.delete(1);
+ int expectint = 1;
+ Assertions.assertEquals(expectedDelete,actual);
+ s.clear();
+ }
+
+ @Test
+ public void testDelete2() {
+ SneakerService ss = new SneakerService();
+ Sneaker s1 = ss.create("Stan Smith", "Adidas", "Tennis", 10.5,10, 80.00f );
+ Sneaker s2 = ss.create( "NOTStan Smith", "NOTAdidas", "NOTTennis", 5.5,133, 55.00f );
+ ss.delete(s1.getId());
+ //boolean expectedDelete = true;
+ //boolean actual = s.delete(1);
+ int expectint = 1;
+ Assertions.assertEquals(expectint,ss.findAll().length);
+ ss.clear();
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/services/WhiskeyServiceTest.java b/src/test/java/services/WhiskeyServiceTest.java
new file mode 100644
index 0000000..4e900f1
--- /dev/null
+++ b/src/test/java/services/WhiskeyServiceTest.java
@@ -0,0 +1,7 @@
+package services;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class WhiskeyServiceTest {
+
+}
\ No newline at end of file