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