I really need some help with my assignment in school. It's been only a month since I'm in Java and I got this super hard assignment to accomplish. I'm struggling for several days now. So I have to make a car shop database with 20 cars. I managed to make a Car class with getters and setters. Now I have to make a bunch of operations that the car shop owner can do with his info of cars. I have info about 3 cars (carsArray [0] [1] [2]) and other 17 empty. The main issue is how to add more info to the next free array (with scanner).
Car carsArray[] = new Car[20]; //cars array with 20 Car objects
for (int c = 0; c < carArray.length; c++)
carArray[c] = new Car();
carArray[0].setRegNr("A123");
carArray[0].setModel("v50");
carArray[0].setYear(2005);
carArray[0].setMileage(2000);
carArray[0].setGear("manu");
carArray[0].setColour("white");
carArray[0].setFuel("diesel");
// this is what I'm trying now with methods (sorry, not sure att all how to use my
// arrays)
public static String[] addCar() {
Car[] c = new Car;
for (int i = 0; i < c.length; i++) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter reg nr.: ");
carsArray[].setRegNr() = keyboard.nextLine();
{
return ???;
}
Carobjects within theforloop.{}withforloops andifstatements, even if they are not strictly necessary.Carclass, which accepts several parameters. At the moment, one is able to create a car (usingnew Car()) without a model, without a build year and without a fuel type.