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

done #10

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

done #10

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.

3 changes: 3 additions & 0 deletions .idea/misc.xml

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

26 changes: 25 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,29 @@
</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>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
21 changes: 21 additions & 0 deletions src/main/java/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Services.TradingCardService;
import io.Console;

public class App {
private TradingCardService tradingCardService = new TradingCardService();
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();
// }
}
}


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

public class Desserts {



private int id;
private String name;
private double price;
private int popularity;
private int numServes;

public Desserts(){

}

public Desserts(int id, String name, double price, int popularity, int numServes){
this.id = id;
this.name = name;
this.price = price;
this.popularity = popularity;
this.numServes = numServes;

}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setPrice(double price) {
this.price = price;
}
public double getPrice() {
return price;
}

public void setpopularity(int popularity) {
this.popularity = popularity;
}
public int getpopularity() {
return popularity;
}

public void setnumServes(int numServes) {
this.numServes = numServes;
}
public int getnumServes() {
return numServes;
}
}
55 changes: 55 additions & 0 deletions src/main/java/Models/TradingCards.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package Models;

public class TradingCards {
private int id;
private String game;
private int rarity;
private boolean isFromStartedDeck;
private double price;

public TradingCards(){

}

public TradingCards(int id, String game, int rarity, boolean isFromStartedDeck, double price){
this.id = id;
this.game = game;
this.rarity = rarity;
this.isFromStartedDeck = isFromStartedDeck;
this.price = price;
}


public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setGame(String game) {
this.game = game;
}
public String getGame() {
return game;
}
public void setRarity(int rarity) {
this.rarity = rarity;
}
public int getRarity() {
return rarity;
}

public void setFromStarterDeck(boolean isFromStartedDeck) {
this.isFromStartedDeck = isFromStartedDeck;
}
public boolean getFromStarterDeck() {
return isFromStartedDeck;
}

public void setPrice(double price) {
this.price = price;
}
public double getPrice() {
return price;
}
}
55 changes: 55 additions & 0 deletions src/main/java/Services/DessertsService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package Services;

import Models.Desserts;

import java.util.ArrayList;

public class DessertsService {
private static int nextId = 1; // (1)

private static ArrayList <Desserts> inventory = new ArrayList<>(); // (2)

public static Desserts create(String name, double price, int popularity, int numServes) {

// (2)
Desserts createdDessert = new Desserts(nextId++, name, price, popularity, numServes);

// (3)
inventory.add(createdDessert);

// (4)
return createdDessert;
}
//read
public Desserts findDessert(int id) {
// should take an int and return an object with that id, if exists
for(int i=0; i<inventory.size(); i++){
if(inventory.get(i).getId()==id){
return inventory.get(i);
}
}
return null;
}

//read all
public Desserts[] findAll() {
// should return a basic array copy of the ArrayList
Desserts[] desArr = new Desserts[inventory.size()];
for(int i=0; i<inventory.size(); i++){
desArr[i] = inventory.get(i);
}
return desArr;
}

//delete
public boolean delete(int id) {
// should remove the object with this id from the ArrayList if exits and return true.
// Otherwise return false
if(findDessert(id) != null){
inventory.remove(findDessert(id));
return true;
}else{
return false;
}
}
}
58 changes: 58 additions & 0 deletions src/main/java/Services/TradingCardService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package Services;

import Models.Desserts;
import Models.TradingCards;
import com.sun.deploy.net.MessageHeader;

import java.util.ArrayList;

public class TradingCardService {
private static int nextId = 1; // (1)


private static ArrayList <TradingCards> inventory = new ArrayList<>(); // (2)

public static TradingCards create(String game, int rarity, boolean isFromStartedDeck, double price) {

// (2)
TradingCards createdTradingCard = new TradingCards(nextId++, game, rarity, isFromStartedDeck, price);

// (3)
inventory.add(createdTradingCard);

// (4)
return createdTradingCard;
}
//read
public TradingCards findTradingCard(int id) {
// should take an int and return an object with that id, if exists
for(int i=0; i<inventory.size(); i++){
if(inventory.get(i).getId()==id){
return inventory.get(i);
}
}
return null;
}

//read all
public TradingCards[] findAll() {
// should return a basic array copy of the ArrayList
TradingCards[] tcArr = new TradingCards[inventory.size()];
for(int i=0; i<inventory.size(); i++){
tcArr[i] = inventory.get(i);
}
return tcArr;
}

//delete
public boolean delete(int id) {
// should remove the object with this id from the ArrayList if exits and return true.
// Otherwise return false
if(findTradingCard(id) != null){
inventory.remove(findTradingCard(id));
return true;
}else{
return false;
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/io/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io;

public class Console {
public static void printWelcome(){
System.out.println("" +
"**************************************************" +
"*** Welcome and Bienvenue ***" +
"*** to ***" +
"*** ZipCo Inventory Manager ***" +
"**************************************************");
}
}
33 changes: 33 additions & 0 deletions src/test/java/Models/DessertsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package Models;

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

public class DessertsTest {
@Test
public void setNameTest() {
String expected = "brownie";
Desserts testDessert = new Desserts();
testDessert.setName(expected);
Assertions.assertEquals(expected, testDessert.getName());
}

@Test // (1)
public void constructorTest(){
int exid = 6;
String exname = "icecream";
double exprice = 4.00;
int expopularity = 9;
int exnumServes = 2;

Desserts testDessert = new Desserts(exid, exname, exprice, expopularity,
exnumServes);

Assertions.assertEquals(exid, testDessert.getId());
Assertions.assertEquals(exname, testDessert.getName());
Assertions.assertEquals(exprice, testDessert.getPrice());
Assertions.assertEquals(expopularity, testDessert.getpopularity());
Assertions.assertEquals(exnumServes, testDessert.getnumServes());

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

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

public class TradingCardTest {
@Test
public void setGameTest() {
String expected = "pokemon";
TradingCards testGame = new TradingCards();
testGame.setGame(expected);
Assertions.assertEquals(expected, testGame.getGame());
}

@Test // (1)
public void constructorTest(){
int exid = 5;
String exgame = "DnD";
int exrarity = 6;
boolean exisFromStartedDeck = false;
double exprice = 15.00;

TradingCards testCard = new TradingCards(exid, exgame, exrarity, exisFromStartedDeck,
exprice);

Assertions.assertEquals(exid, testCard.getId());
Assertions.assertEquals(exgame, testCard.getGame());
Assertions.assertEquals(exrarity, testCard.getRarity());
Assertions.assertEquals(exisFromStartedDeck, testCard.getFromStarterDeck());
Assertions.assertEquals(exprice, testCard.getPrice());

}
}

Loading