アプリ版:「スタンプのみでお礼する」機能のリリースについて

処理内容:
以下の3つのクラスを作成し、実行し、以下の結果を得るプログラムを作成せよ。

実行例
佐藤さんの体重は、85キログラムです。




(1)抽象クラスの作成
クラス名People

name:String型、perivate宣言

getText():戻り値の型は、String
publicなabstractメソッド
getName():戻り値の型は、String
publicメソッド
People():namaeを設定するpublicなコンストラクタ



(2)抽象クラスの実装
クラス名Taiju

weight:int型
private宣言
体重を表す

Taiju():名前と体重を設定するコンストラクタ

getText():戻り値の型は、String
抽象メソッドをオーバーライドしたメソッド
「○○さんの体重は、◇kgです。」
という、文字列を返すメソッドとする。


(3)メインクラス
クラス名MainTaiju
Taijuクラスのインスタンスを、”佐藤”、85 のコンストラクで作成。
あと、出力例のように出力。

A 回答 (5件)

javascriptでコーディングすると、


<script type="text/javascript">
<!--
var People = function(arg1){
this.name = arg1;
}
var Taiju = function(arg1,arg2){
this.weight=arg2;
People.call(this, arg1);
};
Taiju.prototype = {
getName:function(){return this.name;},
getText:function(){return this.weight;}
};
var MainTaiju=new Taiju("佐藤",80);
alert(MainTaiju.getName()+'さんの体重は、' + MainTaiju.getText() + 'キログラムです。');
// -->
</script>
です。
※javascript自体には、abstractクラスの継承とか、private属性とか
がありません。prototype.jsライブラリを使えば可能みたい
    • good
    • 0

細かいミスがあったので直しました。

これで動きます。
abstract class People{
abstract function getText();
private $name=" ";
public function __construct($arg1){
$this->name = $arg1;
}
public function getName(){
return $this->name;
}
}
class Taiju extends People {
private $weight = 0;
function __construct($arg1,$arg2){
parent::__construct($arg1);
$this->weight = (integer) $arg2;
}
public function getText(){
return (string) $this->weight;
}
}
$MainTaiju = new Taiju("佐藤",80);
print $MainTaiju->getName() .'さんの体重は、' . $MainTaiju->getText() .'キログラムです。';
?>
    • good
    • 0

PHP5でコーディングすると


<?php
abstract class People{
abstract function getText();
private $name ='';
function __construct($arg1){
$this->$name = $arg1
}
public function getName(){
return $this->$name;
}
}
class Taiju extends People {
private $weight = 0;
function __construct($arg1,$arg2){
parent::construct($arg1);
$this->$weight = (integer) $arg2;
}
function getText(){
return (string) $this->$weight;
}
}
$MainTaiju = new Taiju("佐藤",80);
print $MainTaiju->getName() .'さんの体重は、' . $MainTaiju->getTex() .'キログラムです。'
?>
かな
    • good
    • 0

プログラムコードの作り方は


http://www.php.net/manual/ja/language.oop5.php
にあります。
    • good
    • 0

で、質問はなんでしょう?

    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!