Add init of products into machine
This commit is contained in:
parent
77a263ef05
commit
f1d5a8d678
16
.idea/compiler.xml
Normal file
16
.idea/compiler.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="untitled104" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="untitled104" target="11" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
20
.idea/jarRepositories.xml
Normal file
20
.idea/jarRepositories.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
13
.idea/libraries/Maven__org_projectlombok_lombok_1_18_22.xml
Normal file
13
.idea/libraries/Maven__org_projectlombok_lombok_1_18_22.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.projectlombok:lombok:1.18.22">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.22/lombok-1.18.22-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.22/lombok-1.18.22-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -1,12 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectKey">
|
||||
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -6,4 +6,3 @@
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
24
pom.xml
Normal file
24
pom.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>APO</groupId>
|
||||
<artifactId>APO</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,8 +0,0 @@
|
||||
package apo.project;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// write your code here
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package apo.project;
|
||||
|
||||
public interface OrderService {
|
||||
|
||||
void order(Products aProduct, int aQuantity);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package apo.project;
|
||||
|
||||
public interface Products {
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package apo.project;
|
||||
|
||||
public interface Shelf {
|
||||
|
||||
boolean haveProducts();
|
||||
}
|
81
src/main/java/apo/project/Machine.java
Normal file
81
src/main/java/apo/project/Machine.java
Normal file
@ -0,0 +1,81 @@
|
||||
package apo.project;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
import apo.project.products.factory.AbstractProductsFactory;
|
||||
import apo.project.products.factory.TestProductsFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Machine {
|
||||
|
||||
private List< Shelf< AbstractProduct > > productsInMachine;
|
||||
|
||||
public Machine() {
|
||||
productsInMachine = new ArrayList<>();
|
||||
initMachine();
|
||||
}
|
||||
|
||||
public void showShelfs() {
|
||||
productsInMachine.forEach( shelf -> System.out.println(shelf.toString()) );
|
||||
}
|
||||
|
||||
private void initMachine() {
|
||||
List<AbstractProduct> products = new ArrayList<>();
|
||||
TestProductsFactory factory = new TestProductsFactory();
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory.COLA ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 1, products ) );
|
||||
products.clear();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory.PEPSI ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 2, products ) );
|
||||
products.clear();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory.FANTA ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 3, products ) );
|
||||
products.clear();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory.TWIX ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 4, products ) );
|
||||
products.clear();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory.KITKAT ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 5, products ) );
|
||||
products.clear();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory._3BIT ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 6, products ) );
|
||||
products.clear();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory.KEBAB ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 7, products ) );
|
||||
products.clear();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory.FRYTKI ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 8, products ) );
|
||||
products.clear();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
products.add( factory.create( AbstractProductsFactory.PIZZA ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 9, products ) );
|
||||
products.clear();
|
||||
}
|
||||
|
||||
}
|
16
src/main/java/apo/project/Main.java
Normal file
16
src/main/java/apo/project/Main.java
Normal file
@ -0,0 +1,16 @@
|
||||
package apo.project;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Machine machine = new Machine();
|
||||
PinPad pinPad = new PinPad();
|
||||
|
||||
machine.showShelfs();
|
||||
|
||||
System.out.println("Wybierz produkt (numer półki)");
|
||||
|
||||
int opt = pinPad.getNumber();
|
||||
|
||||
}
|
||||
}
|
8
src/main/java/apo/project/OrderService.java
Normal file
8
src/main/java/apo/project/OrderService.java
Normal file
@ -0,0 +1,8 @@
|
||||
package apo.project;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
|
||||
public interface OrderService {
|
||||
|
||||
void order( AbstractProduct aProduct, int aQuantity);
|
||||
}
|
11
src/main/java/apo/project/PinPad.java
Normal file
11
src/main/java/apo/project/PinPad.java
Normal file
@ -0,0 +1,11 @@
|
||||
package apo.project;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class PinPad {
|
||||
private final static Scanner sc = new Scanner(System.in);
|
||||
|
||||
public int getNumber() {
|
||||
return sc.nextInt();
|
||||
}
|
||||
}
|
32
src/main/java/apo/project/Shelf.java
Normal file
32
src/main/java/apo/project/Shelf.java
Normal file
@ -0,0 +1,32 @@
|
||||
package apo.project;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class Shelf<T extends AbstractProduct > extends ArrayList<T> {
|
||||
|
||||
private final int shelfNumber;
|
||||
|
||||
public Shelf( int aShelfNumber, List<T> aProducts ) {
|
||||
shelfNumber = aShelfNumber;
|
||||
addAll( aProducts );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(isHaveProducts()) {
|
||||
return shelfNumber + "| " + get( 0 ).toString();
|
||||
}
|
||||
return "EMPTY";
|
||||
}
|
||||
|
||||
public boolean isHaveProducts() {
|
||||
return size() > 0;
|
||||
}
|
||||
}
|
17
src/main/java/apo/project/products/AbstractProduct.java
Normal file
17
src/main/java/apo/project/products/AbstractProduct.java
Normal file
@ -0,0 +1,17 @@
|
||||
package apo.project.products;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public abstract class AbstractProduct {
|
||||
|
||||
protected String name;
|
||||
protected double price;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + ": " + price;
|
||||
}
|
||||
|
||||
}
|
9
src/main/java/apo/project/products/ProductImpl.java
Normal file
9
src/main/java/apo/project/products/ProductImpl.java
Normal file
@ -0,0 +1,9 @@
|
||||
package apo.project.products;
|
||||
|
||||
public class ProductImpl extends AbstractProduct{
|
||||
|
||||
public ProductImpl(String aProductName, double aPrice) {
|
||||
name = aProductName;
|
||||
price = aPrice;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package apo.project.products.factory;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
|
||||
public abstract class AbstractProductsFactory {
|
||||
|
||||
public static final String COLA = "Cola";
|
||||
public static final String PEPSI = "Pepsi";
|
||||
public static final String FANTA = "Fanta";
|
||||
public static final String TWIX = "TWIX";
|
||||
public static final String _3BIT = "3bit";
|
||||
public static final String KITKAT = "Kitkat";
|
||||
public static final String KEBAB = "Kebab";
|
||||
public static final String FRYTKI = "Frytki";
|
||||
public static final String PIZZA = "Pizza";
|
||||
|
||||
public AbstractProduct create( String aProductName ) {
|
||||
switch( aProductName ) {
|
||||
case COLA:
|
||||
case PEPSI:
|
||||
return createProduct(aProductName, 1.50);
|
||||
case FANTA:
|
||||
return createProduct(aProductName, 2.00);
|
||||
case TWIX:
|
||||
return createProduct(aProductName, 2.50);
|
||||
case _3BIT:
|
||||
return createProduct(aProductName, 2.20);
|
||||
case KITKAT:
|
||||
return createProduct(aProductName, 2.10);
|
||||
case KEBAB:
|
||||
return createProduct(aProductName, 10.20);
|
||||
case FRYTKI:
|
||||
return createProduct(aProductName, 6.80);
|
||||
case PIZZA:
|
||||
return createProduct(aProductName, 14.50);
|
||||
}
|
||||
throw new IllegalArgumentException( "There is no such product" );
|
||||
}
|
||||
|
||||
abstract AbstractProduct createProduct(String aProductName, double aPrice);
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package apo.project.products.factory;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
import apo.project.products.ProductImpl;
|
||||
|
||||
public class TestProductsFactory extends AbstractProductsFactory{
|
||||
@Override
|
||||
AbstractProduct createProduct( String aProductName, double aPrice ) {
|
||||
return new ProductImpl(aProductName, aPrice);
|
||||
}
|
||||
}
|
BIN
target/classes/apo/project/Machine.class
Normal file
BIN
target/classes/apo/project/Machine.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/Main.class
Normal file
BIN
target/classes/apo/project/Main.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/OrderService.class
Normal file
BIN
target/classes/apo/project/OrderService.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/PinPad.class
Normal file
BIN
target/classes/apo/project/PinPad.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/Shelf.class
Normal file
BIN
target/classes/apo/project/Shelf.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/payment/CoinHolder.class
Normal file
BIN
target/classes/apo/project/payment/CoinHolder.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/payment/PaymentCollector.class
Normal file
BIN
target/classes/apo/project/payment/PaymentCollector.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/payment/PaymentService.class
Normal file
BIN
target/classes/apo/project/payment/PaymentService.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/products/AbstractProduct.class
Normal file
BIN
target/classes/apo/project/products/AbstractProduct.class
Normal file
Binary file not shown.
BIN
target/classes/apo/project/products/ProductImpl.class
Normal file
BIN
target/classes/apo/project/products/ProductImpl.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,12 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.22" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user