⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readerrenovationcase.java

📁 Java the UML Way 书中所有源码
💻 JAVA
字号:
/*
 * ReaderRenovationCase.java   E.L. 2001-08-12
 *
 * This class has the responsibility to read input about surface,
 * wallpaper, paint and flooring, and to instantiate objects of these classes. 
 * References to these objects are returned to the client program. 
 */
import javax.swing.JOptionPane; 
import myLibrary.InputReader;  // this is the only difference to chapter 7
class ReaderRenovationCase {

  public Surface readAndInstantiateSurface() {
    String nameSurface = InputReader.inputText("The name of the surface: ");
    double lengthSurface = 
              readPositiveDecimalNumeral("The length of the surface (meter): ");
    double widthSurface  = 
              readPositiveDecimalNumeral("The width of the surface (meter): ");
    Surface aSurface = new Surface(nameSurface, lengthSurface, widthSurface);
    return aSurface;
  }

  public Paint readAndInstantiatePaint() {
    String namePaint = InputReader.inputText("Name or number to indentify this paint: ");
    double price = readPositiveDecimalNumeral("Price per liter: ");
    int noOfCoats = readPositiveIntegralNumeral("How many coats? ");
    double coverage = readPositiveDecimalNumeral("How many squaremeters per liter? ");
    Paint aPaint = new Paint(namePaint, price, noOfCoats, coverage);
    return aPaint;
  }
  
  public Wallpaper readAndInstantiateWallpaper() {
    String nameWallpaper = InputReader.inputText(
                       "Name or number to indentify this wallpaper: ");
    double pricePerRoll = readPositiveDecimalNumeral("The price per roll of wallpaper: ");
    double lengthRoll = readPositiveDecimalNumeral("The length of the roll (meter): ");
    double widthRoll = readPositiveDecimalNumeral("The width of the roll (meter): ");
    Wallpaper aWallpaper = 
                new Wallpaper(nameWallpaper, pricePerRoll, lengthRoll, widthRoll);
    return aWallpaper;
  }

  public Flooring readAndInstantiateFlooring() {
    String nameFlooring = InputReader.inputText(
                        "Name or number to indentify this flooring: ");
    double pricePerMeter = readPositiveDecimalNumeral("Price per current meter: ");
    double widthFlooring = readPositiveDecimalNumeral("Width of the flooring (meter): ");
    Flooring aFlooring = new Flooring(nameFlooring, pricePerMeter, widthFlooring);
    return aFlooring;
  }

  /* Private utility methods */
  private static int readPositiveIntegralNumeral(String prompt) {
    int number = 0;
    boolean ok = false;
    do {
      number = InputReader.inputInteger(prompt);
    } while (number <= 0);
    return number;
  }

  private static double readPositiveDecimalNumeral(String prompt) {
    double number = 0;
    boolean ok = false;
    do {
      number = InputReader.inputDecimalNumeral(prompt);
    } while (number <= 0);
    return number;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -