Dateien nach "/" hochladen
commit
39f51a679d
|
@ -0,0 +1,37 @@
|
|||
class Getraenk1 {
|
||||
|
||||
private String typ;
|
||||
|
||||
private boolean kohlenSaeure;
|
||||
private double liter;
|
||||
private double preis;
|
||||
|
||||
public Getraenk1(String typ, boolean kohlenSauere, double liter, double preis) {
|
||||
this.typ = typ;
|
||||
this.kohlenSaeure = kohlenSauere;
|
||||
this.liter = liter;
|
||||
this.preis = preis;
|
||||
|
||||
}
|
||||
|
||||
public double getLiter() {
|
||||
return liter;
|
||||
}
|
||||
|
||||
public double getPreis() {
|
||||
return preis;
|
||||
}
|
||||
|
||||
public void setPreis(double preis) {
|
||||
this.preis = preis;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (kohlenSaeure == true) {
|
||||
return "\n-Drink:" + typ + "\n-Mit Kohlensäure" + "\n-" + liter + " liter\n-Preis: " + preis + "€";
|
||||
} else {
|
||||
return "\n-Drink:" + typ + "\n-Ohne Kohlensäure" + "\n-" + liter + " liter\n-Preis: " + preis + "€";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Getraenkespender {
|
||||
private User user;
|
||||
private static ArrayList<User> users1 = new ArrayList<>();
|
||||
private static ArrayList<String> drinksTypen = new ArrayList<String>(
|
||||
Arrays.asList("wasser", "maracuja", "energydrink", "orange"));
|
||||
private static Scanner scanner = new Scanner(System.in);
|
||||
private Getraenk1 drink;
|
||||
|
||||
public Getraenkespender() throws FileNotFoundException {
|
||||
loadFile("src/Mitgliedschaft.csv");
|
||||
dataControl();
|
||||
login();
|
||||
if (checkAbo()) {
|
||||
System.out.println("Monatliches Abo vorhanden");
|
||||
takeOrder();
|
||||
if (drink != null) {
|
||||
System.out.println("Bitte entnehmen Sie Ihre Flasche:1 " + drink.toString());
|
||||
}
|
||||
} else {
|
||||
System.out.println("Kein monatliches Abo vorhanden.\nPreis pro 0.5l beliebiges Getränk: 1 Euro");
|
||||
takeOrder();
|
||||
if (drink != null) {
|
||||
// Guthaben aktualisieren
|
||||
double preis = drink.getLiter() * 2;
|
||||
double guthaben = user.getGuthaben() - preis;
|
||||
user.setGuthaben(guthaben);
|
||||
System.out.println(user.toString());
|
||||
System.out.println("Bitte entnehmen Sie Ihre Flasche: " + drink.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUser1(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public Getraenk1 getDrink() {
|
||||
return drink;
|
||||
}
|
||||
|
||||
public void setDrink(Getraenk1 drink) {
|
||||
this.drink = drink;
|
||||
}
|
||||
|
||||
private void login() {
|
||||
System.out.println("\n**Willkommen in fitbase**");
|
||||
while (user == null) {
|
||||
System.out.println("Geben Sie Ihr ID ein(ID = Mitgliednummer)");
|
||||
int eingabe1 = scanner.nextInt();
|
||||
findUser(eingabe1);
|
||||
}
|
||||
}
|
||||
|
||||
private void findUser(int id) {
|
||||
for (User benutzer : users1) {
|
||||
if (benutzer.getId() == id) {
|
||||
System.out.println("Zugriff gewährt für Mitglied: " + benutzer.getName() + ", Ihr Guthaben beträgt: "
|
||||
+ benutzer.getGuthaben() + "€");
|
||||
setUser1(benutzer);
|
||||
}
|
||||
}
|
||||
if (user == null) {
|
||||
System.out.println("User nicht gefunden");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAbo() {
|
||||
if (user.getAbo()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void dataControl() {
|
||||
for (User user1 : users1) {
|
||||
System.out.println(user1.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadFile(String pfad) throws FileNotFoundException {
|
||||
Scanner scanner = new Scanner(new File(pfad));
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
String[] lines = line.split(";");
|
||||
String name = lines[0];
|
||||
boolean abo = lines[1].equalsIgnoreCase("ja");
|
||||
int guthaben = Integer.parseInt(lines[2]);
|
||||
User user = new User(name, abo, guthaben);
|
||||
users1.add(user);
|
||||
}
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
private void takeOrder() {
|
||||
|
||||
String getraenk;
|
||||
String kohlenSauere;
|
||||
String liter;
|
||||
|
||||
scanner.nextLine();
|
||||
|
||||
while (drink == null) {
|
||||
ArrayList<String> order = new ArrayList<>();
|
||||
System.out.println("Bitte wählen Sie ein Getränk:");
|
||||
for (String drink : drinksTypen) {
|
||||
System.out.printf("-%s\n", drink);
|
||||
}
|
||||
getraenk = scanner.nextLine().toLowerCase();
|
||||
|
||||
if (drinksTypen.contains(getraenk)) {
|
||||
order.add(getraenk);
|
||||
} else {
|
||||
System.out.println("Ungültige Eingabe. Bitte wählen Sie ein vorhandenes Getränk.");
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println(getraenk + " soll mit oder ohne Kohlensäure? (Antwort: mit oder ohne)");
|
||||
kohlenSauere = scanner.nextLine().toLowerCase();
|
||||
|
||||
if (kohlenSauere.equals("mit") || kohlenSauere.equals("ohne")) {
|
||||
order.add(kohlenSauere);
|
||||
} else {
|
||||
System.out.println("Ungültige Eingabe. Bitte geben Sie entweder (mit) oder (ohne) ein.");
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("0.5, 1.0 oder 1.5 Liter? (Format: x.x)");
|
||||
liter = scanner.nextLine();
|
||||
|
||||
try {
|
||||
double literValue = Double.parseDouble(liter);
|
||||
if (Arrays.asList("0.5", "1.0", "1.5").contains(liter)) {
|
||||
order.add(liter);
|
||||
}
|
||||
System.out.printf("Getränk: %s, Kohlensäure: %s, Liter: %s\n", getraenk, kohlenSauere, literValue);
|
||||
|
||||
makeDrink(order);
|
||||
if (drink != null) {
|
||||
break;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Ungültige Eingabe. Bitte geben Sie eine gültige Liter-Menge ein.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void makeDrink(ArrayList<String> order) {
|
||||
boolean kohlensaeure = order.get(1).equalsIgnoreCase("mit");
|
||||
|
||||
try {
|
||||
double liter = Double.parseDouble(order.get(2));
|
||||
if (Arrays.asList(0.5, 1.0, 1.5).contains(liter)) {
|
||||
double preis = liter * 2;
|
||||
setDrink(new Getraenk1(order.get(0), kohlensaeure, liter, preis));
|
||||
} else {
|
||||
System.out.println("Ungültige Eingabe für die Liter-Menge. Bitte wählen Sie 0.5, 1.0 oder 1.5.");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Ungültige Eingabe für die Liter-Menge. Bitte geben Sie eine Zahl ein.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import java.io.FileNotFoundException;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
Getraenkespender get = new Getraenkespender();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
Michel Hombrecher;ja;0;
|
||||
Amin Bakdalia;ja;0;
|
||||
Siratullah Amiri;nein;10;
|
||||
Yousuf Almahdi;nein;12;
|
||||
Shabir Amiri;ja;0;
|
||||
Paul Becker;nein;0;
|
||||
Patrick Bateman;ja;0;
|
||||
Khabib Nurmagomedov;ja;0;
|
||||
Cristiano Ronaldo;nein;20;
|
||||
Al Pacino;ja;0;
|
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
class User {
|
||||
private int id;
|
||||
private static int mitgliedNummer = 1000;
|
||||
private String name;
|
||||
private boolean abo;
|
||||
private double guthaben;
|
||||
|
||||
public User(String name, boolean abo, int guthaben) {
|
||||
this.name = name;
|
||||
this.abo = abo;
|
||||
this.guthaben = guthaben;
|
||||
this.id = incrementId();
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public double getGuthaben() {
|
||||
return guthaben;
|
||||
}
|
||||
|
||||
public void setGuthaben(double guthaben) {
|
||||
this.guthaben = guthaben;
|
||||
}
|
||||
|
||||
private static int incrementId() {
|
||||
return mitgliedNummer++;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean getAbo() {
|
||||
return abo;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (abo == true) {
|
||||
return "Mitglied (" + id + "): " + name + ", Abo: Vorhanden" + ", Akteulles Guthaben: " + guthaben + "€";
|
||||
} else {
|
||||
return "Mitglied (" + id + "): " + name + ", Abo: nicht vorhanden" + ", Aktuelles Guthaben: " + guthaben+ "€";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue