我想从扫描仪输入创建arraylist。这是摩托车租赁系统。请帮助:)我是绝对的初学者:D
我正在尝试创建这样的表: (日期,日期,名称,licenceID)
这是我的代码:
public class Launcher{
public static void main(String[] args) throws IOException {
ArrayList<Launcher> reservationlist = new ArrayList<>();
reservationlist.add(2016-08-09, 2016-08-20, Mr Smith, 1234567; // there is an error
Helper.welcomeMessage();
char choice, ignore;
for (;;) {
do {
Helper.showMenu();
choice = (char) System.in.read();
do {
ignore = (char) System.in.read();
} while (ignore != '\n');
} while (choice < '1' | choice > '5' & choice != 'q');
if (choice == 'q') {
break;
}
Orders order = new Orders();
switch (choice) {
case '1': // Get information about company
Helper.aboutUs();
break;
case '2': // List of our motorcycles (enum)
System.out.println("Price per 1 day: PREMIUM 500, GOLD 500, BASIC 500");
for (Prices pricelist : Prices.values())
System.out.printf("%s\t%s\n", pricelist.getTitle(), pricelist);
break;
case '3': // Make a reservation
Scanner hp = new Scanner(System.in);
Orders reservation = new Orders();
System.out.println("Type initial date:");
reservation.initialDate = hp.next();
System.out.println("Type final date:");
reservation.finalDate = hp.next();
System.out.println("Type your first name and last name:");
reservation.name = hp.next();
System.out.print("Type your driving licence ID:");
reservation.drivingLicenceID = hp.next();
System.out.println("\n\n Reservation completed " + reservation.name + "\n Thanks for your reservation\n");
break;
reservationlist.add(reservation.initialDate, reservation.finalDate, reservation.name, reservation.drivingLicenceID)); // there is an error
case '4': // Check availability of motorcycles
System.out.println("");
break;
case '5': // Contact with us
Helper.contact();
break;
}
public class Orders {
String initialDate;
String finalDate;
String name;
String drivingLicenceID;
public Orders(String initialDate, String finalDate, String name, String drivingLicenceID) {
this.initialDate = initialDate;
this.finalDate = finalDate;
this.name = name;
this.drivingLicenceID = drivingLicenceID;
}
public Orders() {}
@Override
public String toString() {
return "Orders{" +
"initialDate='" + initialDate + '\'' +
", finalDate='" + finalDate + '\'' +
", name='" + name + '\'' +
", drivingLicenceID=" + drivingLicenceID +
'}';
}
public void setInitialDate(String initialDate) {
this.initialDate = initialDate;
}
public void setFinalDate(String finalDate) {
this.finalDate = finalDate;
}
public void setName(String name) {
this.name = name;
}
public void setDrivingLicenceID(String drivingLicenceID) {
this.drivingLicenceID = drivingLicenceID;
}
}
答案 0 :(得分:2)
我想你试图实现的是这个:
.ToUpper()
而不是
List<Orders> reservationlist = new ArrayList<>();
reservationlist.add(new Orders("2016-08-09", "2016-08-20", "Mr Smith", "1234567"));
而且:
ArrayList<Launcher> reservationlist = new ArrayList<>();
reservationlist.add(2016-08-09, 2016-08-20, Mr Smith, 1234567; // there is an error
而不是
reservationlist.add(reservation);
答案 1 :(得分:0)
除Nicolas解释的内容外,另外一个明显的语法错误如下:
while (choice < '1' | choice > '5' & choice != 'q');
您错误地实施了conditional operators。条件OR
语法为||
,而AND
的语法为&&
。