1 / 11

演習 : 図形クラスを定義してみよう

演習 : 図形クラスを定義してみよう. それぞれ の図形のサイズが一定であるとき、共通するメンバやメソッドをスーパークラスに書き出す。ただし、いずれのクラスも 「 面積 を返すメソッド : area( 引数 ) 」 を持つこと。. BigSquare. BigRectangle. Big Isosceles Triangle. BigCircle. 4 0 * 40 (pixel). 60 * 20 (pixel). 40 * 25 (pixel). 4 0 * 40 (pixel). SmallSquare. SmallRectangle.

branxton
Download Presentation

演習 : 図形クラスを定義してみよう

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 演習 : 図形クラスを定義してみよう それぞれの図形のサイズが一定であるとき、共通するメンバやメソッドをスーパークラスに書き出す。ただし、いずれのクラスも「面積を返すメソッド : area(引数)」を持つこと。 BigSquare BigRectangle BigIsoscelesTriangle BigCircle 40 * 40 (pixel) 60 * 20 (pixel) 40 * 25 (pixel) 40 * 40 (pixel) SmallSquare SmallRectangle SmallIsoscelesTriangle SmallCircle 10 * 10 (pixel) 30 * 10 (pixel) 25 * 15 (pixel) 15 * 15 (pixel)

  2. 演習 : 図形クラスを定義してみよう ? Shape ? Polygon ? Rectangle ? ? ? Circle IsoscelesTriangle Square SmallRectangle BigRectangle SmallSquare SmallCircle SmallIsoscelesTriangle BigSquare BigCircle BigIsoscelesTriangle

  3. 解答: 図形クラスを定義してみよう

  4. 解答: 図形クラスを定義してみよう

  5. 解答: 図形クラスを定義してみよう

  6. 演習 : Drawableインターフェイスを定義してみよう インターフェイス Drawableを定義し、それぞれの図形クラスに以下のメソッドを持たせる。 「座標(x, y)を中心に形を描画するメソッド : draw(int x, int y)」 「座標(x, y)を中心に形を描画し、塗りつぶすメソッド : drawfill(intx, int y)」 「図形の色を設定するメソッド : setColor(Color c)」 「図形の色を返すメソッド : getColor()」 ただし、「draw(int x, int y)」を実行すると“〇〇(クラス名)を(x, y)に描画”、 「drawfill(intx, int y)」を実行すると“〇〇(クラス名)を(x, y)に塗りつぶして描画”という文字列がコンソールに出力されること。 draw(int x, int y) drawfill(intx, int y) setColor(Color c) getColor() 追加

  7. 解答: Drawableインターフェイスを定義してみよう

  8. 解答: Drawableインターフェイスを定義してみよう 他のクラスも同様に コンストラクタを記述する

  9. 演習 : インターフェイスを使ってみよう 「10人の客(乗用車、バイク、ストーブのいずれかランダムに決定)に1~100(L)の給油をするガソリンスタンドをシミュレートする実行クラス : RefuelSimulation」を作成する。給油の際には、どの種類の客が何リットル給油したか出力すること。 実行結果例

  10. 解答 : インターフェイスを使ってみよう

  11. 解答 : インターフェイスを使ってみよう

More Related