我对Java还很陌生,我正在为类的项目工作,我不确定如何编写我的程序来获取userInput(fileName)并从中创建一个新对象。我的指令是编写一个程序,该程序从用户读取文件名,然后从该文件读取数据,创建对象(键入StudentInvoice)并将它们存储在ArrayList中。如何阅读用户输入以创建对象?
这就是我现在所处的位置。
public class StudentInvoiceListApp {
public static void main (String[] args) {
Scanner userInput = new Scanner(System.in);
String fileName;
System.out.println("Enter file name: ");
fileName = userInput.nextLine();
ArrayList<StudentInvoice> invoiceList = new ArrayList<StudentInvoice>();
invoiceList.add(new StudentInvoice());
System.out.print(invoiceList + "\n");
}
没有足够的信息来回答你的问题。例如,输入文件是什么样的?你可能会更好地问一个关于你卡在哪里的更具体的问题。 –