Beispielhafte Menüstruktur hinzugefügt.
parent
1fa6523125
commit
17ddeab07c
|
|
@ -10,6 +10,8 @@ public class OnlineShop {
|
|||
|
||||
// TODO: Hier sollte die Produktliste geladen werden, vgl. Sudoku
|
||||
lager.add(new Produkt("Wein", 4.99));
|
||||
lager.add(new Produkt("Wasser", 0.79));
|
||||
lager.add(new Produkt("Gieskanne", 6.99));
|
||||
}
|
||||
|
||||
public String[] produktListe() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package de.th_mannheim.informatik.shop.backend;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Produkt {
|
||||
String name;
|
||||
private String name;
|
||||
double preis;
|
||||
|
||||
public Produkt(String name, double preis) {
|
||||
|
|
@ -9,18 +11,50 @@ public class Produkt {
|
|||
this.preis = preis;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String neu) {
|
||||
this.name = neu;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name + " " + this.preis + " Euro.";
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(Produkt o) {
|
||||
if (!(o instanceof Produkt))
|
||||
return false;
|
||||
|
||||
if (o == null)
|
||||
return false;
|
||||
|
||||
if (!this.name.equals(((Produkt)o).name)
|
||||
|| this.preis != ((Produkt)o).preis)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, preis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Produkt other = (Produkt) obj;
|
||||
return Objects.equals(name, other.name)
|
||||
&& Double.doubleToLongBits(preis) == Double.doubleToLongBits(other.preis);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,23 @@ import org.junit.jupiter.api.Test;
|
|||
class ProduktTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
void testEquals() {
|
||||
Produkt p1 = new Produkt("Wein", 3.50);
|
||||
Produkt p2 = new Produkt("Wein", 3.50);
|
||||
|
||||
assertTrue(p1.equals(p2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructor() {
|
||||
Produkt p1 = new Produkt("Wein", 3.50);
|
||||
Produkt p2 = new Produkt("Wasser", 0.99);
|
||||
|
||||
assertEquals("Wein", p1.getName());
|
||||
assertEquals("Wasser", p2.getName());
|
||||
|
||||
assertEquals(3.50, p1.preis);
|
||||
assertEquals(0.99, p2.preis);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +1,51 @@
|
|||
package de.th_mannheim.informatik.shop.tui;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import de.th_mannheim.informatik.shop.backend.OnlineShop;
|
||||
|
||||
public class ShoppingTUI {
|
||||
private static OnlineShop shop;
|
||||
|
||||
private static Scanner kb;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Willkommen beim THMA SuperStore!");
|
||||
|
||||
shop = new OnlineShop();
|
||||
|
||||
// TODO: Hauptmenü aufrufen, am besten in einer Schleife
|
||||
|
||||
produktangebot(); // nur als Beispiel, bitte hier entfernen
|
||||
|
||||
System.out.println("Auf Wiedersehen!");
|
||||
shop = new OnlineShop();
|
||||
kb = new Scanner(System.in);
|
||||
|
||||
hauptmenü();
|
||||
|
||||
System.out.println("Auf Wiedersehen!");
|
||||
}
|
||||
|
||||
public static void hauptmenü() {
|
||||
// TODO: hier ein erstes Menü mit bspw.
|
||||
// Produktangebot
|
||||
// Produktsuche
|
||||
// Warenkorbanzeige
|
||||
// evtl. Bestellung (kann auch über Warenkorb realisiert werden)
|
||||
// Exit
|
||||
String eingabe;
|
||||
|
||||
do {
|
||||
System.out.println("Hauptmenü");
|
||||
System.out.println("1: Produktübersicht");
|
||||
System.out.println("2: Produktsuche");
|
||||
System.out.println("-> Tippen Sie exit zum Beenden.");
|
||||
System.out.print("> ");
|
||||
|
||||
eingabe = kb.nextLine();
|
||||
|
||||
switch (eingabe) {
|
||||
case "1": produktangebot(); break;
|
||||
case "2": System.out.println("to be implemented.");
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
} while(!eingabe.equalsIgnoreCase("exit"));
|
||||
}
|
||||
|
||||
public static void produktangebot() {
|
||||
System.out.println("Unser Produktangebot:");
|
||||
System.out.println();
|
||||
|
||||
String[] produkte = shop.produktListe();
|
||||
String[] produkte = shop.produktListe(); // Aufruf API-Methode des Shops
|
||||
|
||||
for (int i = 0; i < produkte.length; i++)
|
||||
System.out.println((i+1) + ". " + produkte[i]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue