JAVA,关于用LINKED LIST时碰到的问题!!!请高手帮下忙啊!!!很急!!!

importjava.util.*;publicclassFactory{privateStockstock;//privatePizza[]pizzas=newPizz... import java.util.*;

public class Factory
{ private Stock stock;
//private Pizza[] pizzas = new Pizza[3];
//private int index = 0;
private Pizza made;
List<Pizza> pizzas = new LinkedList<Pizza>();

public Factory(Stock stock)
{ this.stock = stock;
LinkedList<String> pepTops = new LinkedList<String>();
pepTops.add(new String("pepperoni"));
pepTops.add(new String("mushroom"));
pepTops.add(new String("olive"));
add("pepperoni", pepTops, 4.50);
LinkedList<String> mariTops = new LinkedList<String>();
mariTops.add(new String("prawn"));
mariTops.add(new String("olive"));
add("marinara", mariTops, 6.70);
LinkedList<String> vegeTops = new LinkedList<String>();
vegeTops.add(new String("zucchini"));
vegeTops.add(new String("artichoke"));
add("vegetarian", vegeTops, 8.90); }

private void add(String name, LinkedList<String> toppings, double price)
{ pizzas.add( new Pizza(name, toppings, price));
for (String topping: toppings)
if (!stock.has(topping))
stock.add(topping); }

public void newPizza()
{
String newPizzaName = readPizzaName();
LinkedList<String> newTops = new LinkedList<String>();

do
{
newTops.add(new String(readNewTop()));
}while (!end(readNewTop()));
double price = readPrice();
add(newPizzaName, newTops, price);
}

private String readPizzaName()
{
System.out.print(" Pizza name: ");
return In.nextLine();
}

private double readPrice()
{
System.out.print(" Price: ");
return In.nextDouble();
}

private String readNewTop()
{
System.out.print(" Topping (or end): ");
return In.nextLine();
}
public boolean end(String s)
{ return s.equals("end"); }
=========================================
问题出在newPizza(),只有第一次输入的东西才能被加进add(newPizzaName, newTops, price);
比如说,pizza name: gold
Topping (or end): gold
Topping (or end): copper
Topping (or end): iron
只有gold被加进add(newPizzaName, newTops, price);
这是为什么呢?代码要怎么改呢?
求解啊~
展开
 我来答
mcltl
2010-10-11 · TA获得超过158个赞
知道小有建树答主
回答量:114
采纳率:0%
帮助的人:81万
展开全部
do{
newTops.add(new String(readNewTop()));
}while (!end(readNewTop()));
用于判断和你add进去的不是同一个值 readNewTop()执行了两次
readNewTop()应该赋给一个变量,对变量操作
陈学阳
2010-10-13 · TA获得超过2.8万个赞
知道大有可为答主
回答量:2.1万
采纳率:14%
帮助的人:5574万
展开全部
package cn.com.xxx; //根据实际情况调整

import java.io.*;

public class ReadWriteFile {
public static void printFile(String name) throws Exception {
FileReader fin = new FileReader(name);
int temp;
while ((temp = fin.read()) != -1)
System.out.print((char) temp);
System.out.println();
fin.close();
}

public static void mergeFile(String one, String two, String result)
throws Exception {
FileReader fin1 = new FileReader(one);
FileReader fin2 = new FileReader(two);
PrintWriter out = new PrintWriter(result);

int temp1, temp2;
while ((temp1 = fin1.read()) != -1)
out.print((char) temp1);
out.println();
while ((temp2 = fin2.read()) != -1)
out.append((char) temp2);

out.close();
fin1.close();
fin2.close();
}

public static void main(String[] args) {
try {
printFile("D:\\Test\\1.txt"); //文件路径根据实际情况调整下同
printFile("D:\\Test\\2.txt");
mergeFile("D:\\Test\\1.txt", "D:\\Test\\2.txt", "D:\\Test\\3.txt");
} catch (Exception e) {
e.printStackTrace();
}
}
}

如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!

vaela
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式