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

📄 coffee.java

📁 Java经典例程 从外国一大学计算机教授出版物下载的代码 经典
💻 JAVA
字号:
import java.io.*;
import java.util.*;
import javagently.*;
import java.text.*;

class Coffee {

  /*  The Coffee class        by J M bishop Oct 1996
   *  ----------------        Java 1.1 October 1997
   *                          updated August 2000
   *  keeps an inventory of batches of coffee of a
   *  particular kind
   */

  Coffee () {
  }

  Coffee (String s) {
    name = new String (s);
  };

  void prepareToStock (Stream in)
             throws IOException {
    name = in.readString();
    price = in.readDouble();
    reorder = in.readInt();
    batches = 0;
    stock = 0;
  }

  boolean newBatchIn (Stream in) throws IOException {
    double amount;
    Date sellby;
    String s;

    amount = in.readDouble();
    if (amount == 0) // batch completed
      return false;
    else {
      stock += amount;
      sellby = new Date ();
      s = in.readString();
      try {
        sellby = DF.parse(s);
      } catch (ParseException e) {
        System.out.println("Error in date " + s);
      }
      B[batches] = new Batch (amount,sellby);
      batches ++;
      return true;
    }
  }

  void display () {
    System.out.println(name+" @ G"+
           Stream.format(price,1,2)+" per kg");
    for (int i = 0; i < batches; i++) {
      B[i].display ();
    }
    System.out.println("\t" + Stream.format(stock,1,1) +
           "kg in stock. Reorder level is "
           +reorder+"kg\n");
  }

  private String name;
  private double price;   // per kg
  private double stock; // kgs
  private double reorder; // kgs;
  private Batch B [ ] = new Batch [10];
  private int batches = 0;
  private DateFormat DF = DateFormat.getDateInstance(DateFormat.DEFAULT,
				  Locale.UK);

}

⌨️ 快捷键说明

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