Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
3129ab9fd9 | |||
9536f82e1a | |||
278009f93c | |||
f1d5a8d678 | |||
![]() |
77a263ef05 |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
target/
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
9
.idea/Projekt_APO-Automat_spozywczy.iml
Normal file
9
.idea/Projekt_APO-Automat_spozywczy.iml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
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>
|
1
.idea/description.html
Normal file
1
.idea/description.html
Normal file
@ -0,0 +1 @@
|
||||
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
|
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>
|
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.apache.commons:commons-lang3:3.12.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
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>
|
16
.idea/misc.xml
Normal file
16
.idea/misc.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<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_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/untitled104.iml" filepath="$PROJECT_DIR$/untitled104.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
3
.idea/project-template.xml
Normal file
3
.idea/project-template.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
|
||||
</template>
|
10
.idea/runConfigurations.xml
Normal file
10
.idea/runConfigurations.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
124
.idea/uiDesigner.xml
Normal file
124
.idea/uiDesigner.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
29
pom.xml
Normal file
29
pom.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?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>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
37
src/main/java/apo/project/InputToCashEnum.java
Normal file
37
src/main/java/apo/project/InputToCashEnum.java
Normal file
@ -0,0 +1,37 @@
|
||||
package apo.project;
|
||||
|
||||
public enum InputToCashEnum {
|
||||
|
||||
ONE(1,20),
|
||||
TWO(2, 10),
|
||||
THREE(3, 5),
|
||||
FOUR(4, 2),
|
||||
FIVE(5, 1),
|
||||
SIX(6, 0.5),
|
||||
SEVEN(7, 0.2),
|
||||
EIGHT(8, 0.1);
|
||||
private int no;
|
||||
private double value;
|
||||
|
||||
private InputToCashEnum(int aNo, double aValue) {
|
||||
no = aNo;
|
||||
value = aValue;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getNo() {
|
||||
return no;
|
||||
}
|
||||
|
||||
public static InputToCashEnum fromNo(int aNo) {
|
||||
for (InputToCashEnum cashEnum : InputToCashEnum.values()) {
|
||||
if (cashEnum.no == aNo) {
|
||||
return cashEnum;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
144
src/main/java/apo/project/Machine.java
Normal file
144
src/main/java/apo/project/Machine.java
Normal file
@ -0,0 +1,144 @@
|
||||
package apo.project;
|
||||
|
||||
import apo.project.order.OrderService;
|
||||
import apo.project.order.OrderServiceImpl;
|
||||
import apo.project.payment.*;
|
||||
import apo.project.products.AbstractProduct;
|
||||
import apo.project.products.factory.AbstractProductsFactory;
|
||||
import apo.project.products.factory.PrepareProductsFactory;
|
||||
import apo.project.products.factory.TestProductsFactory;
|
||||
import org.apache.commons.lang3.Range;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Machine {
|
||||
|
||||
private List< Shelf< AbstractProduct > > productsInMachine;
|
||||
private PinPad pinPad;
|
||||
private CardTerminal cardTerminal;
|
||||
private TransactionProcessor transactionProcessor;
|
||||
|
||||
public Machine() {
|
||||
cardTerminal = new CardTerminal();
|
||||
pinPad = new PinPad();
|
||||
productsInMachine = new ArrayList<>();
|
||||
initMachine();
|
||||
}
|
||||
|
||||
public void showShelfs() {
|
||||
productsInMachine.forEach( shelf -> System.out.println( shelf.toString() ) );
|
||||
}
|
||||
|
||||
public void getShelfNumber() {
|
||||
int opt = pinPad.getNumber();
|
||||
Shelf< AbstractProduct > pickedShelf = productsInMachine.stream().filter( shelf -> shelf.getShelfNumber() == opt ).findFirst().orElseThrow();
|
||||
Optional< AbstractProduct > product = pickedShelf.getProduct();
|
||||
if( product.isPresent() ) {
|
||||
System.out.println( "Wybrano " + product.get().toString() );
|
||||
transactionProcessor = new TransactionProcessor( product.get(), pickedShelf );
|
||||
}
|
||||
}
|
||||
|
||||
private void initMachine() {
|
||||
List< AbstractProduct > products = new ArrayList<>();
|
||||
TestProductsFactory factory = new TestProductsFactory();
|
||||
PrepareProductsFactory productsFactory = new PrepareProductsFactory();
|
||||
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( productsFactory.create( AbstractProductsFactory.KEBAB ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 7, products ) );
|
||||
products.clear();
|
||||
|
||||
for( int i = 0; i < 5; i++ ) {
|
||||
products.add( productsFactory.create( AbstractProductsFactory.FRYTKI ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 8, products ) );
|
||||
products.clear();
|
||||
|
||||
for( int i = 0; i < 5; i++ ) {
|
||||
products.add( productsFactory.create( AbstractProductsFactory.PIZZA ) );
|
||||
}
|
||||
productsInMachine.add( new Shelf<>( 9, products ) );
|
||||
products.clear();
|
||||
}
|
||||
|
||||
public void startTransactionProcess() {
|
||||
Scanner sc = new Scanner( System.in );
|
||||
int opt = sc.nextInt();
|
||||
if( opt == 9 ) {
|
||||
// Card card = cardTerminal.getCard();
|
||||
// originally putting card object with all
|
||||
// data needed to process real payment
|
||||
transactionProcessor.processTransaction( new CardPaymentService( 0 ) );
|
||||
return;
|
||||
}
|
||||
collectMoney( opt, sc );
|
||||
}
|
||||
|
||||
private void collectMoney( int aOpt, Scanner aSc ) {
|
||||
double payment = 0;
|
||||
double productPrice = transactionProcessor.getProduct().getPrice();
|
||||
Range< Integer > moneyRange = Range.between( 3, 8 );
|
||||
Range< Integer > paperMoneyRange = Range.between( 1, 2 );
|
||||
while( payment < productPrice ) {
|
||||
if( moneyRange.contains( aOpt ) ) {
|
||||
Coin coin = new Coin( InputToCashEnum.fromNo( aOpt ).getValue() );
|
||||
transactionProcessor.collect( coin );
|
||||
payment += coin.getValue();
|
||||
} else if( paperMoneyRange.contains( aOpt ) ) {
|
||||
PaperMoney paperMoney = new PaperMoney( InputToCashEnum.fromNo( aOpt ).getValue() );
|
||||
transactionProcessor.collect( paperMoney );
|
||||
payment += paperMoney.getValue();
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
double toPay = productPrice - payment;
|
||||
if( toPay < 0 ) {
|
||||
break;
|
||||
}
|
||||
System.out.println( "Pozostało do zapłaty: " + toPay + " zł" );
|
||||
aOpt = aSc.nextInt();
|
||||
}
|
||||
transactionProcessor.processTransaction( new MoneyPaymentService() );
|
||||
}
|
||||
}
|
26
src/main/java/apo/project/Main.java
Normal file
26
src/main/java/apo/project/Main.java
Normal file
@ -0,0 +1,26 @@
|
||||
package apo.project;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Machine machine = new Machine();
|
||||
|
||||
machine.showShelfs();
|
||||
|
||||
System.out.println("Wybierz produkt (numer półki): ");
|
||||
|
||||
machine.getShelfNumber();
|
||||
|
||||
System.out.println("Wybierz metode płatności. " +
|
||||
"Użyj karty lub zacznij wrzucać " +
|
||||
"pieniądze");
|
||||
|
||||
System.out.println("Możliwe wartości do użycia: " +
|
||||
"1: 20 zł, 2: 10 zł, 3: 5 zł, 4: 2 zł, 5:" +
|
||||
" 1 zł, 6: 50 gr, 7: 20 gr, 8: 10 gr. 9: " +
|
||||
"Karta");
|
||||
|
||||
machine.startTransactionProcess();
|
||||
|
||||
}
|
||||
}
|
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;
|
||||
|
||||
class PinPad {
|
||||
private final static Scanner sc = new Scanner(System.in);
|
||||
|
||||
public int getNumber() {
|
||||
return sc.nextInt();
|
||||
}
|
||||
}
|
38
src/main/java/apo/project/Shelf.java
Normal file
38
src/main/java/apo/project/Shelf.java
Normal file
@ -0,0 +1,38 @@
|
||||
package apo.project;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
class Shelf< T extends AbstractProduct > extends ArrayList< T > {
|
||||
|
||||
private final int shelfNumber;
|
||||
|
||||
public Shelf( int aShelfNumber, List< T > aProducts ) {
|
||||
shelfNumber = aShelfNumber;
|
||||
addAll( aProducts );
|
||||
}
|
||||
|
||||
public Optional<AbstractProduct> getProduct() {
|
||||
if( isHaveProducts() ) {
|
||||
return Optional.ofNullable( get( 0 ) );
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if( isHaveProducts() ) {
|
||||
return shelfNumber + "| " + get( 0 ).toString();
|
||||
}
|
||||
return "EMPTY";
|
||||
}
|
||||
|
||||
public boolean isHaveProducts() {
|
||||
return size() > 0;
|
||||
}
|
||||
}
|
51
src/main/java/apo/project/TransactionProcessor.java
Normal file
51
src/main/java/apo/project/TransactionProcessor.java
Normal file
@ -0,0 +1,51 @@
|
||||
package apo.project;
|
||||
|
||||
import apo.project.order.OrderService;
|
||||
import apo.project.order.OrderServiceImpl;
|
||||
import apo.project.payment.*;
|
||||
import apo.project.products.AbstractProduct;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
class TransactionProcessor {
|
||||
|
||||
private final AbstractProduct product;
|
||||
private final PaperMoneyCollector paperCollector;
|
||||
private final CoinPaymentCollector coinCollector;
|
||||
private final ChangeDispatcher changeDispatcher;
|
||||
private final Shelf<AbstractProduct> shelf;
|
||||
private final OrderService orderService;
|
||||
|
||||
TransactionProcessor( AbstractProduct aProduct,
|
||||
Shelf<AbstractProduct> aShelf ) {
|
||||
product = aProduct;
|
||||
shelf = aShelf;
|
||||
paperCollector = new PaperMoneyCollector();
|
||||
coinCollector = new CoinPaymentCollector();
|
||||
changeDispatcher = new ChangeDispatcher();
|
||||
orderService = new OrderServiceImpl();
|
||||
}
|
||||
|
||||
public void processTransaction( PaymentService aPaymentService ) {
|
||||
aPaymentService.charge( product.getPrice() );
|
||||
getCustomerProduct();
|
||||
if( !aPaymentService.isMobileService() ) {
|
||||
changeDispatcher.dispatchChange();
|
||||
}
|
||||
if(shelf.isHaveProducts()) {
|
||||
orderService.order( product, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
private void getCustomerProduct() {
|
||||
shelf.remove( 0 );
|
||||
product.prepareProduct();
|
||||
}
|
||||
|
||||
public void collect( Money aMoney ) {
|
||||
if( aMoney.isCoin() ) {
|
||||
coinCollector.collect( aMoney );
|
||||
}
|
||||
paperCollector.collect( aMoney );
|
||||
}
|
||||
}
|
8
src/main/java/apo/project/order/OrderService.java
Normal file
8
src/main/java/apo/project/order/OrderService.java
Normal file
@ -0,0 +1,8 @@
|
||||
package apo.project.order;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
|
||||
public interface OrderService {
|
||||
|
||||
void order( AbstractProduct aProduct, int aQuantity);
|
||||
}
|
10
src/main/java/apo/project/order/OrderServiceImpl.java
Normal file
10
src/main/java/apo/project/order/OrderServiceImpl.java
Normal file
@ -0,0 +1,10 @@
|
||||
package apo.project.order;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
|
||||
public class OrderServiceImpl implements OrderService{
|
||||
@Override
|
||||
public void order( AbstractProduct aProduct, int aQuantity ) {
|
||||
System.out.println("Ordering product: " + aProduct.toString() + " Quantity: " + aQuantity );
|
||||
}
|
||||
}
|
20
src/main/java/apo/project/payment/CardPaymentService.java
Normal file
20
src/main/java/apo/project/payment/CardPaymentService.java
Normal file
@ -0,0 +1,20 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public class CardPaymentService implements PaymentService {
|
||||
|
||||
private final long cardNumber;
|
||||
|
||||
public CardPaymentService(long aCardNumber) {
|
||||
cardNumber = aCardNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void charge( double aValue ) {
|
||||
System.out.println("Payment from Card Service: " + aValue + " to pay. Card number: " + cardNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMobileService() {
|
||||
return true;
|
||||
}
|
||||
}
|
9
src/main/java/apo/project/payment/CardTerminal.java
Normal file
9
src/main/java/apo/project/payment/CardTerminal.java
Normal file
@ -0,0 +1,9 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public class CardTerminal {
|
||||
|
||||
/* public Card getCard() {
|
||||
// getting card number from termnial
|
||||
return cardObject;
|
||||
}*/
|
||||
}
|
12
src/main/java/apo/project/payment/ChangeDispatcher.java
Normal file
12
src/main/java/apo/project/payment/ChangeDispatcher.java
Normal file
@ -0,0 +1,12 @@
|
||||
package apo.project.payment;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeDispatcher {
|
||||
|
||||
public List<Money> dispatchChange() {
|
||||
System.out.println("Oddaje reszte");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
31
src/main/java/apo/project/payment/Coin.java
Normal file
31
src/main/java/apo/project/payment/Coin.java
Normal file
@ -0,0 +1,31 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public class Coin implements Money {
|
||||
|
||||
private final double value;
|
||||
|
||||
public Coin(double aValue) {
|
||||
value = aValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
System.out.println("Checking validation of coin");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCoin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaperMoney() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public class CoinPaymentCollector implements PaymentCollector {
|
||||
|
||||
@Override
|
||||
public void collect( Money aValue ) {
|
||||
MoneyHolder.collect( aValue );
|
||||
}
|
||||
}
|
12
src/main/java/apo/project/payment/Money.java
Normal file
12
src/main/java/apo/project/payment/Money.java
Normal file
@ -0,0 +1,12 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public interface Money {
|
||||
|
||||
boolean isValid();
|
||||
|
||||
double getValue();
|
||||
|
||||
boolean isCoin();
|
||||
|
||||
boolean isPaperMoney();
|
||||
}
|
32
src/main/java/apo/project/payment/MoneyHolder.java
Normal file
32
src/main/java/apo/project/payment/MoneyHolder.java
Normal file
@ -0,0 +1,32 @@
|
||||
package apo.project.payment;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
class MoneyHolder {
|
||||
|
||||
@Getter
|
||||
private static List<Money> coinsCollected;
|
||||
@Getter
|
||||
private static List<Money> paperMoneyCollected;
|
||||
@Getter
|
||||
private static double collectedForTransaction = 0;
|
||||
|
||||
protected static void collect(Money aMoney) {
|
||||
if(aMoney.isCoin()) {
|
||||
collectedForTransaction += aMoney.getValue();
|
||||
coinsCollected.add( aMoney );
|
||||
coinsCollected.sort( Comparator.comparing( Money::getValue ) );
|
||||
return;
|
||||
}
|
||||
collectedForTransaction += aMoney.getValue();
|
||||
paperMoneyCollected.add( aMoney );
|
||||
paperMoneyCollected.sort( Comparator.comparing( Money::getValue ) );
|
||||
}
|
||||
protected static void flushTransaction() {
|
||||
//deleting info about transaction data
|
||||
}
|
||||
}
|
14
src/main/java/apo/project/payment/MoneyPaymentService.java
Normal file
14
src/main/java/apo/project/payment/MoneyPaymentService.java
Normal file
@ -0,0 +1,14 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public class MoneyPaymentService implements PaymentService {
|
||||
@Override
|
||||
public void charge( double aValue ) {
|
||||
System.out.println("Money Payment Service " +
|
||||
"charged: " + aValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMobileService() {
|
||||
return false;
|
||||
}
|
||||
}
|
30
src/main/java/apo/project/payment/PaperMoney.java
Normal file
30
src/main/java/apo/project/payment/PaperMoney.java
Normal file
@ -0,0 +1,30 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public class PaperMoney implements Money{
|
||||
|
||||
private final double value;
|
||||
|
||||
public PaperMoney(double aValue) {
|
||||
value = aValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCoin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaperMoney() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public class PaperMoneyCollector implements PaymentCollector {
|
||||
|
||||
@Override
|
||||
public void collect( Money aValue ) {
|
||||
MoneyHolder.collect( aValue );
|
||||
}
|
||||
}
|
6
src/main/java/apo/project/payment/PaymentCollector.java
Normal file
6
src/main/java/apo/project/payment/PaymentCollector.java
Normal file
@ -0,0 +1,6 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public interface PaymentCollector {
|
||||
|
||||
void collect(Money aValue);
|
||||
}
|
8
src/main/java/apo/project/payment/PaymentService.java
Normal file
8
src/main/java/apo/project/payment/PaymentService.java
Normal file
@ -0,0 +1,8 @@
|
||||
package apo.project.payment;
|
||||
|
||||
public interface PaymentService {
|
||||
|
||||
void charge(double aValue);
|
||||
|
||||
boolean isMobileService();
|
||||
}
|
20
src/main/java/apo/project/products/AbstractProduct.java
Normal file
20
src/main/java/apo/project/products/AbstractProduct.java
Normal file
@ -0,0 +1,20 @@
|
||||
package apo.project.products;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public abstract class AbstractProduct {
|
||||
|
||||
protected String name;
|
||||
protected double price;
|
||||
|
||||
|
||||
public void prepareProduct() {
|
||||
System.out.println("Wydaje produkt");
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + ": " + price + " zł";
|
||||
}
|
||||
|
||||
}
|
29
src/main/java/apo/project/products/PrepareProduct.java
Normal file
29
src/main/java/apo/project/products/PrepareProduct.java
Normal file
@ -0,0 +1,29 @@
|
||||
package apo.project.products;
|
||||
|
||||
public class PrepareProduct extends AbstractProduct {
|
||||
|
||||
private AbstractProduct decorated;
|
||||
public PrepareProduct(AbstractProduct aProduct) {
|
||||
decorated = aProduct;
|
||||
}
|
||||
@Override
|
||||
public void prepareProduct() {
|
||||
System.out.println("Przygotowywanie produktu " + getName());
|
||||
decorated.prepareProduct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return decorated.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPrice() {
|
||||
return decorated.getPrice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return decorated.toString();
|
||||
}
|
||||
}
|
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,12 @@
|
||||
package apo.project.products.factory;
|
||||
|
||||
import apo.project.products.AbstractProduct;
|
||||
import apo.project.products.PrepareProduct;
|
||||
import apo.project.products.ProductImpl;
|
||||
|
||||
public class PrepareProductsFactory extends AbstractProductsFactory{
|
||||
@Override
|
||||
AbstractProduct createProduct( String aProductName, double aPrice ) {
|
||||
return new PrepareProduct( new ProductImpl( aProductName, 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);
|
||||
}
|
||||
}
|
17
untitled104.iml
Normal file
17
untitled104.iml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/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" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.12.0" level="project" />
|
||||
</component>
|
||||
</module>
|
Loading…
Reference in New Issue
Block a user