<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # 簡介 這是一個影片出租店用的程序,計算每一個顧客的消費金額并打印詳單. 操作者告訴程序,顧客租了哪些影片,租期多長,程序便根據租賃時間和影片類型算費用,影片分三類:普通片,兒童片和新片.除了計算費用,還要為常客計算積分,積分會根據租片種類是否為新片而有不同 # 影片 ~~~ package com.refactor; /** * 影片 * 純數據類 */ public class Movice { public static final int CHILDRENS = 2; public static final int REGULAR = 0; public static final int NEW_RELEASE = 1; private String _title; private int _priceCode; public Movice(String _title, int _priceCode) { this._title = _title; this._priceCode = _priceCode; } public String getTitle() { return _title; } public void setTitle(String _title) { this._title = _title; } public int getPriceCode() { return _priceCode; } public void setPriceCode(int _priceCode) { this._priceCode = _priceCode; } } ~~~ # 租賃 ~~~ package com.refactor; /** * 租賃 * 表示某個顧客租了一部電影 */ public class Rental { //影片 private Movice _movie; private int _daysRented; public Rental(Movice _movie, int _daysRented) { this._movie = _movie; this._daysRented = _daysRented; } public Movice getMovie() { return _movie; } public int getDaysRented() { return _daysRented; } } ~~~ # 顧客 ~~~ package com.refactor; import org.junit.Test; import java.util.Enumeration; import java.util.Vector; /** * 顧客 * 有數據和訪問的函數 */ public class Customer { private String _name; //自動增長的對象數組 private Vector _rentals = new Vector(); public Customer(String _name) { this._name = _name; } public String getName() { return _name; } public void addRental(Rental arg) { _rentals.addElement(arg); } //生成詳單的函數 public String statement() { //總金額 double totalAmount = 0; //頻繁的租客 int frequentRenterPoints = 0; Enumeration rentals = _rentals.elements(); //租賃記錄 String result = "Rental Record for " + getName() + "\n"; while (rentals.hasMoreElements()) { double thisAmount = 0; Rental each = (Rental) rentals.nextElement(); //determine amounts for each line,確定每一行的金額 switch (each.getMovie().getPriceCode()) { case Movice.REGULAR: thisAmount += 2; if (each.getDaysRented() > 2) thisAmount += (each.getDaysRented() - 2) * 1.5; break; case Movice.NEW_RELEASE: thisAmount += each.getDaysRented() * 3; break; case Movice.CHILDRENS: thisAmount += 1.5; if (each.getDaysRented() > 3) thisAmount += (each.getDaysRented() - 3) * 1.5; break; } //add frequent renter points,增加頻繁的租客積分 frequentRenterPoints++; //add bonus for a two day new release rental if ((each.getMovie().getPriceCode() == Movice.NEW_RELEASE) && (each.getDaysRented() > 1)) frequentRenterPoints++; //show figures for this rental,顯示這個租金的數字 result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n"; totalAmount += thisAmount; } //add footer lines,添加頁腳線 result += "Amount owed is " + String.valueOf(totalAmount) + "\n"; result += "You earned " + String.valueOf(frequentRenterPoints) + "frequent renter points"; return result; } } ~~~ # 交互過程 ![](https://box.kancloud.cn/81a6637228eecf476816fba1e6a32ed8_529x353.png) # 對這個程序的評價 ![](https://box.kancloud.cn/8799adad8a72b1bc6668a0be60356281_674x635.png) # 總結 **如果你發現自己需要為程序添加一個特性,而代碼結構使你無法很方便地達成目的,那就先重構那個程序,使特性的添加比較容易進行,然后再添加特性 **
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看