Java 多扫描程序
我有一个类,它创建多个对象并将它们放入如下所示:IntegerLinkedList
public class Shares<E> implements Queue<E> {
    protected LinkedList<E> L;
    public Shares() {
        L = new LinkedList<E>();
    }
    public boolean add(E price) {
        System.out.println("How many of these shares would you like?");
        Scanner scanInt;
        scanInt = new Scanner(System.in);
        Integer noShares = scanInt.nextInt();
        for (int i = 0; i < noShares; i++) {
            L.addLast(price);
        }
        scanInt.close();
        return true;
    }
}
我有一个应用程序,它从控制台扫描输入“add”,如果找到,将调用如下所示的方法:add
public class Application {
    private static Scanner scan;
    public static <E> void main(String[] args) {
        Queue<Integer> S = new Shares<Integer>();
        scan = new Scanner(System.in);
        System.out.println("Please type add");
        String sentence = scan.nextLine();
        while (sentence.equals("quit") == false) {
            if (sentence.equals("add")) {
                System.out
                    .println("What price would you like to buy your shares at?");
                S.add((Integer) scan.nextInt());
            } else
                System.exit(0);
            sentence = scan.nextLine();
        }
    }
}
应用程序应允许用户根据需要多次输入“add”,但在调用方法后会出现错误“未找到行”。add
我猜这是因为方法中的方法尚未关闭,然后在需要时重新打开。这是程序的问题吗,如果是这样,我将如何修复它?Scanner
请注意,此程序尚未完成,因为我将添加一种出售这些股票的销售方法。这就是我使用 while 循环的原因。
 
					 
				 
				    		 
				    		 
				    		 
				    		