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..2664e6c 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,24 @@ ProductInventoryLab 1.0-SNAPSHOT + + + org.junit.jupiter + junit-jupiter-engine + 5.4.2 + test + + + + org.junit.jupiter + junit-jupiter-api + 5.4.2 + test + + + + + @@ -22,4 +40,5 @@ + \ 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..72b71dc --- /dev/null +++ b/src/main/java/Io/App.java @@ -0,0 +1,21 @@ +package Io; + +import services.SneakerService; + +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(); + } + } + diff --git a/src/main/java/Io/Console.java b/src/main/java/Io/Console.java new file mode 100644 index 0000000..fc73bfb --- /dev/null +++ b/src/main/java/Io/Console.java @@ -0,0 +1,15 @@ +package Io; + +public class Console { + public static void printWelcome(){ + System.out.println("" + + "**************************************************" + + "*** Welcome and Bienvenue ***" + + "*** to ***" + + "*** ZipCo Inventory Manager ***" + + "**************************************************"); + } + + + +} diff --git a/src/main/java/models/Sneaker.java b/src/main/java/models/Sneaker.java new file mode 100644 index 0000000..5124832 --- /dev/null +++ b/src/main/java/models/Sneaker.java @@ -0,0 +1,86 @@ +package models; + +import java.util.ArrayList; +import java.util.List; + +public class Sneaker { + public int getQuantity; + private int id; + private String name; + private String brand; + private String sport; + private int size; + private int qty; + private float price; + + public Sneaker(int id, String name, String brand, String sport, int qty, int size, float price) { + this.id = id; + this.name = name; + this.brand = brand; + this.sport = sport; + this.qty = qty; + this.size = size; + this.price = price; + + } + + public Sneaker(int id, String name, String brand, String sport, int qty, float price) { + } + + + public String getName() { + return this.name; + } + public void setName(String name ) { + this.name = 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 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 float getPrice(){ + return price; + } + + public void setPrice(){ + 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..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/CSVUtils.java b/src/main/java/services/CSVUtils.java new file mode 100644 index 0000000..7c5b6b3 --- /dev/null +++ b/src/main/java/services/CSVUtils.java @@ -0,0 +1,9 @@ +package services; + +import java.io.FileWriter; +import java.util.ArrayList; + +public class CSVUtils { + public static void writeLine(FileWriter writer, ArrayList strings) { + } +} diff --git a/src/main/java/services/SneakerService.java b/src/main/java/services/SneakerService.java new file mode 100644 index 0000000..f50b230 --- /dev/null +++ b/src/main/java/services/SneakerService.java @@ -0,0 +1,106 @@ +package services; + +import models.Sneaker; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +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<>(); // (2) + + public static Sneaker create(String name, String brand, String sport, int 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) { + for (Sneaker item : inventory) { + if (item.getId() == id) { + return item; // should take an int and return an object with that id, if exists + } + } + return null; + } + + + //read all + 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(Sneaker item : inventory){ + if(item.getId() == id) { + inventory.remove(item); + return true; // should remove the object with this id from the ArrayList if exits and return true. + } + + } + return false; // Otherwise return false + } +public static void csvFileSaver() throws IOException{ + String csvFile = "/Users/john/Desktop/Sneaker.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, (ArrayList) list); // (4) + } + +// (5) + writer.flush(); + writer.close(); + +} + private void loadData(){ + // (1) + String csvFile = "/Users/John/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]; + int qty = Integer.parseInt(beer[4]); + float price = Float.parseFloat(beer[5]); + + // (5) + inventory.add(new Sneaker(id, name, brand, sport, qty, price)); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/services/WhiskeyService.java b/src/main/java/services/WhiskeyService.java new file mode 100644 index 0000000..1307c24 --- /dev/null +++ b/src/main/java/services/WhiskeyService.java @@ -0,0 +1,4 @@ +package services; + +public class WhiskeyService { +} diff --git a/src/test/java/models/SneakerTest.java b/src/test/java/models/SneakerTest.java new file mode 100644 index 0000000..4ea5189 --- /dev/null +++ b/src/test/java/models/SneakerTest.java @@ -0,0 +1,10 @@ +package models; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SneakerTest { + + + +} \ 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..81c7672 --- /dev/null +++ b/src/test/java/models/WhiskeyTest.java @@ -0,0 +1,4 @@ +package models; + +public class WhiskeyTest { +} diff --git a/src/test/java/services/SneakerServiceTest.java b/src/test/java/services/SneakerServiceTest.java new file mode 100644 index 0000000..74c7513 --- /dev/null +++ b/src/test/java/services/SneakerServiceTest.java @@ -0,0 +1,48 @@ +package services; + +import models.Sneaker; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class SneakerServiceTest { + @Test + public void createTest(){ + + // (1) + String expectedName = "Stan Smith"; + String expectedBrand = "Adidas"; + String expectedSport = "Tennis"; + int expectedSize = (int) 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(); + int 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); + + } + + +} diff --git a/src/test/java/services/WhiskeyServiceTest.java b/src/test/java/services/WhiskeyServiceTest.java new file mode 100644 index 0000000..cb856f0 --- /dev/null +++ b/src/test/java/services/WhiskeyServiceTest.java @@ -0,0 +1,4 @@ +package services; + +public class WhiskeyServiceTest { +}