因此,我正在為汽車經(jīng)銷商制定程序,這是我班的最后一個項目。目前,我說我已經(jīng)完成了75%,但是我在弄清楚如何更新數(shù)組列表中的用戶輸入時遇到了麻煩。因此,每個陣列列表插槽均包含汽車的年份,品牌,型號,顏色和行駛里程。我可以添加新車,可以移除車,并且可以退出程序。我嘗試了許多事情,讀了許多論文,博客,論壇和我的課堂書籍,但是它總是隨著程序員的輸入而更新。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
提交
取消