From 928dbbb5bd0172a9b9fe4bfbf2d4103d8ffc5930 Mon Sep 17 00:00:00 2001 From: Fatima Zehra Ulu <3026753@stud.hs-mannheim.de> Date: Sun, 14 Dec 2025 23:25:52 +0100 Subject: [PATCH] Commit 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fertigstellung der Produkt Klasse; Ausgabe der Produkte in einem String; Anpassen der Importe für die Objekte --- Products.java | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Products.java diff --git a/Products.java b/Products.java new file mode 100644 index 0000000..6c8d166 --- /dev/null +++ b/Products.java @@ -0,0 +1,87 @@ +package Shop; +import java.util.*; + + public class Products { + private double grossWorth; + private String Name; + private double weight; + private double netWorth; + private double tax; + private int productID; + private int stock; + + // Constructor for the Products class + public Products(String Name, double weight, double netWorth, double tax, int stock, int productID) { + this.Name = Name; + this.weight = weight; + this.netWorth = netWorth; + this.tax = tax; + this.stock = stock; + this.productID = productID; + } + public int getProductID() { + return productID; + } + + public String getName() { + return Name; + } + + public double getWeight() { + return weight; + } + + public double getNetWorth() { + return netWorth; + } + + public double getTax() { + return tax; + } + + public int getStock() { + return stock; + } + + // Brutto Preis + public double getGrossPrice() { + return this.netWorth * (1 + this.tax / 100); + } + + // Reine Steuer + public double getTaxAmount() { + return this.getGrossPrice() - this.netWorth; + } + public String toString() { + return + "ID:" + this.productID + ", \n" //1. ID + + "Name: " + this.Name + ", \n" //2. Name + + "Gewicht: " + this.weight + " Kg, \n" //3. Gewicht + + "Preis: " + this.netWorth + " Euro, \n" //4. Nettopreis + + "MwSt-Satz: " + this.tax + " %, \n" //5. MwSt-Satz + + "Lagerbestand: "+ this.stock + " Stück"; //6. Lagerbestand + } + + + @Override + public int hashCode() { + return Objects.hash(Name, netWorth); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Products other = (Products) obj; + return Objects.equals(Name, other.Name) + && Double.doubleToLongBits(netWorth) == Double.doubleToLongBits(other.netWorth); + } + + + } + +