资源简介
SSD3所有exercise的答案,很全面

代码片段和文件信息
import java.io.*;
import java.util.*;
/* DOCUMENT THIS CLASS */
public class ShoppingCartApplication {
private static BufferedReader stdIn =
new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter stdOut =
new PrintWriter(System.out true);
private static PrintWriter stdErr =
new PrintWriter(System.err true);
private ShoppingCart cart;
/* DOCUMENT THIS PUBLIC METHOD */
public static void main(String[] args) throws IOException {
ShoppingCartApplication application = new ShoppingCartApplication();
application.run();
}
private void run() throws IOException {
cart = new ShoppingCart();
int choice = getChoice();
while (choice != 0) {
if (choice == 1) {
cart.addProduct(readProduct());
} else if (choice == 2) {
stdOut.println(cart.toString());
} else if (choice == 3) {
stdOut.println(cart.getTotalValue());
}
choice = getChoice();
}
}
private int getChoice() throws IOException {
do {
int input;
try {
stdErr.println();
stdErr.print(“[0] Quit\n“
+ “[1] Add Product\n“
+ “[2] Display Products\n“
+ “[3] Display Total\n“
+ “choice>“);
stdErr.flush();
input = Integer.parseInt(stdIn.readLine());
if (0 <= input && 3 >= input) {
return input;
} else {
stdErr.println(“Invalid choice: “ + input);
}
} catch (NumberFormatException nfe) {
stdErr.println(nfe);
}
} while (true);
}
private Product readProduct() throws IOException {
final String DELIM = “_“;
String name = ““;
int quantity = 0;
double price = 0.0;
/* PLACE YOUR CODE HERE */
do{
try{
stdErr.println(“product [product name_qty_price]“);
StringTokenizer tokenizer=new StringTokenizer(stdIn.readLine()DELIM);
if(tokenizer.countTokens()==3){
name=tokenizer.nextToken();
quantity=Integer.parseInt(tokenizer.nextToken());
price=Double.parseDouble(tokenizer.nextToken());
if(quantity<=0||price<0) stdErr.println(“Invalid input“);
else break;
}else stdErr.println(“Invalid input“);
}catch(NumberFormatException m){
stdErr.println(m);
}
}while(true);
return new Product(name quantity price);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3435 2010-11-14 17:04 excercise\excercise 1\exe-shopping-cart.jar
文件 934 2006-01-10 16:51 excercise\excercise 1\student-files\Product.class
文件 9517 2006-01-10 16:51 excercise\excercise 1\student-files\Product.html
文件 57 2006-01-10 16:51 excercise\excercise 1\student-files\resources\inherit.gif
文件 1135 2006-01-10 16:51 excercise\excercise 1\student-files\ShoppingCart.class
文件 8509 2006-01-10 16:51 excercise\excercise 1\student-files\ShoppingCart.html
文件 2405 2010-11-16 22:30 excercise\excercise 1\student-files\ShoppingCartApplication.java
文件 1855 2005-12-13 15:10 excercise\excercise 1\student-files\ShoppingCartApplication原.java
文件 71513 2010-11-18 00:15 excercise\excercise 2\uml-gou-cof.jpg
文件 107102 2010-11-18 17:22 excercise\excercise 2\uml-gou-cof1.jpg
文件 1283 2010-11-25 11:35 excercise\excercise 3\student-files\Coffee\Coffee.java
文件 737 2010-11-25 11:06 excercise\excercise 3\student-files\Coffee\Product.java
文件 2484 2005-12-08 15:30 excercise\excercise 3\student-files\Coffee\TestCoffee.java
文件 861 2010-11-25 23:15 excercise\excercise 3\student-files\CoffeeBrewer\CoffeeBrewer.java
文件 773 2010-11-25 23:16 excercise\excercise 3\student-files\CoffeeBrewer\Product.java
文件 2105 2005-12-08 15:30 excercise\excercise 3\student-files\CoffeeBrewer\TestCoffeeBrewer.java
文件 626 2010-11-25 23:15 excercise\excercise 3\student-files\OrderItem\OrderItem.java
文件 737 2010-11-25 11:06 excercise\excercise 3\student-files\OrderItem\Product.java
文件 2177 2005-12-08 15:30 excercise\excercise 3\student-files\OrderItem\TestOrderItem.java
文件 737 2010-11-25 11:06 excercise\excercise 3\student-files\Product\Product.java
文件 2487 2005-12-08 15:30 excercise\excercise 3\student-files\Product\TestProduct.java
文件 1295 2006-01-10 17:14 excercise\excercise 4\student-files\Coffee.class
文件 15188 2006-01-10 17:14 excercise\excercise 4\student-files\Coffee.html
文件 971 2006-01-10 17:14 excercise\excercise 4\student-files\CoffeeBrewer.class
文件 11474 2006-01-10 17:14 excercise\excercise 4\student-files\CoffeeBrewer.html
文件 12545 2005-12-02 15:25 excercise\excercise 4\student-files\GourmetCoffee.java
文件 968 2006-01-10 17:15 excercise\excercise 4\student-files\OrderItem.class
文件 9760 2006-01-10 17:14 excercise\excercise 4\student-files\OrderItem.html
文件 979 2006-01-10 17:14 excercise\excercise 4\student-files\Product.class
文件 11042 2006-01-10 17:14 excercise\excercise 4\student-files\Product.html
............此处省略72个文件信息
- 上一篇:psk systemview 仿真
- 下一篇:FICO PA模拟题
相关资源
- 数据库系统基础教程答案第三版机械
- 《数字信号处理第三版》课后习题答
- 数据结构年终考题范围和答案 耿国华
- 大学物理答案 同济大学 高等教育出版
- 信息论与编码(仇佩亮编著 高等教育
- 《复变函数》习题答案(第四版)
- 中科院 编译原理 习题及解答
- 西安电子科技大学 并行计算 霍红卫
- 浙江工业大学2005-2006学年单片机习题
- 信息系统分析与设计试卷及答案
- SSD4 exercise8答案
- 杨素行第三版模电答案
- 复变函数参考答案(西安交通大学版
- 复旦大学出版社 李贤平 《概率论基础
- 数值分析答案(第五版)李庆扬
- 数据结构殷人昆版的课后答案
- 郁道银 工程光学 习题答案
- 操作系统教程课后答案华中科技大学
- 用友ERP考试系统练习题库及答案
- 《原子物理学》高教 杨福家 完整版课
- 真正!!!概率论与数理统计浙江大
- 计算机操作系统课后_汤小丹_第四版
- 计算机操作系统(第四版)汤小丹课
- 南京大学考研845真题答案-2018
- Convex Optimization 习题答案
- 数据结构考研试题历届试卷(附答案
- 计算机网络自顶向下方法答案(第六
- 数学分析教材,复旦,陈传璋、金福
- 操作系统教程课后习题答案
- 编译原理龙书答案
评论
共有 条评论