Reputation:
I have this class which is supposed to have 3 lists of objects of other classes.
Now, how can I fill the list from the main class by using the following method
from the class?
import java.util.ArrayList;
import java.util.List;
public class FcomCarRentalSystem {
public List<Customer> customers = new ArrayList<Customer>();
public List<Car> cars = new ArrayList<Car>();
public List<Rental> rental = new ArrayList<Rental>();
// Add Car
public String addCar(Car tcar) {
cars.add(tcar);
String state = "“added car successfully”";
return state;
}
Note that Car
, Customers
, Rental
are classes and they have no problem.
Here is the main class. When I add the following car it is supposed to show the message "added successfully". But nothing shows in my main class.
What did I do wrong here?
public class App {
public static void main(String[] args) {
FcomCarRentalSystem company = new FcomCarRentalSystem ();
Car nii1 = new Car("QA33145","Nissan",CarType.SEDAN,true);
company.addCar(nii1);
}
}
Any help would be appreciated.
You can see in these images what is required with the class diagram.
Upvotes: 2
Views: 152
Reputation: 18245
public static void main(String[] args) {
FcomCarRentalSystem company = new FcomCarRentalSystem ();
System.out.println(company.addCar(new Car()));
System.out.println(company.addCustomer(new Customer()));
System.out.println(company.addRental(new Rental()));
}
Upvotes: 2