Fertiges produkt
ich konnte ihnen leider Keine Email schreiben sodass ich alles auf Gitty hochlademain
parent
13f6234dd1
commit
fdcb71bd46
|
|
@ -0,0 +1,47 @@
|
|||
package pckg.Backend;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Bestellung {
|
||||
// FEHLER BEHOBEN: Keine Referenz mehr auf OnlineShop, um StackOverflow zu vermeiden
|
||||
// private OnlineShop shop = new OnlineShop();
|
||||
|
||||
private String name;
|
||||
private String adresse;
|
||||
private Warenkorb warenkorb;
|
||||
private double gesamtpreis;
|
||||
|
||||
public Bestellung(String name, String adresse, Warenkorb warenkorb) {
|
||||
this.name = name;
|
||||
this.adresse = adresse;
|
||||
this.warenkorb = warenkorb;
|
||||
this.gesamtpreis = warenkorb.gesamtpreis();
|
||||
}
|
||||
|
||||
public Bestellung() {}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getAdresse() {
|
||||
return adresse;
|
||||
}
|
||||
|
||||
public Warenkorb getWarenkorb() {
|
||||
return warenkorb;
|
||||
}
|
||||
|
||||
public double getGesamtpreis() {
|
||||
return gesamtpreis;
|
||||
}
|
||||
|
||||
public void warenkorbLeeren() {
|
||||
// Wir erstellen eine Kopie der Liste, um ConcurrentModificationException zu vermeiden
|
||||
for (WarenkorbPosition wp : new ArrayList<>(warenkorb.getPositionen())) {
|
||||
warenkorb.clear(wp.getProdukt());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package pckg.Backend;
|
||||
|
||||
import pckg.Backend.Produkt;
|
||||
import pckg.Backend.Warenkorb;
|
||||
import pckg.Backend.Bestellung;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
class BestellungTest {
|
||||
|
||||
private Warenkorb warenkorb;
|
||||
private Produkt apfel;
|
||||
private Produkt birne;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
// Mock-Daten vorbereiten: Wir brauchen Produkte und einen Warenkorb
|
||||
apfel = new Produkt(1, "Apfel", 0.2, 1.50, 7, 100);
|
||||
birne = new Produkt(2, "Birne", 0.2, 2.00, 7, 100);
|
||||
|
||||
warenkorb = new Warenkorb();
|
||||
warenkorb.produktHinzufügen(apfel, 2); // 3.00€
|
||||
warenkorb.produktHinzufügen(birne, 1); // 2.00€
|
||||
// Gesamtpreis sollte 5.00€ sein
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBestellungInitialisierung() {
|
||||
Bestellung bestellung = new Bestellung("Max Mustermann", "Musterstraße 1, Berlin", warenkorb);
|
||||
|
||||
assertEquals("Max Mustermann", bestellung.getName());
|
||||
assertEquals("Musterstraße 1, Berlin", bestellung.getAdresse());
|
||||
assertEquals(5.00, bestellung.getGesamtpreis(), 0.001, "Der Gesamtpreis wurde nicht korrekt übernommen.");
|
||||
assertEquals(warenkorb, bestellung.getWarenkorb());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWarenkorbLeeren() {
|
||||
Bestellung bestellung = new Bestellung("Max Mustermann", "Musterstraße 1", warenkorb);
|
||||
|
||||
// Sicherstellen, dass der Warenkorb vor dem Leeren nicht leer ist
|
||||
assertFalse(bestellung.getWarenkorb().getPositionen().isEmpty());
|
||||
|
||||
// Methode ausführen
|
||||
bestellung.warenkorbLeeren();
|
||||
|
||||
// Prüfen, ob die Liste der Positionen jetzt leer ist
|
||||
assertTrue(bestellung.getWarenkorb().getPositionen().isEmpty(),
|
||||
"Der Warenkorb sollte nach dem Aufruf von warenkorbLeeren() leer sein.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyConstructor() {
|
||||
Bestellung leer = new Bestellung();
|
||||
assertNull(leer.getName());
|
||||
assertNull(leer.getWarenkorb());
|
||||
assertEquals(0.0, leer.getGesamtpreis());
|
||||
}
|
||||
}
|
||||
330
OnlineShop.java
330
OnlineShop.java
|
|
@ -1,147 +1,267 @@
|
|||
package Shop;
|
||||
package pckg.Backend;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
|
||||
public class OnlineShop {
|
||||
ArrayList<Products> warehouse;
|
||||
|
||||
public Object OnlineShop() throws FileNotFoundException {
|
||||
warehouse = new ArrayList<>();
|
||||
private static Warenkorb warenkorb = new Warenkorb();
|
||||
private static Scanner sc = new Scanner(System.in);
|
||||
public ArrayList<Produkt> warehouse;
|
||||
|
||||
//Einlesen
|
||||
Scanner scan = new Scanner(new File("resources/produkte.csv")); //Scanner erstellen
|
||||
scan.nextLine();
|
||||
public OnlineShop() throws FileNotFoundException {
|
||||
warehouse = new ArrayList<Produkt>();
|
||||
|
||||
while (scan.hasNextLine()) {
|
||||
String line = scan.nextLine().trim();
|
||||
String[] Parts = line.split(",");
|
||||
Scanner sc = new Scanner(new File("resources/produkte.csv"));
|
||||
sc.nextLine();
|
||||
|
||||
while(sc.hasNextLine() ) {
|
||||
String zeile = sc.nextLine();
|
||||
String[] teile = zeile.split(",");
|
||||
|
||||
if (Parts.length == 6) {
|
||||
int productID = Integer.parseInt(Parts[0].trim()); // ID ist jetzt da
|
||||
String Name = Parts[1].trim();
|
||||
double weight = Double.parseDouble(Parts[2].trim());
|
||||
double netWorth = Double.parseDouble(Parts[3].trim());
|
||||
double tax = Double.parseDouble(Parts[4].trim()); // z.B. 7.0 oder 19.0
|
||||
int stock = Integer.parseInt(Parts[5].trim());
|
||||
int id = Integer.parseInt(teile[0]);
|
||||
String name = teile[1];
|
||||
double gewicht = Double.parseDouble(teile[2]);
|
||||
double preis = Double.parseDouble(teile[3]);
|
||||
int mwst = Integer.parseInt(teile[4]);
|
||||
int bestand = Integer.parseInt(teile[5]);
|
||||
|
||||
Products prod = new Products(Name, weight, netWorth, tax, stock, productID);
|
||||
warehouse.add(prod);
|
||||
} else {
|
||||
System.err.println("Fehler beim Parsen numerischer Daten in Zeile: " + line);
|
||||
Produkt p = new Produkt(id, name, gewicht, preis, mwst, bestand);
|
||||
warehouse.add(p);
|
||||
}
|
||||
sc.close();
|
||||
}
|
||||
|
||||
}
|
||||
scan.close();
|
||||
public void angebot() throws FileNotFoundException {
|
||||
System.out.println("\n\n\nUnser Angebot: \n");
|
||||
|
||||
return null;
|
||||
}
|
||||
static String[] ProductList(){
|
||||
ArrayList<Products> warehouse;
|
||||
warehouse = new ArrayList<>();
|
||||
String[] productList = new String[warehouse.size()];
|
||||
for (int i = 0; i < warehouse.size(); i++) {
|
||||
productList[i] = warehouse.get(i).toString();
|
||||
Produkt p = warehouse.get(i);
|
||||
System.out.printf(" %-2d | %-23s | %.2f€ | + %2d%%\n", p.getId(), p.getName(), p.getPreis(), p.getMwst());
|
||||
}
|
||||
|
||||
return productList;
|
||||
System.out.println("\nWählen Sie ein Produkt anhand der Artikelnummer für Ihren Warenkorb aus \noder geben Sie 'Hauptmenü' an, wenn Sie zurück wollen: ");
|
||||
String eingabe = sc.nextLine().toLowerCase();
|
||||
|
||||
if (eingabe.equals("mainMenu") || eingabe.equals("hauptmenü")) {
|
||||
return; // Einfach zurückkehren, TUI zeigt Menü wieder an
|
||||
}
|
||||
int nummer = Integer.parseInt(eingabe);
|
||||
int index = nummer - 1;
|
||||
|
||||
if (index >= 0 && index < warehouse.size()) {
|
||||
Produkt p = warehouse.get(index);
|
||||
System.out.println("\n\n\nSie haben folgendes ausgewählt: \n" + p.getId() + " | " + p.getName());
|
||||
System.out.println("\nGeben Sie bitte die gewünschte Menge an: \n");
|
||||
int menge = Integer.parseInt(sc.nextLine());
|
||||
if (menge <= p.getBestand()) {
|
||||
warenkorb.produktHinzufügen(p, menge);
|
||||
decrease(p, menge);
|
||||
System.out.println("Das Produkt wurde in der gewünschten Menge zum Warenkorb hinzugefügt .");
|
||||
} else {
|
||||
System.out.println("Die menge im bestand ist leider nicht ausreichend für ihre Bestellung");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Ungültige Artikelnummer.");
|
||||
}
|
||||
System.out.println("Sie werden zum Hauptmenü zurück geführt\n\n\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
class OrderCustomer {
|
||||
private String CustomerName;
|
||||
private String Adress;
|
||||
private Cart cart;
|
||||
private double wholeAmount;
|
||||
public void suche() throws FileNotFoundException {
|
||||
System.out.println("\n Bitte geben sie den Artikel den Sie suchen ein?: ");
|
||||
String suchbegriff = sc.nextLine().toLowerCase();
|
||||
|
||||
public OrderCustomer(String Name, String Adress, Cart cart, double wholeAmount) {
|
||||
this.CustomerName = Name;
|
||||
this.Adress = Adress;
|
||||
this.cart = cart;
|
||||
this.wholeAmount = wholeAmount;
|
||||
if (suchbegriff.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return CustomerName;
|
||||
if (suchbegriff.equals("mainMenu")) {
|
||||
return;
|
||||
}
|
||||
boolean gefunden = false;
|
||||
|
||||
public String getAdresse() {
|
||||
return Adress;
|
||||
for (int artnr = 0; artnr < warehouse.size(); artnr++) {
|
||||
Produkt p = warehouse.get(artnr);
|
||||
|
||||
if (p.compareSearchName(suchbegriff)) {
|
||||
if(!gefunden) {
|
||||
System.out.println("\nFolgender Treffer ist vorhanden: ");
|
||||
}
|
||||
System.out.println(p);
|
||||
gefunden = true;
|
||||
|
||||
public Cart getCart() {
|
||||
return cart;
|
||||
System.out.println("\nMöchten Sie das Produkt zu Ihrem Warenkorb hinzufügen?");
|
||||
String antwort = sc.nextLine().toLowerCase();
|
||||
|
||||
if (antwort.equals("ja")) {
|
||||
System.out.println("Geben Sie bitte die gewünschte Menge an: ");
|
||||
try {
|
||||
int menge = Integer.parseInt(sc.nextLine());
|
||||
|
||||
if (menge <= p.getBestand()) {
|
||||
warenkorb.produktHinzufügen(p, menge);
|
||||
decrease(p, menge);
|
||||
System.out.println("Das Produkt wurde in der gewünschten Menge zum Warenkorb hinzugefügt, Sie werden zum Hauptmenü zurückgeleitet");
|
||||
return; // Zurück zur TUI
|
||||
} else {
|
||||
System.out.println("Die menge im bestand ist leider nicht ausreichend für ihre Bestellung,Sie werden zum Hauptmenü zurückgeleitet");
|
||||
return; // Zurück zur TUI
|
||||
}
|
||||
|
||||
public double wholeAmount() {
|
||||
return wholeAmount;
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Ungültige Menge.");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Sie werden zum Hauptmenü zurückgeleitet");
|
||||
return; // Zurück zur TUI
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!gefunden) {
|
||||
System.out.println("Leider keine Treffer,Sie werden zum Hauptmenü zurückgeleitet");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showCart() throws FileNotFoundException {
|
||||
if (warenkorb.getPositionen().size() == 0) {
|
||||
System.out.println("\n\nIhr Warenkorb ist leer, viel spaß beim shoppen , um Ihnen dieses zu erleichtern werden sie zum Hauptmenü zurück geleitet");
|
||||
return; // Zurück zur TUI
|
||||
} else {
|
||||
System.out.println("\n--------------Warenkorbübersicht-----------------------");
|
||||
System.out.println(" ");
|
||||
|
||||
Products getProductById(int ProductID) {
|
||||
int i = 0;
|
||||
while (i < warehouse.size()) {
|
||||
if (ProductID == warehouse.get(i).getProductID()) {
|
||||
return warehouse.get(i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void showProducts() {
|
||||
int i = 0;
|
||||
while (i < warehouse.size()) {
|
||||
Products p = warehouse.get(i);
|
||||
System.out.println(p.getProductID() + " | " + p.getName() + " | " +
|
||||
String.format("%.2f €", p.getGrossPrice()) + " | Bestand: " + p.getStock());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
OnlineShop.Order createOrder(String customerName, String Adress, Cart cart) {
|
||||
double net = Products.getNetWorth();
|
||||
double tax = Cart.taxDelivery();
|
||||
double gross = Cart.GrossAmountProd();
|
||||
|
||||
Order order = new Order(customerName, Adress, cart, net, tax, gross);
|
||||
cart.clear();
|
||||
return order;
|
||||
int pos = 1;
|
||||
for (WarenkorbPosition wp : warenkorb.getPositionen()) {
|
||||
System.out.printf("Pos.: %2d | %2dx | %-23s | %6.2f€ | %2d%% ݁\n",
|
||||
pos++,
|
||||
wp.getMenge(),
|
||||
wp.getProdukt().getName(),
|
||||
wp.getProdukt().getPreis(),
|
||||
wp.getProdukt().getMwst());
|
||||
}
|
||||
System.out.println("--------------------------------------------------------");
|
||||
System.out.printf("%-29s %19.2f€ ", "Nettosumme:", warenkorb.produkteNetto());
|
||||
System.out.printf("%-29s %19.2f€", "MwSt:", warenkorb.produkteMwst());
|
||||
System.out.println("--------------------------------------------------------");
|
||||
System.out.printf("%-29s %19.2f€", "Versandkosten:", warenkorb.versandNetto());
|
||||
System.out.printf("%-29s %19.2f€n", "MwSt Versand:", warenkorb.versandMwst());
|
||||
System.out.println("--------------------------------------------------------");
|
||||
System.out.printf("%-29s %19.2f€", "Gesamt Brutto:", warenkorb.gesamtpreis());
|
||||
System.out.println("--------------------------------------------------------");
|
||||
|
||||
|
||||
public static class Order {
|
||||
private String customerName;
|
||||
private String address;
|
||||
private Cart cart;
|
||||
private double net;
|
||||
private double tax;
|
||||
private double gross;
|
||||
|
||||
public Order(String customerName, String address, Cart cart, double net, double tax, double gross) {
|
||||
this.customerName = customerName;
|
||||
this.address = address;
|
||||
this.cart = cart;
|
||||
this.net = net;
|
||||
this.tax = tax;
|
||||
this.gross = gross;
|
||||
}
|
||||
System.out.println("\n\n\nMöchten Sie bestellen, die Menge ändern oder zurück zum Hauptmenü?: ");
|
||||
String eingabe = sc.nextLine().toLowerCase();
|
||||
|
||||
public void printConfirmation() {
|
||||
System.out.println("===== BESTELLBESTÄTIGUNG =====");
|
||||
System.out.println("Name: " + customerName);
|
||||
System.out.println("Adresse: " + address);
|
||||
cart.printCart();
|
||||
System.out.println("Netto: " + net + " €");
|
||||
System.out.println("MwSt: " + tax + " €");
|
||||
System.out.println("Brutto: " + gross + " €");
|
||||
switch (eingabe) {
|
||||
case "hauptmenü":
|
||||
return;
|
||||
|
||||
case "menge":
|
||||
menge();
|
||||
break;
|
||||
|
||||
case "bestellen":
|
||||
bestellen();
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("\n\nUngültige Eingabe überprüfen Sie und Versuchen Sie es bitte erneut: \n\n");
|
||||
showCart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void bestellen() throws FileNotFoundException {
|
||||
System.out.print("Bitte geben Sie Ihren vollständigen Namen ein: ");
|
||||
String name = sc.nextLine();
|
||||
|
||||
System.out.print("\nBitte geben Sie Ihre Lieferadresse ein: ");
|
||||
String adresse = sc.nextLine();
|
||||
|
||||
Bestellung bestellung = new Bestellung(name, adresse, warenkorb);
|
||||
|
||||
System.out.println("\n\n\n\n\n(\\ (\\");
|
||||
System.out.println("Danke schön für Ihre Bestellung!");
|
||||
System.out.println("----------------------------------------------------");
|
||||
System.out.println("Name: \n" + bestellung.getName());
|
||||
System.out.println("\nAdresse: \n" + bestellung.getAdresse());
|
||||
System.out.println("\nArtikel:" );
|
||||
int artpos = 1;
|
||||
for (WarenkorbPosition wp : bestellung.getWarenkorb().getPositionen()) {
|
||||
System.out.printf("Pos.: %2d. | %2d | %-23s | %.2f€\n",
|
||||
artpos++,
|
||||
wp.getMenge(),
|
||||
wp.getProdukt().getName(),
|
||||
wp.getProdukt().getPreis());
|
||||
}
|
||||
System.out.printf("\nGesamtpreis: \n%.2f€\n", bestellung.getGesamtpreis());
|
||||
System.out.println("----------------------------------------------------");
|
||||
bestellung.warenkorbLeeren();
|
||||
System.out.println("\n\nIhr Warenkorb wurde geleert! Sie können nun eine neue Bestellung beginnen " +
|
||||
"oder die Seite verlassen, dafür werden Sie zum hauptmenü zurück geführt.");
|
||||
}
|
||||
|
||||
|
||||
public void menge() throws FileNotFoundException {
|
||||
System.out.print("Welche Position möchten Sie bearbeiten?: ");
|
||||
int posNr = Integer.parseInt(sc.nextLine()) - 1;
|
||||
|
||||
if (posNr < 0 || posNr >= warenkorb.getPositionen().size()) {
|
||||
System.out.println("Ungültige Eingabe, bitte überprüfen und Versuchen Sie es bitte erneut:");
|
||||
showCart();
|
||||
return;
|
||||
}
|
||||
|
||||
WarenkorbPosition wp = warenkorb.getPositionen().get(posNr);
|
||||
Produkt p = wp.getProdukt();
|
||||
int alt = wp.getMenge();
|
||||
|
||||
System.out.print("\nGeben Sie bitte die neue Menge an: ");
|
||||
int neu = Integer.parseInt(sc.nextLine());
|
||||
int x = neu - alt;
|
||||
|
||||
if (neu == 0) {
|
||||
increase(p, alt);
|
||||
warenkorb.clear(p);
|
||||
System.out.println("Dsa Produkt an dieser Position wurde aus Dem Warenkorb gelöscht gelöscht! ");
|
||||
}
|
||||
else if (x > 0 && p.getBestand() < x) {
|
||||
System.out.println("Das gewünschte produkt ist leider nicht in dieser Masse vorhanden");
|
||||
}
|
||||
else {
|
||||
if (x > 0) decrease(p, x);
|
||||
else if (x < 0) increase(p, -x);
|
||||
warenkorb.mengeAendern(p, neu);
|
||||
System.out.println("Die Menge wurde geändert wurde zu: " + neu + "geändert. ");
|
||||
}
|
||||
showCart();
|
||||
}
|
||||
|
||||
|
||||
public boolean decrease(Produkt p, int menge) {
|
||||
for (Produkt lagerProdukt : warehouse) {
|
||||
if (lagerProdukt.getId() == p.getId()) {
|
||||
if (lagerProdukt.bestand >= menge) {
|
||||
lagerProdukt.bestand -= menge;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void increase(Produkt p, int menge) {
|
||||
for (Produkt lagerProdukt : warehouse) {
|
||||
if (lagerProdukt.getId() == p.getId()) {
|
||||
lagerProdukt.bestand += menge;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package pckg.Backend;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
class OnlineShopTest {
|
||||
|
||||
private OnlineShop shop;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
// 1. Eine temporäre Test-CSV erstellen, damit der Konstruktor nicht fehlschlägt
|
||||
File resourcesDir = new File("resources");
|
||||
if (!resourcesDir.exists()) resourcesDir.mkdir();
|
||||
|
||||
File testFile = new File("resources/produkte.csv");
|
||||
try (PrintWriter out = new PrintWriter(testFile)) {
|
||||
out.println("id,name,gewicht,preis,mwst,bestand"); // Header
|
||||
out.println("1,TestApfel,0.5,2.99,7,10"); // Test-Daten
|
||||
out.println("2,TestBirne,0.4,3.49,7,5");
|
||||
}
|
||||
|
||||
shop = new OnlineShop();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCSVLoading() {
|
||||
// Prüfen, ob die Produkte aus der CSV korrekt geladen wurden
|
||||
assertNotNull(shop.warehouse);
|
||||
assertEquals(2, shop.warehouse.size());
|
||||
assertEquals("TestApfel", shop.warehouse.get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDecreaseBestand() {
|
||||
Produkt p = shop.warehouse.get(0); // TestApfel hat Bestand 10
|
||||
|
||||
// Erfolgreiches Abziehen
|
||||
boolean success = shop.decrease(p, 3);
|
||||
assertTrue(success);
|
||||
assertEquals(7, p.getBestand());
|
||||
|
||||
// Zu viel abziehen
|
||||
boolean fail = shop.decrease(p, 20);
|
||||
assertFalse(fail);
|
||||
assertEquals(7, p.getBestand()); // Bestand darf sich nicht ändern bei Fehlschlag
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIncreaseBestand() {
|
||||
Produkt p = shop.warehouse.get(1); // TestBirne hat Bestand 5
|
||||
shop.increase(p, 10);
|
||||
assertEquals(15, p.getBestand());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package pckg.Backend;
|
||||
|
||||
public class Produkt {
|
||||
private int id;
|
||||
private String name;
|
||||
private double gewicht;
|
||||
private double preis;
|
||||
private int mwst;
|
||||
int bestand;
|
||||
|
||||
public Produkt(int id, String name, double gewicht, double preis, int mwst, int bestand) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.gewicht = gewicht;
|
||||
this.preis = preis;
|
||||
this.mwst = mwst;
|
||||
this.bestand = bestand;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public double getPreis() {
|
||||
return preis;
|
||||
}
|
||||
|
||||
public double getGewicht() {
|
||||
return gewicht;
|
||||
}
|
||||
|
||||
public int getMwst() {
|
||||
return mwst;
|
||||
}
|
||||
|
||||
public int getBestand() {
|
||||
return bestand;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return id + " | " + name + " | " + preis + "€";
|
||||
}
|
||||
|
||||
public boolean compareSearchName(String suchbegriff) {
|
||||
String n = name.toLowerCase();
|
||||
String s = suchbegriff.toLowerCase();
|
||||
|
||||
for (int i = 0; i <= n.length() - s.length(); i++) {
|
||||
if (n.startsWith(s, i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue