<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Amazon風ECサイト</title>
<style>
/* === 全体のリセットと基本スタイル === */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
color: #333;
}
img {
max-width: 100%;
height: auto;
}
button {
cursor: pointer;
border: none;
padding: 10px 15px;
border-radius: 5px;
}
a {
text-decoration: none;
color: inherit;
}
/* === ヘッダー部分 === */
header {
background-color: #232f3e;
color: white;
padding: 10px 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
header .logo {
font-size: 24px;
font-weight: bold;
}
header .search-bar {
flex: 1;
margin: 0 20px;
display: flex;
}
header .search-bar input {
width: 100%;
padding: 8px;
font-size: 16px;
border-radius: 4px 0 0 4px;
border: none;
}
header .search-bar button {
background-color: #ff9900;
color: white;
font-size: 16px;
border-radius: 0 4px 4px 0;
}
header .user-actions {
display: flex;
align-items: center;
gap: 15px;
}
header .user-actions a {
color: white;
font-size: 16px;
}
header .cart-icon {
position: relative;
}
header .cart-count {
position: absolute;
top: -5px;
right: -10px;
background-color: red;
color: white;
font-size: 12px;
border-radius: 50%;
padding: 4px 7px;
}
/* === ナビゲーションバー === */
nav {
background-color: #37475a;
padding: 10px 20px;
display: flex;
justify-content: space-around;
}
nav a {
color: white;
font-size: 16px;
}
/* === バナーセクション === */
.banner {
background-image: url('https://via.placeholder.com/1200x400');
background-size: cover;
background-position: center;
height: 400px;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
color: white;
}
.banner h1 {
font-size: 36px;
margin-bottom: 10px;
}
.banner button {
background-color: #ff9900;
border: none;
color: white;
font-size: 16px;
padding: 10px 20px;
}
/* === 商品セクション === */
.products {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: center;
padding: 20px;
}
.product {
width: 23%;
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 15px;
text-align: center;
}
.product img {
height: 150px;
object-fit: cover;
border-radius: 8px;
}
.product h3 {
font-size: 18px;
margin: 10px 0;
}
.product .price {
font-size: 16px;
color: #ff9900;
margin-bottom: 10px;
}
.product button {
background-color: #ff9900;
color: white;
font-size: 14px;
}
.product .favorite {
background-color: #e0e0e0;
color: #333;
font-size: 14px;
margin-top: 10px;
}
/* === カートポップアップ === */
.cart-popup {
position: fixed;
top: 70px;
right: 20px;
background-color: white;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
border-radius: 8px;
width: 300px;
padding: 20px;
display: none;
z-index: 1000;
}
.cart-popup h3 {
margin-bottom: 10px;
font-size: 18px;
}
.cart-popup .cart-item {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
.cart-popup .cart-item span {
font-size: 14px;
}
.cart-popup button {
width: 100%;
background-color: #ff9900;
border: none;
color: white;
padding: 10px;
font-size: 16px;
}
/* === レスポンシブ対応 === */
@media (max-width: 768px) {
.product {
width: 48%;
}
header .search-bar {
flex-direction: column;
gap: 10px;
}
}
@media (max-width: 480px) {
.product {
width: 100%;
}
}
</style>
</head>
<body>
<header>
<div class="logo">Amazon風ECサイト</div>
<div class="search-bar">
<input type="text" placeholder="商品を検索">
<button>検索</button>
</div>
<div class="user-actions">
<a href="#">ログイン</a>
<div class="cart-icon" onclick="toggleCartPopup()">
<img src="https://via.placeholder.com/32" alt="カート">
<div class="cart-count">0</div>
</div>
</div>
</header>
<nav>
<a href="#">ホーム</a>
<a href="#">カテゴリ</a>
<a href="#">セール</a>
<a href="#">おすすめ</a>
</nav>
<div class="banner">
<div>
<h1>ビッグセール開催中!</h1>
<button>セールを見る</button>
</div>
</div>
<div class="products">
<div class="product">
<img src="https://via.placeholder.com/200" alt="商品1">
<h3>商品1</h3>
<div class="price">¥3,000</div>
<button onclick="addToCart('商品1', '¥3,000')">カートに追加</button>
<button class="favorite" onclick="addToFavorite('商品1')">お気に入り</button>
</div>
<div class="product">
<img src="https://via.placeholder.com/200" alt="商品2">
<h3>商品2</h3>
<div class="price">¥5,000</div>
<button onclick="addToCart('商品2', '¥5,000')">カートに追加</button>
<button class="favorite" onclick="addToFavorite('商品2')">お気に入り</button>
</div>
</div>
<div class="cart-popup" id="cart-popup">
<h3>カートの中身</h3>
<div id="cart-items"></div>
<button onclick="checkout()">購入手続きへ</button>
</div>
<script>
let cart = [];
let favorites = [];
function addToCart(name, price) {
cart.push({ name, price });
updateCart();
alert(`${name} をカートに追加しました!`);
}
function addToFavorite(name) {
if (!favorites.includes(name)) {
favorites.push(name);
alert(`${name} をお気に入りに追加しました!`);
} else {
alert(`${name} はすでにお気に入りに追加されています!`);
}
}
function updateCart() {
const cartCount = document.querySelector('.cart-count');
const cartItems = document.getElementById('cart-items');
cartCount.textContent = cart.length;
cartItems.innerHTML = '';
cart.forEach(item => {
const div = document.createElement('div');
div.className = 'cart-item';
div.innerHTML = `<span>${item.name}</span><span>${item.price}</span>`;
cartItems.appendChild(div);
});
}
function toggleCartPopup() {
const cartPopup = document.getElementById('cart-popup');
cartPopup.style.display = cartPopup.style.display === 'block' ? 'none' : 'block';
}
function checkout() {
alert('購入手続きを開始します!');
cart = [];
updateCart();
toggleCartPopup();
}
</script>
</body>
</html>
タグ: programming
Java ジェネリクス
public class MyApp {
private static <T> void showThreeTimes(T n) {
System.out.println(n);
System.out.println(n);
System.out.println(n);
}
public static void main(String[] args) {
showThreeTimes(3);
showThreeTimes(5.2);
}
}
Java メソッド
public class MyApp {
private static void showAd() {
System.out.println("---------");
System.out.println("SALE! 50% OFF!");
System.out.println("---------");
}
private static void showContent() {
System.out.println("BREAKING NEWS!");
System.out.println("Two baby pandas born at our Zoo!");
}
public static void main(String[] args) {
showAd();
showContent();
showAd();
}
}
高度なAI風文章生成ツール
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>高度なAI風文章生成ツール</title>
<style>
/* 全体スタイル */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}
.container {
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #333;
}
textarea {
width: 100%;
height: 120px;
margin: 10px 0;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
resize: none;
}
button {
display: block;
width: 100%;
padding: 10px;
font-size: 16px;
color: white;
background-color: #007bff;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.output {
margin-top: 20px;
padding: 15px;
background: #f1f1f1;
border: 1px solid #ddd;
border-radius: 4px;
}
.loading {
text-align: center;
margin-top: 20px;
font-size: 16px;
color: #555;
}
.spinner {
width: 50px;
height: 50px;
margin: 10px auto;
border: 5px solid rgba(0, 0, 0, 0.1);
border-top-color: #007bff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="container">
<h1>高度なAI風文章生成ツール</h1>
<form id="textForm">
<label for="topic">テーマを入力してください:</label>
<textarea id="topic" placeholder="例: テクノロジーの未来"></textarea>
<button type="submit">文章を生成する</button>
</form>
<div id="loading" class="loading" style="display: none;">
<div class="spinner"></div>
文章を生成中です…お待ちください。
</div>
<div id="output" class="output" style="display: none;">
<h3>生成された文章:</h3>
<p id="generatedText"></p>
</div>
</div>
<script>
const form = document.getElementById("textForm");
const topicInput = document.getElementById("topic");
const loadingDiv = document.getElementById("loading");
const outputDiv = document.getElementById("output");
const generatedText = document.getElementById("generatedText");
// サンプルデータ(キーワードごとに分類)
const textDatabase = {
テクノロジー: [
"テクノロジーは人々の生活を大きく変える可能性があります。",
"未来の社会ではAIとロボットが主要な役割を果たすでしょう。",
"技術革新は医療、教育、環境保護の分野で重要な変化をもたらします。",
],
環境: [
"環境保護は持続可能な未来の鍵です。",
"再生可能エネルギーは地球を守る大きな手段です。",
"気候変動への対策は国際的な協力を必要とします。",
],
教育: [
"教育の未来はデジタル化により変わります。",
"オンライン学習は世界中の人々に平等な教育機会を提供します。",
"AIは個別化された学習体験を可能にします。",
],
};
// ランダムな文章を取得する関数
const getRandomText = (texts) => {
return texts[Math.floor(Math.random() * texts.length)];
};
// フォーム送信イベント
form.addEventListener("submit", (event) => {
event.preventDefault();
const topic = topicInput.value.trim();
if (!topic) {
alert("テーマを入力してください!");
return;
}
// ローディング表示
loadingDiv.style.display = "block";
outputDiv.style.display = "none";
setTimeout(() => {
// テーマから関連する文章を探す
let generated = "申し訳ありませんが、該当するデータが見つかりませんでした。";
Object.keys(textDatabase).forEach((key) => {
if (topic.includes(key)) {
generated = getRandomText(textDatabase[key]);
}
});
// 結果を表示
generatedText.textContent = `テーマ「${topic}」に基づいて生成された文章:\n\n${generated}`;
outputDiv.style.display = "block";
loadingDiv.style.display = "none";
}, 1500); // 擬似的な遅延を追加
});
</script>
</body>
</html>
株価予想AI.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>株価予測AI</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
header {
background-color: #007bff;
color: #fff;
text-align: center;
padding: 20px 10px;
}
header h1 {
margin: 0;
font-size: 24px;
}
main {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
input[type="text"], button {
font-size: 16px;
padding: 10px;
margin: 10px 0;
width: 100%;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
button {
background-color: #007bff;
color: #fff;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.result, .history {
margin-top: 20px;
}
.result p {
font-size: 18px;
margin: 8px 0;
}
canvas {
margin-top: 20px;
max-width: 100%;
}
</style>
</head>
<body>
<header>
<h1>株価予測AI</h1>
</header>
<main>
<p>株価を予測するために企業名またはティッカーシンボルを入力してください:</p>
<input type="text" id="stockInput" placeholder="例: AAPL, 7203.T">
<button onclick="predictStock()">予測する</button>
<div class="result" id="result"></div>
<canvas id="stockChart"></canvas>
<div class="history">
<h2>予測履歴</h2>
<ul id="history"></ul>
</div>
</main>
<script>
const historyList = document.getElementById('history');
const stockChartCanvas = document.getElementById('stockChart');
let stockChart;
function generateDummyData() {
// 過去1週間分のダミーデータを生成
const data = [];
for (let i = 6; i >= 0; i--) {
data.push({
date: new Date(Date.now() - i * 24 * 60 * 60 * 1000).toLocaleDateString(),
price: (Math.random() * 200 + 100).toFixed(2) // ¥100〜¥300
});
}
return data;
}
function predictStock() {
const stockSymbol = document.getElementById('stockInput').value.trim();
const resultDiv = document.getElementById('result');
// 入力チェック
if (!stockSymbol) {
resultDiv.innerHTML = "<p style='color: red;'>企業名またはティッカーシンボルを入力してください。</p>";
return;
}
// 過去の株価データを生成
const pastData = generateDummyData();
// 株価予測(ダミーデータ)
const predictedPrice = (Math.random() * 1000 + 100).toFixed(2); // ¥100〜¥1100
const change = (Math.random() * 10 - 5).toFixed(2); // -5%〜+5%の変動率
const predictionDate = new Date().toLocaleString();
// 結果を表示
resultDiv.innerHTML = `
<p><strong>${stockSymbol}</strong> の予測結果:</p>
<p>予測株価: <strong>¥${predictedPrice}</strong></p>
<p>予測変動率: <strong>${change}%</strong></p>
<p>予測日時: ${predictionDate}</p>
`;
// 履歴に追加
const historyItem = document.createElement('li');
historyItem.innerHTML = `
<strong>${stockSymbol}</strong>: ¥${predictedPrice} (${change}%) - ${predictionDate}
`;
historyList.prepend(historyItem);
// グラフを更新
updateChart(stockSymbol, pastData, predictedPrice);
// 入力欄をクリア
document.getElementById('stockInput').value = '';
}
function updateChart(symbol, pastData, predictedPrice) {
const labels = pastData.map(d => d.date);
const prices = pastData.map(d => parseFloat(d.price));
prices.push(parseFloat(predictedPrice)); // 予測値を追加
if (stockChart) {
stockChart.destroy(); // 既存のチャートを削除
}
stockChart = new Chart(stockChartCanvas, {
type: 'line',
data: {
labels: [...labels, '予測'],
datasets: [{
label: `${symbol} 株価推移`,
data: prices,
borderColor: '#007bff',
backgroundColor: 'rgba(0, 123, 255, 0.2)',
fill: true,
}]
},
options: {
responsive: true,
scales: {
x: {
title: {
display: true,
text: '日付'
}
},
y: {
title: {
display: true,
text: '株価 (¥)'
}
}
}
}
});
}
</script>
</body>
</html>
Youtube風サイト
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MyTube - 動画共有プラットフォーム</title>
<style>
/* 共通スタイル */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f9f9f9;
}
header {
background-color: #ff0000;
color: white;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
}
header .logo {
font-size: 24px;
cursor: pointer;
}
header .search-bar input {
width: 300px;
padding: 8px;
border: none;
border-radius: 4px;
}
header .search-bar button {
padding: 8px 12px;
margin-left: 5px;
background-color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
header .user-menu img {
border-radius: 50%;
}
nav {
background-color: #333;
color: white;
padding: 10px;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
}
nav ul li {
margin: 0 15px;
}
nav ul li a {
text-decoration: none;
color: white;
}
main {
padding: 20px;
}
.video-grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.video-card {
background-color: white;
border: 1px solid #ddd;
border-radius: 5px;
margin: 15px;
overflow: hidden;
width: 320px;
}
.video-card img {
width: 100%;
}
.video-card h3, .video-card p {
margin: 10px;
}
.video-player-page {
display: none;
}
.video-player {
max-width: 800px;
margin: 0 auto;
}
.video-player video {
width: 100%;
margin-bottom: 10px;
}
.recommendations ul {
list-style: none;
padding: 0;
}
.recommendations ul li {
display: flex;
margin-bottom: 10px;
}
.recommendations ul li img {
margin-right: 10px;
border-radius: 4px;
}
.comments textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
padding: 10px;
}
.comments button {
padding: 10px 15px;
background-color: #ff0000;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
footer {
background-color: #333;
color: white;
text-align: center;
padding: 20px 0;
margin-top: 20px;
}
</style>
</head>
<body>
<!-- ヘッダー -->
<header>
<div class="logo" onclick="showPage('home')">MyTube</div>
<div class="search-bar">
<input type="text" placeholder="動画を検索">
<button>検索</button>
</div>
<div class="user-menu">
<img src="https://via.placeholder.com/40" alt="ユーザーアイコン">
</div>
</header>
<nav>
<ul>
<li><a href="#" onclick="showPage('home')">ホーム</a></li>
<li><a href="#">トレンド</a></li>
<li><a href="#">音楽</a></li>
<li><a href="#">ゲーム</a></li>
<li><a href="#">ニュース</a></li>
</ul>
</nav>
<!-- ホームページ -->
<main class="video-grid" id="home-page">
<article class="video-card" onclick="showPage('video-player')">
<img src="https://via.placeholder.com/320x180" alt="Video Thumbnail">
<h3>動画タイトル1</h3>
<p>チャンネル名: ユーザーA</p>
<p>再生回数: 10,000回</p>
</article>
<article class="video-card" onclick="showPage('video-player')">
<img src="https://via.placeholder.com/320x180" alt="Video Thumbnail">
<h3>動画タイトル2</h3>
<p>チャンネル名: ユーザーB</p>
<p>再生回数: 8,500回</p>
</article>
</main>
<!-- 動画再生ページ -->
<main class="video-player-page" id="video-player-page">
<section class="video-player">
<video controls>
<source src="sample-video.mp4" type="video/mp4">
お使いのブラウザでは動画を再生できません。
</video>
<h1>動画タイトル1</h1>
<p>再生回数: 10,000回 | 投稿日: 2024年11月19日</p>
<p>チャンネル名: ユーザーA</p>
<p>動画の説明文: これは動画の説明文です。概要やリンク、関連情報をここに記載します。</p>
</section>
<aside class="recommendations">
<h2>おすすめ動画</h2>
<ul>
<li>
<a href="#" onclick="showPage('video-player')">
<img src="https://via.placeholder.com/150x100" alt="Video Thumbnail">
<p>動画タイトル2</p>
</a>
</li>
</ul>
</aside>
<section class="comments">
<h2>コメント</h2>
<form>
<textarea placeholder="コメントを追加"></textarea>
<button>送信</button>
</form>
<ul>
<li>ユーザーA: 素晴らしい動画です!</li>
<li>ユーザーB: もっと見たい!</li>
</ul>
</section>
</main>
<footer>
<p>© 2024 MyTube - 動画共有プラットフォーム</p>
</footer>
<script>
function showPage(page) {
document.getElementById('home-page').style.display = page === 'home' ? 'block' : 'none';
document.getElementById('video-player-page').style.display = page === 'video-player' ? 'block' : 'none';
}
</script>
</body>
</html>
PHP トレイト
<?php
trait LogTrait
{
public function log()
{
echo "Instance created" . PHP_EOL;
}
}
abstract class Score
{
use LogTrait;
private $subject;
protected $points;
public function __construct($subject, $points)
{
$this->subject = $subject;
$this->points = $points;
$this->log();
}
abstract protected function getResult();
public function getInfo()
{
return "{$this->subject}, {$this->points}, {$this->getResult()}";
}
}
class MathScore extends Score
{
public function __construct($points)
{
parent::__construct("Math", $points);
}
protected function getResult()
{
echo "MathScore method" . PHP_EOL;
return $this->points >= 50 ? "Pass" : "Fail";
}
}
class EnglishScore extends Score
{
public function __construct($points)
{
parent::__construct("English", $points);
}
protected function getResult()
{
echo "EnglishScore method" . PHP_EOL;
return $this->points >= 95 ? "Pass" : "Fail";
}
}
class User
{
use LogTrait;
private $name;
private $score;
public function __construct($name, $score)
{
$this->name = $name;
$this->score = $score;
$this->log();
}
public function getInfo()
{
return "{$this->name}, {$this->score->getInfo()}";
}
}
$user1 = new User("Taro", new MathScore(70));
$user2 = new User("Jiro", new EnglishScore(90));
echo $user1->getInfo() . PHP_EOL;
echo $user2->getInfo() . PHP_EOL;
PHP logメソッド
<?php
interface Loggable
{
public function log();
}
abstract class Score implements Loggable
{
private $subject;
protected $points;
public function __construct($subject, $points)
{
$this->subject = $subject;
$this->points = $points;
$this->log();
}
public function log()
{
echo "Instance created: {$this->subject}" . PHP_EOL;
}
abstract protected function getResult();
public function getInfo()
{
return "{$this->subject}, {$this->points}, {$this->getResult()}";
}
}
class MathScore extends Score
{
public function __construct($points)
{
parent::__construct("Math", $points);
}
protected function getResult()
{
echo "MathScore method" . PHP_EOL;
return $this->points >= 50 ? "Pass" : "Fail";
}
}
class EnglishScore extends Score
{
public function __construct($points)
{
parent::__construct("English", $points);
}
protected function getResult()
{
echo "EnglishScore method" . PHP_EOL;
return $this->points >= 95 ? "Pass" : "Fail";
}
}
class User implements Loggable
{
private $name;
private $score;
public function __construct($name, $score)
{
$this->name = $name;
$this->score = $score;
$this->log();
}
public function log()
{
echo "Instance created: {$this->name}" . PHP_EOL;
}
public function getInfo()
{
return "{$this->name}, {$this->score->getInfo()}";
}
}
$user1 = new User("Taro", new MathScore(70));
$user2 = new User("Jiro", new EnglishScore(90));
echo $user1->getInfo() . PHP_EOL;
echo $user2->getInfo() . PHP_EOL;
PHP 抽象メソッド
<?php
abstract class Score
{
private $subject;
protected $points;
public function __construct($subject, $points)
{
$this->subject = $subject;
$this->points = $points;
}
abstract protected function getResult();
public function getInfo()
{
return "{$this->subject}, {$this->points}, {$this->getResult()}";
}
}
class MathScore extends Score
{
public function __construct($points)
{
parent::__construct("Math", $points);
}
// protected function getResult()
// {
// echo "MathScore method" . PHP_EOL;
// return $this->points >= 50 ? "Pass" : "Fail";
// }
}
class EnglishScore extends Score
{
public function __construct($points)
{
parent::__construct("English", $points);
}
protected function getResult()
{
echo "EnglishScore method" . PHP_EOL;
return $this->points >= 95 ? "Pass" : "Fail";
}
}
class User
{
private $name;
private $score;
public function __construct($name, $score)
{
$this->name = $name;
$this->score = $score;
}
public function getInfo()
{
return "{$this->name}, {$this->score->getInfo()}";
}
}
$user1 = new User("Taro", new MathScore(70));
$user2 = new User("Jiro", new EnglishScore(90));
echo $user1->getInfo() . PHP_EOL;
echo $user2->getInfo() . PHP_EOL;
PHP 子クラス
<?php
class Score
{
private $subject;
private $points;
public function __construct($subject, $points)
{
$this->subject = $subject;
$this->points = $points;
}
private function getResult()
{
return $this->points >= 80 ? "Pass" : "Fail";
}
public function getInfo()
{
return "{$this->subject}, {$this->points}, {$this->getResult()}";
}
}
class MathScore extends Score
{
public function __construct($points)
{
parent::__construct("Math", $points);
}
}
class EnglishScore extends Score
{
public function __construct($points)
{
parent::__construct("English", $points);
}
}
class User
{
private $name;
private $score;
public function __construct($name, $score)
{
$this->name = $name;
$this->score = $score;
}
public function getInfo()
{
return "{$this->name}, {$this->score->getInfo()}";
}
}
$user1 = new User("Taro", new MathScore(70));
$user2 = new User("Jiro", new EnglishScore(90));
echo $user1->getInfo() . PHP_EOL;
echo $user2->getInfo() . PHP_EOL;
