Skip to content

Commit

Permalink
cohort 42.1 project #1 update day #2
Browse files Browse the repository at this point in the history
  • Loading branch information
biblelamp committed Apr 19, 2024
1 parent 178c696 commit 8a25c50
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 89 deletions.
20 changes: 12 additions & 8 deletions BerlinAIT/Cohort42.1project/JavaPizza/src/pizza/JavaPizza.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pizza;

import pizza.controller.AppController;
import pizza.repository.PizzaRepository;
import pizza.service.CustomerService;
import pizza.service.ExtComponentService;
import pizza.service.OrderService;
Expand All @@ -11,20 +12,23 @@
* JavaPizza based on https://www.foodora.cz/en/restaurant/uyou/saporito-pizza-and-pasta
*
* @author Sergey Iryupin
* @version 17-Apr-24
* @version 18-Apr-24
*/
public class JavaPizza {
public static void main(String[] args) {
// create all repositories
PizzaRepository pizzaRepository = new PizzaRepository();
// create all services
PizzaService pizzaService = new PizzaService();
PizzaService pizzaService = new PizzaService(pizzaRepository);
ExtComponentService extComponentService = new ExtComponentService();
CustomerService customerService = new CustomerService();
OrderService orderService = new OrderService();
// init data
pizzaService.init();
// create controller
AppController controller = new AppController(pizzaService, extComponentService, customerService, orderService);
// run application
controller.run();
// init all data
pizzaRepository.init();
extComponentService.init();
customerService.init();
// create & run controller
new AppController(pizzaService, extComponentService, customerService, orderService)
.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@

import java.util.Scanner;

/**
* Application controller
* Implements a menu for working with the application
*
* @author Sergey Iryupin
* @version 18-Apr-24
*/
public class AppController {
private PizzaService pizzaService;
private ExtComponentService extСomponentService;
private CustomerService customerService;
private OrderService orderService;
private Scanner scanner;
private final PizzaService pizzaService;
private final ExtComponentService extСomponentService;
private final CustomerService customerService;
private final OrderService orderService;
private final Scanner scanner;

public AppController(PizzaService pizzaService,
ExtComponentService extСomponentService,
CustomerService customerService,
OrderService orderService) {
public AppController(final PizzaService pizzaService,
final ExtComponentService extСomponentService,
final CustomerService customerService,
final OrderService orderService) {
this.pizzaService = pizzaService;
this.extСomponentService = extСomponentService;
this.customerService = customerService;
Expand All @@ -27,21 +34,26 @@ public AppController(PizzaService pizzaService,

public void run() {
char cmd;
// create all controllers
PizzaController pizzaController = new PizzaController(pizzaService, scanner);
ExtComponentController extComponentController = new ExtComponentController(extСomponentService, scanner);
CustomerController customerController = new CustomerController(customerService, scanner);
OrderController orderController = new OrderController(orderService, scanner);
do {
System.out.print("Choose service: [p]izza, [e]xtcomponent, [c]ustomer, [o]rder, e[x]it: ");
cmd = scanner.nextLine().charAt(0);
switch (cmd) {
case 'p':
pizzaServiceMenu();
pizzaController.run();
break;
case 'e':
// TODO Call ExtComponentService
extComponentController.run();
break;
case 'c':
// TODO Call CustomerService
customerController.run();
break;
case 'o':
// TODO Call OrderService
orderController.run();
break;
case 'x':
break;
Expand All @@ -51,46 +63,4 @@ public void run() {
} while (cmd != 'x');
System.out.println("Exit.");
}

private void pizzaServiceMenu() {
char cmd;
String[] input;
String name, composition;
int id, price;
do {
System.out.print("Pizza service: [a]dd, [u]pdate, [d]elete, [p]rint, [b]ack: ");
cmd = scanner.nextLine().charAt(0);
switch (cmd) {
case 'a':
System.out.print("Pizza service: add: name & composition & price: ");
input = scanner.nextLine().split("&");
name = input[0].trim();
composition = input[1].trim();
price = Integer.valueOf(input[2].trim());
pizzaService.add(name, composition, price);
break;
case 'u':
System.out.print("Pizza service: update: id & name & composition & price: ");
input = scanner.nextLine().split("&");
id = Integer.valueOf(input[0].trim());
name = input[1].trim();
composition = input[2].trim();
price = Integer.valueOf(input[3].trim());
pizzaService.update(id, name, composition, price);
break;
case 'd':
System.out.print("Pizza service: delete: id: ");
id = Integer.valueOf(scanner.nextLine());
pizzaService.delete(id);
break;
case 'p':
pizzaService.print();
break;
case 'b':
break;
default:
System.out.println("Unrecognized command: " + cmd);
}
} while (cmd != 'b');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package pizza.controller;

import pizza.service.CustomerService;

import java.util.Scanner;

/**
* Pizza service controller
* Implements a menu for working with customer service
*
* @author Sergey Iryupin
* @version 18-Apr-24
*/
public class CustomerController {
private CustomerService service;
private Scanner scanner;

public CustomerController(CustomerService customerService, Scanner scanner) {
this.service = customerService;
this.scanner = scanner;
}

public void run() {
char cmd;
String[] input;
String name, address, phone;
int id;
do {
System.out.print("Pizza service: [a]dd, [u]pdate, [d]elete, [p]rint, [b]ack: ");
cmd = scanner.nextLine().charAt(0);
switch (cmd) {
case 'a':
System.out.print("Customer service: add: name & address & phone: ");
input = scanner.nextLine().split("&");
name = input[0].trim();
address = input[1].trim();
phone = input[2].trim();
service.add(name, address, phone);
break;
case 'u':
System.out.print("Customer service: update: id & name & composition & price: ");
input = scanner.nextLine().split("&");
id = Integer.valueOf(input[0].trim());
name = input[1].trim();
address = input[2].trim();
phone = input[3].trim();
service.update(id, name, address, phone);
break;
case 'd':
System.out.print("Customer service: delete: id: ");
id = Integer.valueOf(scanner.nextLine());
service.delete(id);
break;
case 'p':
service.print();
break;
case 'b':
break;
default:
System.out.println("Unrecognized command: " + cmd);
}
} while (cmd != 'b');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package pizza.controller;

import pizza.service.ExtComponentService;

import java.util.Scanner;

/**
* Pizza service controller
* Implements a menu for working with ext component service
*
* @author Sergey Iryupin
* @version 18-Apr-24
*/
public class ExtComponentController {
private ExtComponentService service;
private Scanner scanner;

public ExtComponentController(ExtComponentService service, Scanner scanner) {
this.service = service;
this.scanner = scanner;
}

public void run() {
char cmd;
String[] input;
String name;
int id, price;
do {
System.out.print("Pizza service: [a]dd, [u]pdate, [d]elete, [p]rint, [b]ack: ");
cmd = scanner.nextLine().charAt(0);
switch (cmd) {
case 'a':
System.out.print("ExtComponent service: add: name & price: ");
input = scanner.nextLine().split("&");
name = input[0].trim();
price = Integer.valueOf(input[1].trim());
service.add(name, price);
break;
case 'u':
System.out.print("ExtComponent service: update: id & name & price: ");
input = scanner.nextLine().split("&");
id = Integer.valueOf(input[0].trim());
name = input[1].trim();
price = Integer.valueOf(input[2].trim());
service.update(id, name, price);
break;
case 'd':
System.out.print("ExtComponent service: delete: id: ");
id = Integer.valueOf(scanner.nextLine());
service.delete(id);
break;
case 'p':
service.print();
break;
case 'b':
break;
default:
System.out.println("Unrecognized command: " + cmd);
}
} while (cmd != 'b');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package pizza.controller;

import pizza.service.OrderService;

import java.util.Scanner;

/**
* Pizza service controller
* Implements a menu for working with order service
*
* @author Sergey Iryupin
* @version 18-Apr-24
*/
public class OrderController {
private OrderService service;
private Scanner scanner;

public OrderController(OrderService service, Scanner scanner) {
this.service = service;
this.scanner = scanner;
}

public void run() {
char cmd;
String[] input;
int id;
do {
System.out.print("Order service: [c]reate, [d]elete, [e]dit, [p]rint, [b]ack: ");
cmd = scanner.nextLine().charAt(0);
switch (cmd) {
case 'c':
// TODO
break;
case 'd':
// TODO
break;
case 'e':
// TODO
break;
case 'p':
// TODO
break;
case 'b':
break;
default:
System.out.println("Unrecognized command: " + cmd);
}
} while (cmd != 'b');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package pizza.controller;

import pizza.service.PizzaService;

import java.util.Scanner;

/**
* Pizza service controller
* Implements a menu for working with pizza service
*
* @author Sergey Iryupin
* @version 18-Apr-24
*/
public class PizzaController {
private PizzaService service;
private Scanner scanner;

public PizzaController(PizzaService pizzaService, Scanner scanner) {
this.service = pizzaService;
this.scanner = scanner;
}

public void run() {
char cmd;
String[] input;
String name, composition;
int id, price;
do {
System.out.print("Pizza service: [a]dd, [u]pdate, [d]elete, [p]rint, [b]ack: ");
cmd = scanner.nextLine().charAt(0);
switch (cmd) {
case 'a':
System.out.print("Pizza service: add: name & composition & price: ");
input = scanner.nextLine().split("&");
name = input[0].trim();
composition = input[1].trim();
price = Integer.valueOf(input[2].trim());
service.add(name, composition, price);
break;
case 'u':
System.out.print("Pizza service: update: id & name & composition & price: ");
input = scanner.nextLine().split("&");
id = Integer.valueOf(input[0].trim());
name = input[1].trim();
composition = input[2].trim();
price = Integer.valueOf(input[3].trim());
service.update(id, name, composition, price);
break;
case 'd':
System.out.print("Pizza service: delete: id: ");
id = Integer.valueOf(scanner.nextLine());
service.delete(id);
break;
case 'p':
service.print();
break;
case 'b':
break;
default:
System.out.println("Unrecognized command: " + cmd);
}
} while (cmd != 'b');
}
}
Loading

0 comments on commit 8a25c50

Please sign in to comment.