?? coffee.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 + -