0

This is my main function:

public static void main(String[] args) {
    List<CarDetails> carList = new ArrayList<CarDetails>();
    String addAnother;
    
    Scanner scan = new Scanner(System.in);
    
    
    do {
        CarDetails car = new CarDetails();
        car.setCarModel();
        car.setCarType();
        car.setCarCostPrice();
        car.setInsuranceType();
        car.setInsurancePremium();
        carList.add(car);
        
        System.out.print("Do you want to enter details of any other car (y/n): ");
        addAnother = scan.nextLine();
        
    }while(addAnother.equals("y"));
    
    for(int i=0; i<carList.size(); i++) {
        System.out.println(carList.get(i));
    }
    
    

}

When I'm trying to get an output of my code, I'm getting weird output. It is my first time using an ArrayList of objects. Please help me. This is my output screenshot. Output

WangJexi
  • 1
  • 5
  • 1. You need to read the user input and populate the `car` fields; currently the setters do NOT set any values. 2. You need to override method `toString` in `Car` class so that the `Car` instances have appropriate string representation. – Nowhere Man Mar 20 '22 at 18:46
  • @NowhereMan Sorry, couldn't understand. Can you please elaborate? – WangJexi Mar 20 '22 at 18:56

0 Answers0