# java 題目翻譯問題

write an inheritance hierarchy for classes Quadrilateral,Trapezoid ,parallelogram,Rectangle

and Square.Use Quadrilateral as the superclass of the hierarchy. Create and use a Point

class to represent the points in each shape. Make the hierarchy as deep(i.e.,as many

levels)as possible.Specify the instance variables and methods for each class.The private

instance variables of Quadrilateral should be the x-y coordinate pairs for the four

endpoints of the Quadrilateral.Write a program that instantiates objects of your classes and

Rating
• 10 years ago

- 在每個形狀類別裡,建立一個Point的類別來表示每個圖形的頂點.

- 盡量加深該結構的層級深度.(e.g.祖父類別,父類別,子類別,子孫類別...)

- 每一個類別裡請詳列該類別裡專有的變數和方法.

- 請編寫另一程式,可以將上述所有類別實體化(物件),並且輸出每個物件的面積.

此體目要求深度...

四邊形為父類別

不等邊四邊形也是四邊形,所以可以是四邊形的子類別

平行四邊形也能是不等邊四邊形, 所以是它的子類別

矩形也是平行四邊形, 所以是它的子類別.

正方形也算矩形的細分, 所以是它的子類別.

舉例:

private Point p1, p2, p3, p4; // 舉例

// 程式碼...

}

public void getArea(){ //body }

// 程式碼...

}

public class parallelogram extends Trapezoid{

public void getArea(){ //body }

// 程式碼...

}

public class Rectangle extends parallelogram{

public void getArea(){ //body }

// 程式碼...

}

public class Square extends Rectangle{

public void getArea(){ //body }

// 程式碼...

}

希望這樣友幫到你

豚仔

Source(s):