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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

.idea/
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
Expand Down
53 changes: 0 additions & 53 deletions .idea/$PRODUCT_WORKSPACE_FILE$

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/compiler.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/encodings.xml

This file was deleted.

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

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,18 @@
</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>
</dependencies>
</project>
112 changes: 112 additions & 0 deletions src/main/java/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import io.Console;
import models.Sneaker;
import services.SneakerService;

public class App {

private SneakerService sneakerService = new SneakerService();

public static void main(String... args) {
App application = new App();
application.init();
}

public void init() {
Console.println("Welcome!!");
Integer action = Console.getIntegerInput(
"1 create shoe\n" +
"2 read shoes\n" +
"3 update shoe\n" +
"4 delete shoe\n" +
"select action: ");
interpretUserAction(action);

}

public void interpretUserAction(Integer action) {
switch(action) {
case 1: // create
create("Shoe");
Console.println("New Sneaker created with id %s", sneakerService.size());
break;
case 2: // read
read("shoe");
break;
case 3: // update
update();
break;
case 4: // destroy
delete();
break;
case 5:
System.exit(0);
break;
default:
init();
}
init();
}

public void create(String product) {
String name = Console.getStringInput("%s name: ", product);
String brand = Console.getStringInput("%s brand: ", product);
String sport = Console.getStringInput("%s sport: ", product);
Double size = Console.getDoubleInput("%s size: ", product);
Integer quantity = Console.getIntegerInput("%s quantity: ", product);
Float price = Float.parseFloat(Console.getStringInput("%s price: ", product));

sneakerService.create(name, brand, sport, size, quantity, price);

}
public void read(String product) {
Console.println(sneakerService.toString());
}

public void update() {
Integer id = Console.getIntegerInput("enter id of sneaker to update: ");
Sneaker toUpdate = sneakerService.findSneaker(id);
Integer action = Console.getIntegerInput("Update Sneaker:\n" +
"1 : Name\n2 : Brand\n3 : Sport\n" +
"4 : Size\n5 : Quantity\n6 : Price\n" +
"Select attribute to update: ");
toUpdate = dispatchUpdate(action, toUpdate);
sneakerService.update(id, toUpdate);
Console.println("Shoe %s has been updated", id);
}

public Sneaker dispatchUpdate(Integer action, Sneaker sneaker) {
switch(action) {
case 1:
String name = Console.getStringInput("Change Name: ");
sneaker.setName(name);
break;
case 2:
String brand = Console.getStringInput("Change Brand: ");
sneaker.setBrand(brand);
break;
case 3:
String sport = Console.getStringInput("Change Sport: ");
sneaker.setSport(sport);
break;
case 4:
Double size = Console.getDoubleInput("Change Size: ");
sneaker.setSize(size);
break;
case 5:
Integer quantity = Console.getIntegerInput("Change Quantity: ");
sneaker.setQuantity(quantity);
break;
case 6:
Float price = Float.parseFloat(Console.getStringInput("Change Price: "));
sneaker.setPrice(price);
break;
}
return sneaker;
}

public void delete() {
Integer id = Console.getIntegerInput("Enter Id of Sneaker to delete: ");
if (sneakerService.delete(id)) Console.println("Sneaker %s successfully deleted", id);
else Console.println("Deletion failed");
}
}
48 changes: 48 additions & 0 deletions src/main/java/io/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io;

import java.util.Scanner;

public class Console {
public static void print(String val, Object... args) {
System.out.print(String.format(val, args));
}

public static void println(String val, Object... args) {
print(val + "\n", args);
}

public static String getStringInput(String prompt, Object... args) {
Scanner scanner = new Scanner(System.in);
print(prompt, args);
return scanner.nextLine();
}

public static Double getDoubleInput(String prompt, Object... args) {
String stringInput = getStringInput(prompt, args);
try {
Double doubleInput = Double.parseDouble(stringInput);
return doubleInput;
} catch (NumberFormatException nfe) {
println("[ %s ] is an invalid user input!", stringInput);
println("Try inputting a numeric value!");
return getDoubleInput(prompt, args);
}
}

public static Long getLongInput(String prompt, Object... args) {
String stringInput = getStringInput(prompt, args);
try {
Long longInput = Long.parseLong(stringInput);
return longInput;
} catch (NumberFormatException nfe) {
println("[ %s ] is an invalid user input!", stringInput);
println("Try inputting an integer value!");
return getLongInput(prompt, args);
}
}

public static Integer getIntegerInput(String prompt, Object... args) {
return getLongInput(prompt, args).intValue();
}

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

public class Sneaker {
private Integer id;
private String name;
private String brand;
private String sport;
private Double size;
private Integer quantity;
private Float price;

public Sneaker() {}

public Sneaker(Integer id, String name, String brand, String sport, Double size, Integer quantity, Float price) {
this.id = id;
this.name = name;
this.brand = brand;
this.sport = sport;
this.size = size;
this.quantity = quantity;
this.price = price;
}

public Integer getId() {
return id;
}

public void setId(Integer 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 Integer getQuantity() {
return quantity;
}

public void setQuantity(Integer quantity) {
this.quantity = quantity;
}

public Float getPrice() {
return price;
}

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

public String toString() {
return String.format("\n%s %s %s %s %s %s %s", getId(),
getBrand(), getName(), getSport(),
getSize(), getQuantity(), getPrice());
}
}
Loading