coffeeshop.java

来自「Java经典例程 从外国一大学计算机教授出版物下载的代码 经典」· Java 代码 · 共 51 行

JAVA
51
字号
import java.io.*;
import java.util.*;
import java.text.*;
import javagently.*;
import myutilities.*;

class CoffeeShop {

   /* A test Coffee Shop program    by J M Bishop Oct 1996
    * --------------------------    Java 1.1 October 1997
    *                               updated August 2000
    * checks that data can be read into the
    * Coffee and Batch classes, and printed out again.
    * Uses an array to store several objects of each.
    */

  public static void main (String [] args) throws IOException {

    Stream in = Filer.open("coffee.dat");

    Coffee C [ ] = new Coffee [10];
    int kind;

    // Introductory messages
    System.out.println("Nelson's Coffee Shop");
    System.out.println("Inventory control");
    System.out.println("Stocking from coffee.data");

    // Read in the data for the coffees
    for (kind=0; kind<10; kind++) {
      try {
        C[kind] = new Coffee ();
        C[kind].prepareToStock (in);
        boolean morebatches = true;
        while (morebatches)
          morebatches = C[kind].newBatchIn (in);
      }
      catch (EOFException e) {
        System.out.println("That's the shop stocked for today\n");
        break;
      }
    }

    // Display all the details
    DateFormat DF = DateFormat.getDateInstance(DateFormat.FULL);
    System.out.println("The contents on " + DF.format(new Date()));
    for (int i = 0; i<kind; i++)
      C[i].display();
  }
}

⌨️ 快捷键说明

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