我的任务是创建一个 ArrayList 来跟踪商店每天的销售情况以及客户花费最多的帖子。我完成了任务,所以我想。所有三个类都在 Eclipse 和我的终端窗口中编译。但是,当我将它们上传到学校的系统然后进行测试时,我在课堂上遇到了错误。不用说这对我来说是令人沮丧和困惑的,我是一个非常陌生的人。这是我的 ArrayList 语法的某种问题,但我无法弄清楚,因为它在 Eclipse 上运行良好。:/
我得到的错误是:
Store.java:17: illegal start of type
customers = new ArrayList<>(); \\the up arrow is under the ">"
代码如下。
//******************************************
// Store.java
// Written...
// 2013
//*******************************************
//===========================================
// Store class holds ArrayList of customers
//===========================================
import java.util.ArrayList;
import java.util.List;
public class Store {private List<Customer> customers; //stores customers
public Store() {
customers = new ArrayList<>();
}
//creates new customer for arraylist
public void addSale(String customerName, double amount) {
Customer c = new Customer(customerName, amount);
customers.add(c);
}
//finds the best customer
public String nameOfBestCustomer() {
if (customers.isEmpty()) {
return "No customers are stored!";
} else {
Customer best = customers.get(0);
for (Customer c : customers) {
if (c.getAmount() > best.getAmount()) {
best = c;
}
}
return best.getName();
}
}
}