因此,我正在为汽车经销商制定程序,这是我班的最后一个项目。目前,我说我已经完成了75%,但是我在弄清楚如何更新数组列表中的用户输入时遇到了麻烦。因此,每个阵列列表插槽均包含汽车的年份,品牌,型号,颜色和行驶里程。我可以添加新车,可以移除车,并且可以退出程序。我尝试了许多事情,读了许多论文,博客,论坛和我的课堂书籍,但是它总是随着程序员的输入而更新。package carDealer;import java.util.ArrayList;import java.util.Scanner;public class VehicleInformation {public static void main(String [] args) { Scanner scnr = new Scanner(System.in); ArrayList<VehicleInventory> car = new ArrayList<VehicleInventory>(); String userInput = "-"; while (!userInput.equals("q")) { System.out.println("Commands: 'a' to add, 'd' to delete, 'e' to edit, 'q' to quit"); userInput = scnr.next(); if (userInput.equals("a")) { System.out.println("Year: "); int year = scnr.nextInt(); System.out.println("Make: "); String make = scnr.next(); System.out.println("Model: "); String model = scnr.next(); System.out.println("Color: "); String color = scnr.next(); System.out.println("Mileage: "); int mileage = scnr.nextInt(); VehicleInventory userCar = new VehicleInventory(); userCar.setMake(make); userCar.setModel(model); userCar.setYear(year); userCar.setColor(color); userCar.setMileage(mileage); userCar.print(); addCar(car, userCar); } if (userInput.equals("d")) { for (int i = 0; i < car.size(); ++i) { System.out.print((i + 1) + " "); car.get(i).print(); } System.out.println("List number: "); int userNum = scnr.nextInt(); car.remove(userNum - 1); System.out.println("count: " + car.size()); } if (userInput.equals("e")) { for (int i = 0; i < car.size(); ++i) { System.out.print((i + 1) + " "); car.get(i).print(); }
添加回答
举报
0/150
提交
取消