Create the following simple StoreTestProgram class: public class StoreTestProgra
ID: 3782860 • Letter: C
Question
Create the following simple StoreTestProgram class: public class StoreTestProgram {public static void main(String args[]) {Customer[] result; Store walmart; walmart = new Store('Walmart off Innes"); walmart.addCustomer(new Customer("Amie", 14. 'F', 100) walmart.addCustomer(new Customer("Brad", 15, 'M', 0)); walmart.addCustomer(new Customer("Cory", 10, 'M', 100)); walmart.addCustomer(new Customer("Dave", 5, 'M', 48)); walmart.addCustomer(new Customer("Earl", 21, 'M'. 500)); walmart.addCus tomer(new Customer("Flem", 18, 'h'. 1)); walmart.addCustomer(new Customer("Gary", 8, 'M', 20)); walmart.addCustomer(new Customer("Hugh", 65, 'M', 30)); walmart.addCustomer(new Customer("Iggy", 43, 'M', 74)); walmart.addCustomer(new Customer("Joan", 55, 'F', 32)); walmart.addCustomer(new Customer("Kyle", 16, 'M', 88)); walmart.addCustomer(new Customer("Lore", 12, 'F', 1000)); walmart.addCustomer(new Customer("Mary", 17, 'F', 6)); walmart.addCustomer(new Customer("Hick", 13, 'M', 2)); walmart.addCustomer(new Customer("Omar", 18, 'M', 24)); walmart.addCustomer(new Customer("Patt", 24, 'F', 45)); walmart.addCustomer(new Customer("Quin", 42, 'M' 355)); walmart.addCustomer(new Customer("Ruth", 45, 'F', 119)); walmart.addCustomer(new Customer("Snow", 74, 'F', 20)); walmart.addCus tomer(new Customer("Tamy", 88, 'F', 25)); walmart.addCustomer(new Customer("Visa", 2, 'F' 75)); walmart.addCustomer(new Customer("Vern", 9, 'M', 90)); walmart.addCustomer(new Customer("Hill", 11, 'M", 220)); walmart.addCustomer(new Customer("Xeon", 17, 'F', 453)); walmart.addCustomer(new Customer(Ying", 19, 'F', 76)); walmart.addCustomer(new Customer! "Zack", 22, 'M', 35)); System.out.println("Here are the customers: "); walmart.listCustomers();}}Explanation / Answer
public class Customer {
private String c_name;
private int c_age;
private char c_sex;
private int c_amt;
public Customer(){
}
public void display_data()
{
System.out.println(c_name+" "+c_age+" "+c_sex+" "+c_amt); // Display data of single customer
}
public Customer(String name,int age, char sex, int amt)
{
c_name=name;
c_age=age;
c_sex=sex;
c_amt=amt;
}
}
import java.util.*; // Package Included For ArrayList Class Dynamic Class allocation, No limitation of static Size Declaration
public class Store // Store Class with a String Name
{
private String title;
List<Customer> c = new ArrayList<Customer>(); // List with no limit of customers
public Store(String title)
{
title=title; // Store title name into title field
}
public void addCustomer(Customer c1)
{
c.add(c1); // add a customer into the list
}
public void listCustomers()
{
for (int i=0;i<c.size();i++)
{
c.get(i).display_data(); // display the complete data
}
}
}
public class StoreTestProgram {
public static void main(String args[])
{
Customer result[];
Store walmart;
walmart=new Store("Walmart off Innes");
walmart.addCustomer(new Customer("Amie",14,'F',100));
walmart.addCustomer(new Customer("Brad",15,'M',0));
walmart.addCustomer(new Customer("Cory",10,'M',100));
walmart.addCustomer(new Customer("Dave",5,'M',48));
walmart.addCustomer(new Customer("Earl",21,'M',500));
walmart.addCustomer(new Customer("Flem",18,'M',1));
walmart.addCustomer(new Customer("Gary",8,'M',20));
walmart.addCustomer(new Customer("Hugh",65,'M',30));
walmart.addCustomer(new Customer("Iggy",43,'M',74));
walmart.addCustomer(new Customer("Joan",55,'F',32));
walmart.addCustomer(new Customer("Kyle",16,'M',88));
walmart.addCustomer(new Customer("Lore",12,'F',1000));
walmart.addCustomer(new Customer("Mary",17,'F',6));
walmart.addCustomer(new Customer("Nick",13,'M',2));
walmart.addCustomer(new Customer("Omar",18,'M',24));
walmart.addCustomer(new Customer("Patt",24,'F',45));
walmart.addCustomer(new Customer("Quin",42,'M',355));
walmart.addCustomer(new Customer("Ruth",45,'F',119));
walmart.addCustomer(new Customer("Snow",74,'F',20));
walmart.addCustomer(new Customer("Tamy",88,'F',25));
walmart.addCustomer(new Customer("Ulsa",2,'F',25));
walmart.addCustomer(new Customer("Vern",9,'M',90));
walmart.addCustomer(new Customer("Will",11,'M',220));
walmart.addCustomer(new Customer("Xeon",17,'F',453));
walmart.addCustomer(new Customer("Ying",19,'F',76));
walmart.addCustomer(new Customer("Zack",22,'M',35));
System.out.println("Here are the customers: ");
walmart.listCustomers();
}
}
Output:-
--------------------Configuration: <Default>--------------------
Here are the customers:
Amie 14 F 100
Brad 15 M 0
Cory 10 M 100
Dave 5 M 48
Earl 21 M 500
Flem 18 M 1
Gary 8 M 20
Hugh 65 M 30
Iggy 43 M 74
Joan 55 F 32
Kyle 16 M 88
Lore 12 F 1000
Mary 17 F 6
Nick 13 M 2
Omar 18 M 24
Patt 24 F 45
Quin 42 M 355
Ruth 45 F 119
Snow 74 F 20
Tamy 88 F 25
Ulsa 2 F 25
Vern 9 M 90
Will 11 M 220
Xeon 17 F 453
Ying 19 F 76
Zack 22 M 35
Process completed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.