Skip to content
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
2 changes: 0 additions & 2 deletions ProductInventoryLab.iml

This file was deleted.

21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,24 @@
</plugin>
</plugins>
</build>

<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>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
91 changes: 91 additions & 0 deletions src/main/java/models/Sneaker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package models;

public class Sneaker {
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.size = size;
this.qty = qty;
this.price = price;
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public String getBrand() {
return brand;
}

public String getSport() {
return sport;
}

public float getSize() {
return size;
}

public int getQty() {
return qty;
}

public float getPrice() {
return price;
}

public void setId(int id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public void setBrand(String brand) {
this.brand = brand;
}

public void setSport(String sport) {
this.sport = sport;
}

public void setSize(float size) {
this.size = size;
}

public void setQty(int qty) {
this.qty = qty;
}

public void setPrice(float price) {
this.price = price;
}

@Override
public String toString() {
return "Sneaker{" +
"id=" + id +
", name='" + name + '\'' +
", brand='" + brand + '\'' +
", sport='" + sport + '\'' +
", size=" + size +
", qty=" + qty +
", price=" + price +
'}';
}
}
56 changes: 56 additions & 0 deletions src/main/java/models/Whiskey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package models;

public class Whiskey {
int id;
String name;
String brand;
float price;

public Whiskey(int id, String name, String brand,float price) {
this.id = id;
this.name = name;
this.brand = brand;
this.price=price;

}

public int getId() {
return id;
}

public String getName() {
return name;
}

public String getBrand() {
return brand;
}

public float getPrice() {
return price;
}

public void setId(int id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public void setBrand(String brand) {
this.brand = brand;
}

public void setPrice(float price) {
this.price = price;
}

@Override
public String toString() {
return "Sneaker{" +
"id=" + id +
", name='" + name + '\'' +
", brand='" + brand + "}";
}
}
51 changes: 51 additions & 0 deletions src/main/java/services/SneakerService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package services;

import models.Sneaker;

import java.util.ArrayList;
import java.util.List;

public class SneakerService {
private static int nextId = 1;

public static void setNextId(int nextId) {
SneakerService.nextId = nextId;
}

private ArrayList<Sneaker> inventory = new ArrayList<>();

public Sneaker create(String name, String brand, String sport, float size, int quantity, float price) {
Sneaker sneaker = new Sneaker(nextId++, name, brand, sport, size, quantity, price);
inventory.add(sneaker);
return sneaker;
}

public Sneaker findSneaker(int id) {
for (int i = 0; i < inventory.size(); i++) {
if (inventory.get(i).getId() == id)
return inventory.get(i);
}
return null;

}
public Sneaker[] findAll() {
Sneaker[] sneakersArr=new Sneaker[inventory.size()];
for(int i=0; i< inventory.size(); i++){
sneakersArr[i] = inventory.get(i);
}

return sneakersArr;
}
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;
}



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

import models.Whiskey;

import java.util.ArrayList;

public class WhiskeyService {
private static int nextId = 1;
public static void setNextId(int nextId) {
WhiskeyService.nextId = nextId;
}
private ArrayList<Whiskey> joyInventory = new ArrayList<>();
public Whiskey create( String name, String brand,float price){
Whiskey whiskey = new Whiskey(nextId++, name, brand,price);
joyInventory.add(whiskey);
return whiskey;
}
public Whiskey findWhiskey(int id){
for (int i = 0; i < joyInventory.size(); i++) {
if (joyInventory.get(i).getId() == id)
return joyInventory.get(i);
}
return null;
}
public Whiskey[] findAll() {
Whiskey[] sneakersArr=new Whiskey[joyInventory.size()];
for(int i=0; i< joyInventory.size(); i++){
sneakersArr[i] = joyInventory.get(i);
}

return sneakersArr;
}
public boolean delete(int id) {
for(int i=0; i<joyInventory.size();i++){
if(joyInventory.get(i).getId()==id){
joyInventory.remove(i);
return true;
}
}
return false;
}
}
87 changes: 87 additions & 0 deletions src/test/java/models/SneakerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package models;


import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
//import org.junit.jupiter.api.Test;
//import org.junit.jupiter.api.TestTemplate;


public class SneakerTest {
int expectedId;
String expectedName;
String expectedBrand;
String expectedSport;
float expectedSize;
int expectedQty;

float expectedPrice;

@Before
public void setUp() {
expectedId = 6;
expectedName = "Stan Smith";
expectedBrand = "Adidas";
expectedSport = "Tennnis";
expectedSize = 10.0f;
expectedQty = 10;
expectedPrice = 80.00f;
Sneaker sneaker = new Sneaker(expectedId, expectedName, expectedBrand, expectedSport, expectedSize, expectedQty, expectedPrice);

}

@Test
public void nameTest() {
Sneaker sneaker = new Sneaker(6, "", "", "", 10, 2, 99.90f);
int expectedId = 6;
String expectedName = "Stan Smith";
String expectedBrand = "Adidas";
String expectedSport = "Tennnis";
float expectedSize = 10.0f;
int expectedQty = 10;
float expectedPrice = 80.00f;
}

@Test
public void constructorTest() {

int expectedId = 6;
String expectedName = "Stan Smith";
String expectedBrand = "Adidas";
String expectedSport = "Tennnis";
float expectedSize = 10.0f;
int expectedQty = 10;
float expectedPrice = 80.00f;

Sneaker sneaker = new Sneaker(expectedId, expectedName, expectedBrand, expectedSport, expectedSize, expectedQty, expectedPrice);
Assert.assertEquals(expectedId, sneaker.getId());
Assert.assertEquals(expectedName, sneaker.getName());
Assert.assertEquals(expectedBrand, sneaker.getBrand());
Assert.assertEquals(expectedSport, sneaker.getSport());
Assert.assertEquals(expectedQty, sneaker.getQty());
Assert.assertEquals(expectedPrice, sneaker.getPrice(), 0.0);

}

@Test
public void testSetterMethods() {
Sneaker sneaker = new Sneaker(8, "Dan Smith", "Flojo", "Tennis", 8.5f, 2, 80f);
sneaker.setId(expectedId);
sneaker.setName(expectedName);
sneaker.setBrand(expectedBrand);
sneaker.setSport(expectedSport);
sneaker.setSize(expectedSize);
sneaker.setQty(expectedQty);
sneaker.setPrice(expectedPrice);


Assert.assertEquals(expectedId, sneaker.getId());
Assert.assertEquals(expectedName, sneaker.getName());
Assert.assertEquals(expectedBrand, sneaker.getBrand());
Assert.assertEquals(expectedSport, sneaker.getSport());
Assert.assertEquals(expectedQty, sneaker.getQty());
Assert.assertEquals(expectedPrice, sneaker.getPrice(), 0.0);
}

}
Loading