Create the following simplified Customer class: public class Customer {String na
ID: 3782859 • Letter: C
Question
Create the following simplified Customer class: public class Customer {String name; int char float age; gender; money;//A simple constructor public Customer(String n, int a, char g, float m) {name = n; age = a; gender = g; money = m;}//Return a String representation of the object public String toString() {String result; result = "Customer " + name + ": a " + age + " year old"; if (gender == 'F') result = "fe"; return result + "male with $" + money;}} Create the following simple Store class. public class Store {public static final int MAX_CUSTOMERS = 500; public Store(String n) {new Customer (MAX_CUSTOMERS); customerCount = 0;} public void addCustopmer(Customer c) {if (customerCOuntExplanation / Answer
PROGRAM CODE:
Customer.java
package simple;
public class Customer {
String name;
int age;
char gender;
float money;
public Customer(String n, int a, char g, float m) {
name = n;
age = a;
gender = g;
money = m;
}
@Override
public String toString() {
String result;
result = "Customer " + name + ": a " + age + " year old ";
if(gender=='F')
result += "fe";
return result + "male with $" + money;
}
}
Store.java
package simple;
public class Store {
public static final int MAX_CUSTOMERS = 500;
String name;
Customer[] customers;
int customerCount;
public Store(String n) {
name = n;
customers = new Customer[MAX_CUSTOMERS];
customerCount = 0;
}
public void addCustomer(Customer c)
{
if(customerCount < MAX_CUSTOMERS)
customers[customerCount++] = c;
}
public void listCustomers()
{
for(int i=0; i<customerCount; i++)
System.out.println(customers[i]);
}
}
StoreCustomerTester.java
package simple;
public class StoreCustomerTester {
public static void main(String[] args) {
Customer c1 = new Customer("John Doe", 31, 'M', 1000);
Customer c2 = new Customer("Jane Doe", 28, 'F', 1100);
Store s1 = new Store("Wall Mart");
s1.addCustomer(c1);
s1.addCustomer(c2);
s1.listCustomers();
}
}
OUTPUT:
Customer John Doe: a 31 year old male with $1000.0
Customer Jane Doe: a 28 year old female with $1100.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.