Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature sneaker properties #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@
<artifactId>ProductInventoryLab</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>

</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>



<build>
<plugins>
<plugin>
Expand All @@ -22,4 +40,5 @@
</plugins>
</build>


</project>
21 changes: 21 additions & 0 deletions src/main/java/Io/App.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

15 changes: 15 additions & 0 deletions src/main/java/Io/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Io;

public class Console {
public static void printWelcome(){
System.out.println("" +
"**************************************************" +
"*** Welcome and Bienvenue ***" +
"*** to ***" +
"*** ZipCo Inventory Manager ***" +
"**************************************************");
}



}
86 changes: 86 additions & 0 deletions src/main/java/models/Sneaker.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

4 changes: 4 additions & 0 deletions src/main/java/models/Whiskey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package models;

public class Whiskey {
}
9 changes: 9 additions & 0 deletions src/main/java/services/CSVUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package services;

import java.io.FileWriter;
import java.util.ArrayList;

public class CSVUtils {
public static void writeLine(FileWriter writer, ArrayList<String> strings) {
}
}
106 changes: 106 additions & 0 deletions src/main/java/services/SneakerService.java
Original file line number Diff line number Diff line change
@@ -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<nextId> {

private static int nextId = 1; // (1)
private static List<Sneaker> 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<String>(Arrays.asList(String.valueOf(nextId)))); // (2)

for (Sneaker s : inventory) {
List<String> 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<String>) 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();
}
}

}
4 changes: 4 additions & 0 deletions src/main/java/services/WhiskeyService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package services;

public class WhiskeyService {
}
10 changes: 10 additions & 0 deletions src/test/java/models/SneakerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package models;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SneakerTest {



}
4 changes: 4 additions & 0 deletions src/test/java/models/WhiskeyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package models;

public class WhiskeyTest {
}
48 changes: 48 additions & 0 deletions src/test/java/services/SneakerServiceTest.java
Original file line number Diff line number Diff line change
@@ -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);

}


}
4 changes: 4 additions & 0 deletions src/test/java/services/WhiskeyServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package services;

public class WhiskeyServiceTest {
}