2

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.

-- enter image description here

enter image description here

3
  • 1
    You're not printing out the result of your operation Commented Oct 23, 2020 at 10:00
  • System.out.println(company.addCar(nii1); would help you see it. Commented Oct 23, 2020 at 10:01
  • just print the result you get and see !! Commented Oct 23, 2020 at 10:03

1 Answer 1

2
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()));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.