PHPのテストです。
チャンネルは1から12の間で設定してください。<?php $tv = new Television(); $tv->setChannel(20); print('現在のチャンネルは '.$tv->getChannel().'<br />' ); $tv->setChannel(10); print('現在のチャンネルは '.$tv->getChannel().'<br />' ); class Television { private $channelNo = 8; const MAX_CHANNEL = 12; const MIN_CHANNEL = 1; const ERROR_MSG = ' チャンネルは1から12の間で設定してください。
'; public function setChannel( $channel ) { if ( ($channel >= self::MIN_CHANNEL) and ($channel <= self::MAX_CHANNEL) ) { $this->channelNo = $channel; } else { print( self::ERROR_MSG ); } } public function getChannel() { return $this->channelNo; } } ?>