平成15年 春期 基本情報技術者 午後 問08
問08 Java次の Java プログラムの説明及びプログラムを読んで,設問に答えよ。 〔プログラムの説明〕 図形の面積を計算し,その結果を出力するプログラムである。 図形は,三角形,長方形及び正方形のいずれかであり,プログラムでは, 次の属性をもつ図形オブジェクトとして定める。 三角形:3辺の長さ 長方形:縦と横の2辺の長さ 正方形:1辺の長さ AreaTest (1) 三角形,長方形及び正方形のオブジェクトを生成し,配列 figures に設定する。 (2) 各図形の面積を求めて,結果を出力する。 ここで,各図形には,正しい図形となる数値が与えられているものとする。 Figure Triangle Rectangle Square
図 実行結果
public class AreaTest {
public static void main(String args[]) {
Figure[] figures = {
new Triangle(2, 3, 3),
new Rectangle(5, 8),
new Square(5)};
for (int i = 0; i < figures.length; i++) {
System.out.println(figures[i] +
"area = " + figures[i].getArea());
}
}
}
〔プログラム 2〕
public abstract class Figure {
public abstract double getArea();
}
〔プログラム 3〕 public class Triangle extends 〔プログラム 4〕 public class Rectangle extends 〔プログラム 5〕 public class Square extends 設問 プログラム中の
a,b,d に関する解答群 ア abstract イ Figure ウ getArea エ Rectangle オ Square カ super c に関する解答群 ア height イ height * height ウ height * width エ width オ width * width e に関する解答群 ア super(height) イ super(height, height) ウ super(width) エ super(width, height) オ super(width, width) カ this.height = height キ this.height = width ク this.width = height ケ this.width = width
[←前の問題] [次の問題→] [問題一覧表] [分野別] [基本情報技術者試験TOP ]
©2004-2025 情報処理試験.jp
|
プライバシーポリシー・著作権・リンク
|
お問合わせ
| |
