class Box {
private double width;
private double height;
private double depth;
Box(Box obiekt){
width=obiekt.width;
height=obiekt.height;
depth=obiekt.depth;
}
Box(double w, double h, double d){
w=width;
h=height;
d=depth;
}
Box(){
width=-1;
height=-1;
depth=-1;
}
Box(double len){
width=height=depth=len;
}
double volume() {
return width*height*depth;
}
}
class BoxWeight extends Box{
double weight;
BoxWeight(BoxWeight obiekt){
super(obiekt);
weight=obiekt.weight;
}
BoxWeight(double w, double h, double d, double m){
super(w,h,d);
weight=m;
}
BoxWeight(double len, double m){
super(len);
weight=m;
}
BoxWeight(){
super();
weight=-1;
}
}
class Shipment extends BoxWeight{
double cost;
Shipment(Shipment obiekt){
super(obiekt);
cost=obiekt.cost;
}
Shipment(double w, double h, double d, double m, double c){
super(w,h,d,m);
cost=m;
}
Shipment(double len, double m, double c){
super(len, m);
cost=c;
}
Shipment(){
super();
cost=-1;
}
}
public class DemoShipment {
public static void main(String[] args) {
double vol;
Shipment shipment1=new Shipment(10, 20, 15, 10, 3.14);
Shipment shipment2=new Shipment(2, 3, 4, 0.76, 1.28);
vol=shipment1.volume();
System.out.println("Objętość shipment1: "+vol);
System.out.println("Ciężar shipment1: "+shipment1.weight);
System.out.println("Koszt przesyłki w złotówkach:" +shipment1.cost);
vol=shipment2.volume();
System.out.println("Objętość shipment2: "+vol);
System.out.println("Ciężar shipment1: "+shipment2.weight);
System.out.println("Koszt przesyłki w złotówkach:" +shipment2.cost);
}
}
Nie wiem gdzie zrobiłem błąd ale otrzymuję złe wyniki. Zgadza się tylko ciężar. Objętość i koszt w obu przypakach pokazuję jako ciężar
Objętość shipment1: 0.0
Ciężar shipment1: 10.0
Koszt przesyłki w złotówkach:10.0
Objętość shipment2: 0.0
Ciężar shipment1: 0.76
Koszt przesyłki w złotówkach:0.76