/** * ドメイン非依存URL出力フィルタ * javadrill.tech移行時はwp_options.home/siteurlのみ変更すればよい * * データベースには絶対URL(https://minner.asia)を保持し、 * 表示時に現在のドメイン(home_url())に動的変換する */ function javadrill_make_urls_dynamic($content) { if (empty($content)) { return $content; } // データベース内の絶対URLを現在のhome_url()に置換 $old_url = 'https://minner.asia'; $new_url = untrailingslashit(home_url()); // http版も対応(念のため) $content = str_replace($old_url, $new_url, $content); $content = str_replace('http://minner.asia', $new_url, $content); return $content; } // 投稿本文、ウィジェット、タームの説明、抜粋に適用 add_filter('the_content', 'javadrill_make_urls_dynamic', 20); add_filter('widget_text', 'javadrill_make_urls_dynamic', 20); add_filter('term_description', 'javadrill_make_urls_dynamic', 20); add_filter('get_the_excerpt', 'javadrill_make_urls_dynamic', 20); 007 クラス (クラスの作成)003 解答例 | Javaドリル

007 クラス (クラスの作成)003 解答例

007-003 007 クラス
public class Book {
    // フィールド
    private String title;
    private String author;
    private int publicationYear;

    // コンストラクタ
    public Book(String title, String author, int publicationYear) {
        this.title = title;
        this.author = author;
        this.publicationYear = publicationYear;
    }

    // ゲッターとセッター
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getPublicationYear() {
        return publicationYear;
    }

    public void setPublicationYear(int publicationYear) {
        this.publicationYear = publicationYear;
    }

    // 情報を表示するメソッド
    public void displayInfo() {
        System.out.println("Title: " + title);
        System.out.println("Author: " + author);
        System.out.println("Publication Year: " + publicationYear);
    }
}

この例では、Book クラスがタイトル、著者、出版年を保持し、それぞれの情報を取得および設定するためのゲッターとセッターを提供しています。また、displayInfo() メソッドを使用して、すべての情報をコンソールに表示する方法も示しています。自分で手を動かして、この例をもとに実際のコーディングを行ってみてください。

「007 クラス」問題集リスト

🎯 実習で理解を深めよう

この内容についてJavaDrillで実際に手を動かして学習できます

コメント

タイトルとURLをコピーしました