Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ac3360c82f | ||
![]() |
f70652e7a6 | ||
![]() |
95b1bcface | ||
![]() |
fb1a69e3d3 | ||
![]() |
7ee97c9a7a | ||
![]() |
02c1d29e9f | ||
![]() |
707b932c8b | ||
![]() |
cb38d7392b | ||
![]() |
01b89d7e77 | ||
![]() |
3a1266c485 | ||
![]() |
ecf6089dbb | ||
![]() |
2d89456f54 | ||
![]() |
8b94f4945a |
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
11
.idea/Projekt_APO-Automat_spozywczy.iml
Normal file
11
.idea/Projekt_APO-Automat_spozywczy.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?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$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="openjdk-17" 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$/.idea/Projekt_APO-Automat_spozywczy.iml" filepath="$PROJECT_DIR$/.idea/Projekt_APO-Automat_spozywczy.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
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>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16
src/main/java/products/AbstractMenu.java
Normal file
16
src/main/java/products/AbstractMenu.java
Normal file
@ -0,0 +1,16 @@
|
||||
package main.java.products;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class AbstractMenu<T extends Product> extends ArrayList<T> {
|
||||
|
||||
public void showMenu() {
|
||||
showMenuName();
|
||||
for (int i = 0; i < size(); i++) {
|
||||
System.out.println(i + 1 + ". " + get(i) + " " + get(i).getPrice());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void showMenuName();
|
||||
|
||||
}
|
15
src/main/java/products/Denomination.java
Normal file
15
src/main/java/products/Denomination.java
Normal file
@ -0,0 +1,15 @@
|
||||
package main.java.products;
|
||||
|
||||
public enum Denomination {
|
||||
TEN_GR(0.1), TWENTY_GR(0.2), FIFTY_GR(0.5), ONE(1), TWO(2), FIVE(5), TEN(10), TWENTY(20), FIFTY(50), HUNDRED(100), TWO_HUNDRET(200);
|
||||
|
||||
private double denomination;
|
||||
|
||||
private Denomination(double denomination) {
|
||||
this.denomination = denomination;
|
||||
}
|
||||
|
||||
public double getDenomination() {
|
||||
return denomination;
|
||||
}
|
||||
}
|
34
src/main/java/products/Drink.java
Normal file
34
src/main/java/products/Drink.java
Normal file
@ -0,0 +1,34 @@
|
||||
package main.java.products;
|
||||
|
||||
|
||||
public class Drink implements Product {
|
||||
|
||||
private final String name;
|
||||
private final double price;
|
||||
int quantity;
|
||||
|
||||
public Drink(String aName, double aPrice, int aQuantity) {
|
||||
this.name = aName;
|
||||
this.price = aPrice;
|
||||
this.quantity = aQuantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setQuantity(int aQuantity) {
|
||||
quantity = aQuantity;
|
||||
}
|
||||
}
|
21
src/main/java/products/DrinkMenu.java
Normal file
21
src/main/java/products/DrinkMenu.java
Normal file
@ -0,0 +1,21 @@
|
||||
package main.java.products;
|
||||
|
||||
public class DrinkMenu extends AbstractMenu<Drink> {
|
||||
|
||||
DrinkMenu() {
|
||||
|
||||
Drink cola = new Drink("Cola", 4.50, 1);
|
||||
Drink water = new Drink("Water", 2.10, 5);
|
||||
Drink orangeJuice = new Drink("Orange juice", 3.50, 5);
|
||||
add(cola);
|
||||
add(water);
|
||||
add(orangeJuice);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showMenuName() {
|
||||
System.out.println("Drinks menu");
|
||||
System.out.println("Choose your drink");
|
||||
}
|
||||
}
|
200
src/main/java/products/Main.java
Normal file
200
src/main/java/products/Main.java
Normal file
@ -0,0 +1,200 @@
|
||||
package main.java.products;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
private final static Scanner sc = new Scanner(System.in);
|
||||
|
||||
public static void main(String[] aArg) {
|
||||
|
||||
useMachine();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void useMachine() {
|
||||
DrinkMenu drinkMenu = new DrinkMenu();
|
||||
SnackMenu snackMenu = new SnackMenu();
|
||||
MealMenu mealMenu = new MealMenu();
|
||||
while (true) {
|
||||
System.out.println("Welcome!\nWhat do you want to buy?");
|
||||
System.out.println("1. A drink");
|
||||
System.out.println("2. A snack");
|
||||
System.out.println("3. A meal");
|
||||
|
||||
|
||||
int selectedType = sc.nextInt();
|
||||
double price = 0;
|
||||
if (selectedType == 1) {
|
||||
Drink drink = orderADrink(drinkMenu);
|
||||
price = drink.getPrice();
|
||||
} else if (selectedType == 2) {
|
||||
Snack snack = orderASnack(snackMenu);
|
||||
price = snack.getPrice();
|
||||
} else if (selectedType == 3) {
|
||||
price = orderAMeal(mealMenu);
|
||||
}
|
||||
|
||||
System.out.println("Choose payment option");
|
||||
System.out.println("1. Cash");
|
||||
System.out.println("2. Credit card");
|
||||
|
||||
int paymentType = sc.nextInt();
|
||||
if (paymentType == 1) {
|
||||
payInCash(price);
|
||||
} else if (paymentType == 2) {
|
||||
payWithCard(price);
|
||||
}
|
||||
if (selectedType == 3) {
|
||||
System.out.println("Preparing a meal...");
|
||||
System.out.println("Take your meal");
|
||||
} else {
|
||||
System.out.println("Take your product. Thank you!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static Drink orderADrink(DrinkMenu drinkMenu) {
|
||||
drinkMenu.showMenu();
|
||||
int opt;
|
||||
Drink orderedDrink = null;
|
||||
while (orderedDrink == null) {
|
||||
opt = sc.nextInt();
|
||||
if (opt < 1 || opt > 4) {
|
||||
System.out.println("You have chosen wrong option");
|
||||
} else {
|
||||
orderedDrink = drinkMenu.get(opt - 1);
|
||||
}
|
||||
}
|
||||
System.out.println("You ordered " + orderedDrink);
|
||||
System.out.println("Price: " + orderedDrink.getPrice());
|
||||
|
||||
if (orderedDrink.getQuantity() == 1) {
|
||||
System.out.println("This was the last " + orderedDrink.toString());
|
||||
System.out.println("Notification was sent to the service staff about the lack of drink");
|
||||
drinkMenu.remove(orderedDrink);
|
||||
}
|
||||
orderedDrink.setQuantity(orderedDrink.getQuantity() - 1);
|
||||
return orderedDrink;
|
||||
}
|
||||
|
||||
private static Snack orderASnack(SnackMenu snackMenu) {
|
||||
snackMenu.showMenu();
|
||||
int opt;
|
||||
Snack orderedSnack = null;
|
||||
while (orderedSnack == null) {
|
||||
opt = sc.nextInt();
|
||||
if (opt < 1 || opt > 4) {
|
||||
System.out.println("You have chosen wrong option");
|
||||
} else {
|
||||
orderedSnack = snackMenu.get(opt - 1);
|
||||
}
|
||||
}
|
||||
System.out.println("You ordered " + orderedSnack);
|
||||
System.out.println("Price: " + orderedSnack.getPrice());
|
||||
if (orderedSnack.getQuantity() == 1) {
|
||||
System.out.println("This was the last " + orderedSnack.toString());
|
||||
System.out.println("Notification was sent to the service staff about the lack of drink");
|
||||
snackMenu.remove(orderedSnack);
|
||||
|
||||
}
|
||||
orderedSnack.setQuantity(orderedSnack.getQuantity() - 1);
|
||||
return orderedSnack;
|
||||
|
||||
}
|
||||
|
||||
private static double orderAMeal(MealMenu mealMenu) {
|
||||
mealMenu.showMenu();
|
||||
int opt;
|
||||
Meal orderedMeal = null;
|
||||
while (orderedMeal == null) {
|
||||
opt = sc.nextInt();
|
||||
if (opt < 1 || opt > 4) {
|
||||
System.out.println("You have chosen wrong option");
|
||||
} else {
|
||||
orderedMeal = mealMenu.get(opt - 1);
|
||||
}
|
||||
}
|
||||
System.out.println("You ordered " + orderedMeal);
|
||||
System.out.println("Price: " + orderedMeal.getPrice());
|
||||
if (orderedMeal.getQuantity() == 1) {
|
||||
System.out.println("This was the last " + orderedMeal.toString());
|
||||
System.out.println("Notification was sent to the service staff about the lack of meal");
|
||||
System.out.println("Staff prepared 5 new meals");
|
||||
orderedMeal.setQuantity(5);
|
||||
|
||||
}
|
||||
orderedMeal.setQuantity(orderedMeal.getQuantity() - 1);
|
||||
return orderedMeal.getPrice();
|
||||
|
||||
}
|
||||
|
||||
private static void payWithCard(double price) {
|
||||
System.out.println("Follow the instructions on the pin pad");
|
||||
System.out.println("To pay: " + price);
|
||||
System.out.println("Type 'pay' to pay");
|
||||
while (true) {
|
||||
String cardPayment = sc.nextLine();
|
||||
if (cardPayment.equals("pay")) {
|
||||
break;
|
||||
} else if (cardPayment.equals("c")) {
|
||||
cancelTransaction(price);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void payInCash(double price) {
|
||||
System.out.println("Insert a coin or banknote.");
|
||||
double sum = 0;
|
||||
|
||||
while (true) {
|
||||
String payment;
|
||||
payment = sc.next();
|
||||
if (payment.equals("c")) {
|
||||
cancelTransaction(sum);
|
||||
return;
|
||||
}
|
||||
if (Arrays.stream(Denomination.values()).anyMatch((t) -> t.getDenomination() == (Double.parseDouble(payment)))) {
|
||||
sum += Double.parseDouble(payment);
|
||||
|
||||
} else {
|
||||
System.out.println("Wrong input");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Credits: " + sum);
|
||||
if (sum == price) {
|
||||
return;
|
||||
} else if (sum > price) {
|
||||
giveChange(sum, price);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void cancelTransaction(double sum) {
|
||||
System.out.println("Take change from the dispenser: " + (sum));
|
||||
}
|
||||
|
||||
private static void giveChange(double sum, double price) {
|
||||
DecimalFormat df = new DecimalFormat("###.##");
|
||||
System.out.println("Take change from the dispenser: " + df.format((sum - price)));
|
||||
}
|
||||
|
||||
|
||||
}
|
34
src/main/java/products/Meal.java
Normal file
34
src/main/java/products/Meal.java
Normal file
@ -0,0 +1,34 @@
|
||||
package main.java.products;
|
||||
|
||||
public class Meal implements Product {
|
||||
|
||||
private final String name;
|
||||
private final double price;
|
||||
private int quantity;
|
||||
|
||||
public Meal(String aName, double aPrice, int aQuantity) {
|
||||
this.name = aName;
|
||||
this.price = aPrice;
|
||||
this.quantity = aQuantity;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(int aQuantity) {
|
||||
quantity = aQuantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
18
src/main/java/products/MealMenu.java
Normal file
18
src/main/java/products/MealMenu.java
Normal file
@ -0,0 +1,18 @@
|
||||
package main.java.products;
|
||||
|
||||
public class MealMenu extends AbstractMenu<Meal> {
|
||||
MealMenu() {
|
||||
Meal pizza = new Meal("Pizza", 15.50, 1);
|
||||
Meal spaghetti = new Meal("Spaghetti", 14.10, 5);
|
||||
Meal fries = new Meal("Fries", 6.40, 5);
|
||||
add(pizza);
|
||||
add(spaghetti);
|
||||
add(fries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showMenuName() {
|
||||
System.out.println("Meals menu");
|
||||
System.out.println("Choose your meal");
|
||||
}
|
||||
}
|
10
src/main/java/products/Product.java
Normal file
10
src/main/java/products/Product.java
Normal file
@ -0,0 +1,10 @@
|
||||
package main.java.products;
|
||||
|
||||
public interface Product {
|
||||
|
||||
double getPrice();
|
||||
|
||||
int getQuantity();
|
||||
|
||||
void setQuantity(int aQuantity);
|
||||
}
|
36
src/main/java/products/Snack.java
Normal file
36
src/main/java/products/Snack.java
Normal file
@ -0,0 +1,36 @@
|
||||
package main.java.products;
|
||||
|
||||
public class Snack implements Product {
|
||||
|
||||
private final String name;
|
||||
private final double price;
|
||||
int quantity;
|
||||
|
||||
public Snack(String aName, double aPrice, int aQuantity) {
|
||||
this.name = aName;
|
||||
this.price = aPrice;
|
||||
this.quantity = aQuantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuantity(int aQuantity) {
|
||||
quantity = aQuantity;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
19
src/main/java/products/SnackMenu.java
Normal file
19
src/main/java/products/SnackMenu.java
Normal file
@ -0,0 +1,19 @@
|
||||
package main.java.products;
|
||||
|
||||
public class SnackMenu extends AbstractMenu<Snack> {
|
||||
SnackMenu() {
|
||||
|
||||
Snack lion = new Snack("Lion", 3.50, 5);
|
||||
Snack mars = new Snack("Mars", 3.10, 5);
|
||||
Snack snickers = new Snack("Snickers", 3.40, 5);
|
||||
add(lion);
|
||||
add(mars);
|
||||
add(snickers);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showMenuName() {
|
||||
System.out.println("Snacks menu");
|
||||
System.out.println("Choose your snack");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user