私は四角形クラスの四角形の面積を計算すると仮定していますが、四角形クラスの四角形の領域を渡すことはできません。四角形の面積は、アレイで6回。 the uml diagram looks like this配列パラメータを別のクラスに渡すことはできません
私のRectangleクラス
public class Rectangle extends Shape {
Scanner in = new Scanner(System.in);
int length;
int width;
Rectangle(String name, String unit, int length, int width) {
super(name, unit);
this.length = length;
this.width = width;
}
public int getwidth() {
return this.width;
}
public int getlength() {
return this.length;
}
public void setwidth(int width) {
this.width = width;
}
public void setlength(int length) {
this.length = length;
}
@Override
public void getInput() {
}
@Override
public int getArea() {
return this.width * this.length;
}
@Override
public void display() {
super.display();
System.out.println("length:" + this.length + "width:" + this.width);
System.out.println("area is" + getArea());
}
public class Cube extends Shape {
Rectangle[] r = new Rectangle[6];
Boolean solid;
String color;
Cube(String name, String unit, Boolean solid, String color) {
super(name, unit);
this.solid = solid;
this.color = color;
}
@Override
public int getArea() {
int sum = 0;
r[0] = new Rectangle("Rectangle", "Unit1", 10, 20);
r[1] = new Rectangle("Rectangle", "Unit2", 10, 20);
r[2] = new Rectangle("Rectangle", "Unit3", 10, 20);
r[3] = new Rectangle("Rectangle", "Unit4", 10, 20);
r[4] = new Rectangle("Rectangle", "Unit5", 10, 20);
r[5] = new Rectangle("Rectangle", "Unit6", 10, 20);
for (int i = 0; i < r.length; i++) {
sum = sum + r[i];
}
return sum;
}
@Override
public void getInput() {
}
@Override
public void display() {
super.display();
System.out.println("color:" + this.color + "solid:" + this.solid);
System.out.println("sum of cube" + getArea());
}
}
}
申し訳ありませんが、あなたが何を求めているのかは不明です。配列パラメータを渡す場所で、 'Cube'クラスのコードを表示する必要があります。 –
@arfa 'キューブクラスの中で矩形の領域を渡すことはできませんが、どういう意味ですか? ' – user3437460
umlダイアグラムのリンクを見れば分かりますか? – arfa