Question: Write a class that repeatedly prompts the user if they want to enter the data to create a Customer object (use the attached Customer class.)
Write a class that repeatedly prompts the user if they want to enter the data to create a Customer object (use the attached Customer class.) If the user enters the String "yes", then the program should prompt the user to enter a String value and a double value, create a Customer object, and add the newly created Customer object to an ArrayList. If the user enters the String "no", then the program should display all of the Customer objects in the ArrayList, one per line. If the user enters any String other than "yes" or "no", then display a message to the user indicating they should answer yes or no and then prompt the user again. Do not alter the Customer class in any way. Here is a sample run of the program: ------------------------------------------------- Would you like to enter data for a Customer object? Enter yes or no. whatever Enter yes or no. Would you like to enter data for a Customer object? Enter yes or no. yes Enter the customer name.
Alice Enter the customer balance. 3.42
Customer class
public class Customer
{
private String name;
private double balance;
public Customer(String name, double balance)
{
this.name = name;
this.balance = balance;
}
@Override
public String toString()
{
return String.format("Customer Name: %30s Balance: $%,.2f", name, balance);
}
}
Step by Step Solution
3.34 Rating (157 Votes )
There are 3 Steps involved in it
Here I am providing the code Hope it helps Please ... View full answer
Get step-by-step solutions from verified subject matter experts
