Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**Make a customer array, and put the objects in that array,when you run the loop

ID: 3743650 • Letter: #

Question

**Make a customer array, and put the objects in that array,when you run the loop you will have a counter it will call each object from the array. Then will create each customer at a time.**

**DOWN BELOW IS ALL THE INFO NEEDED ABOUT THE CUSTOMERS****

***COUCH AND TV ARE ENUM TYPES

import java.io. import java.util.* public class ReadCustomers public static void main(String args []) Scanner input; String line; String array; Customer ci; Customer c2; Customer c3; // make a customer array, and put the objects in that array,when you run the loop you will have a counter it will call each object from the array. Then will create each customer at a time try input = new Scanner(new File ("customers. txt")); //declare a line and will read in a line while(input.hasNext)) line nput.nextLine(); array- line.split(","); System.out println(array.toString)); //have customer object c1new Customer(array [0], new Address(array [1], array (21,array [3],array [4]), array [5]); c2 new Customer(array[0], new Address (array [1],array [21,array [3],array [4]), array [5]) c3 = new Custome r (array [0], new Address(array[1],array [2] ,array [3],array[4]), array [5]); System.out.println(c1.toString)); System.out.println(c2.toString)); System.out println(c3.toString));

Explanation / Answer

Customer.java

/**
* The Class Customer.
*/
public class Customer {

/** The name. */
private String name;
  
/** The address. */
private Address address;
  
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
  
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
  
/**
* Gets the address.
*
* @return the address
*/
public Address getAddress() {
return address;
}
  
/**
* Sets the address.
*
* @param address the new address
*/
public void setAddress(Address address) {
this.address = address;
}
  
/**
* Instantiates a new customer.
*
* @param name the name
* @param address the address
*/
public Customer(String name, Address address) {
super();
this.name = name;
this.address = address;
}

@Override
public String toString() {
return "Customer [name=" + name + ", address=" + address + "]";
}
}

Address.java

/**
* The Class Address.
*/
public class Address {
  
/** The street. */
private String street;
  
/** The city. */
private String city;
  
/** The state. */
private String state;
  
/** The pin. */
private String pin;
  
/** The phone. */
private String phone;
  
/**
* Instantiates a new address.
*
* @param street the street
* @param city the city
* @param state the state
* @param pin the pin
* @param phone the phone
*/
public Address(String street, String city, String state, String pin, String phone) {
super();
this.street = street;
this.city = city;
this.state = state;
this.pin = pin;
this.phone = phone;
}

/**
* Gets the street.
*
* @return the street
*/
public String getStreet() {
return street;
}
  
/**
* Sets the street.
*
* @param street the new street
*/
public void setStreet(String street) {
this.street = street;
}
  
/**
* Gets the city.
*
* @return the city
*/
public String getCity() {
return city;
}
  
/**
* Sets the city.
*
* @param city the new city
*/
public void setCity(String city) {
this.city = city;
}
  
/**
* Gets the state.
*
* @return the state
*/
public String getState() {
return state;
}
  
/**
* Sets the state.
*
* @param state the new state
*/
public void setState(String state) {
this.state = state;
}
  
/**
* Gets the pin.
*
* @return the pin
*/
public String getPin() {
return pin;
}
  
/**
* Sets the pin.
*
* @param pin the new pin
*/
public void setPin(String pin) {
this.pin = pin;
}
  
/**
* Gets the phone.
*
* @return the phone
*/
public String getPhone() {
return phone;
}
  
/**
* Sets the phone.
*
* @param phone the new phone
*/
public void setPhone(String phone) {
this.phone = phone;
}

@Override
public String toString() {
return "[" + street + "," + city + "," + state + "," + pin
+ "," + phone + "]";
}
}

ReadCustomers.java

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
* The Class ReadCustomers.
*/
public class ReadCustomers {

/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args) {

Scanner input;
String line;
String array[];
Customer customer;
List<Customer> liCustomer = new ArrayList<>(); // Initialize a list/array of type Customer
try {
input = new Scanner(new File("\customers.txt")); // Read Customer Data from a file
while (input.hasNext()) {  
line = input.nextLine();
// split the data based on delimiter comma
array = line.split(",");
// Create a new Customer instance based on file contents
customer = new Customer(array[0],new Address(array[1], array[2], array[3], array[4], array[5]));
// Add the customer instance to the array liCustomer
liCustomer.add(customer);
}
System.out.println("Array of Customers :::: ");
// for each loop to iterate through each element in customers array and print the contents
for (Customer cust : liCustomer) {
System.out.println(cust.toString());
}
} catch (Exception ex) {
System.out.println("Exception occurred while reading customers' data " + ex.getMessage());
}
}

}

Please place customers.txt in src folder and run ReadCustomers.java class to get the Output similar to this :

Array of Customers ::::
Customer [name=Jones, address=[123 Mitchell,Arlington,Texas,76019,1222-1233-8484-9999]]
Customer [name=Smith, address=[61 Bose Lane,Dallas,Texas,76000,7777-8393-8484-9999]]