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
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: 16 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>9</source>
<target>9</target>
</configuration>
</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>
168 changes: 168 additions & 0 deletions src/main/java/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import models.Sneaker;
import services.SneakerService;

import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;

import static services.SneakerService.inventory;
import static utils.CSVUtils.csvFile;

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();
runMainMenu();
}

public void runMainMenu() {
boolean running = true;
Scanner scanner = new Scanner(System.in);


while (running) {
Console.printMainMenu();
utils.CSVUtils.loadData();
utils.CSVUtils.writeSneakersToCSV(csvFile, inventory);
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
addNewItem();
// Create product
// Implement the logic to create a product and add it to inventory
break;
case 2:
readExistingProducts();
// Read existing products
// Implement the logic to read and display existing products
break;
case 3:
updateItem();
// Update product
// Implement the logic to update a product's details
break;
case 4:
deleteItem();
// Delete product
// Implement the logic to delete a product from inventory
break;
case 5:
getInventoryReport();
// Get reports about products
// Implement the logic to generate and display reports
break;
case 6:
System.out.println("Do you want to quit?\n" +
"if Yes - type [y]\n" +
"if No - type [n]");
String quit = scanner.nextLine();
if (quit.equalsIgnoreCase("y")) {
running = false;
}if (quit.equalsIgnoreCase("n")){
return;
}
break;
default:
System.out.println("Invalid choice. Please select a valid option.");
}
}

System.out.println("Exiting the program. Goodbye!");
scanner.close();
}

public void addNewItem() {
Scanner scanner = new Scanner(System.in);
System.out.println("Please give a name of this product");
String name = scanner.nextLine();
System.out.println("Please give the brand of this product");
String brand = scanner.nextLine();
System.out.println("Please tell what sport");
String sport = scanner.nextLine();
System.out.println("Please give a size");
double size = scanner.nextDouble();
System.out.println("Please give a qty ot this items");
int qty = scanner.nextInt();
System.out.println("Please give a price");
float price = scanner.nextFloat();
sneakerService.create(name, brand, sport, size, qty, price);
System.out.println("We add new itm to inventory");
}

public void updateItem() {
Scanner scanner = new Scanner(System.in);
System.out.println("If you want to update some item press [1] , return press [2]");
int answer1 = scanner.nextInt();
System.out.println("What is the ID of the item that you want to update ?");
int itemID = scanner.nextInt();
if (answer1 == 1) {
Sneaker temp = sneakerService.findSneaker(itemID);

System.out.println("Set new price price press [1] \n" +
"Set new Qty press [2] \n");
int choise = scanner.nextInt();

if (choise == 1) {
System.out.println("What is new price?");
float newPrice = scanner.nextFloat();
temp.setPrice(newPrice);
}
if (choise == 2) {
System.out.println("What is new Qty?");
int newQty = scanner.nextInt();
temp.setQty(newQty);
} else {
return;
}

}
}

public void getInventoryReport () {
Scanner scanner = new Scanner(System.in);
System.out.println("If you want to see the list of all items press [1] , return press [2]");
int answer = scanner.nextInt();
if (answer == 1) {
sneakerService.getInvetoryReport();
} else {
return;
}
}
public void deleteItem () {
Scanner scanner = new Scanner(System.in);
System.out.println("What item do you want to delete ? \n" +
"Please provide the item ID ");
int answer = scanner.nextInt();
for (Sneaker itemToDelete : sneakerService.findAll()) {
if (itemToDelete.getId() == answer) {
sneakerService.delete(itemToDelete.getId());
System.out.println("The item was succsefully removed");
}
else {
System.out.println("We dont have this ID number in our inventory list");
}
}
}

public void readExistingProducts () {
for (Sneaker s : sneakerService.findAll()){

System.out.println(s.getName());
}
}

}



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

import models.Sneaker;
import services.SneakerService;

import java.io.*;
import java.util.List;

import static services.SneakerService.inventory;

public class CSVUtils {
private static final int HEADER_LINE = 1;

private static final char DEFAULT_SEPARATOR = ',';
public static final String csvFile = "/Users/dima/Projects/Product-Inventory-Lab/Sneaker.csv";

public static void writeLine(Writer w, List<String> values) throws IOException {
boolean first = true;
StringBuilder sb = new StringBuilder();

for (String value : values) {
if (!first) {
sb.append(DEFAULT_SEPARATOR);
}
sb.append(value);
first = false;
}
sb.append("\n");
w.append(sb.toString());
}

public static void writeSneakersToCSV(String csvFilePath, List<Sneaker> sneakers) {
try (FileWriter writer = new FileWriter(csvFilePath)) {
writeLine(writer, List.of("ID", "Name", "Brand", "Sport", "Size", "Quantity", "Price"));

for (Sneaker s : sneakers) {
List<String> list = List.of(
String.valueOf(s.getId()),
s.getName(),
s.getBrand(),
s.getSport(),
String.valueOf(s.getSize()),
String.valueOf(s.getQty()),
String.valueOf(s.getPrice())
);

CSVUtils.writeLine(writer, list);
}
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static void loadData() {
// (1)
// String csvFile = csvFile;
String line = "";
String csvSplitBy = ",";

// (2)

try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
// Skip the header line
br.readLine();

SneakerService sneakerService = new SneakerService();
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];
double size = Double.parseDouble(beer[4]);
int qty = Integer.parseInt(beer[5]);
float price = Float.parseFloat(beer[6]);

// (5)
sneakerService.create(name, brand, sport, size, qty, price);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import services.SneakerService;

import java.util.Scanner;
//package io;


public class Console extends SneakerService {

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


public static void printMainMenu() {
System.out.println(""+
"*****************************************************"+"\n"+
"*** Press number to make choice ***"+"\n"+
"*** [1] Create a new product ***"+"\n"+
"*** [2] Read existing products ***"+"\n"+
"*** [3] Update product ***"+"\n"+
"*** [4] Delete product ***"+"\n"+
"*** [5] Get reports about products ***"+"\n"+
"*** [6] Exit the program ***"+"\n"+
"*****************************************************"

);
}

public static void createAProduct(){

}

}
Loading