Commit 2
Fertigstellung der Produkt Klasse; Ausgabe der Produkte in einem String; Anpassen der Importe für die Objektemain
parent
e4801d4c8f
commit
928dbbb5bd
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue