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

NEED HELP WITH THIS QUESTION !!! PLEASE !!! PROGRAMMING LANGUAGE : JAVA A class

ID: 3811664 • Letter: N

Question

NEED HELP WITH THIS QUESTION !!! PLEASE !!!

PROGRAMMING LANGUAGE : JAVA

A class hierarchy will be created using inheritance to represent clients The "Customer" class should look like this: l-) "CustomerID to represent customer number 2-) "Name" and "Surname" in String type representing first and last name 3-) Unparametric constructor 4-) Constructor that uses all variables 5-) Copy Constructor 6-) toString method 7-) Get and Set methods To represent national customers, derive a class named "National Customcr" with inheritance from the "Customer" class The "National Customer" class should be as follows: l-) "LicenccPlateNumber" in int type to represent the provincial traffic plate code 2-)"Occupation" in String type representing the customer's occupation 3-) Unparametric constructor 4-) Constructor that uses a variables 5-) Copy Constructor 6-) to String method 7-) Get and Set methods To represent international customers, derive a class named "International Customer" with inheritance from the "Customer" class The "International Customer" class should be as follows: 1-"Country" in the String type representing the country 2-)"City" in int type representing the city 3-) Unparametric constructor 4-) Constructor that uses all variables 5-) Copy Constructor 6-0 toString method 7-) Get and Set methods The first linc of thc file contains thc namc of thc product and the product namcs. For examplc, 5 The product is ratcd and the names of these products are given as products A, B, C, D and E The following lines are arranged as follows: customer information first (n: national, i n international meaning), On the bottom line there are grades that the relevant customer has made for the products. A comma-separated-value(CSV) file is a simple text format used to store a list of records. A comma is used a delimiter to separate the fields for each record. This format is commonly used to transfer data between a spreadsheet or database. The first line of the file contains the name of the product and the product names. For example, 5 The product is rated and the names of these products are given as products A, B, C, D and E

Explanation / Answer

Main.java
--------------
package chegg.customer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class Main {
   static Map<Customer, String[][]> map = new HashMap<Customer, String[][]>();
   public static void main(String[] args) {
       String[][] arrayStr = new String[5][2];
       List<String> list = Main.readFile("customer");
       String[] product = null;
       String[] rating = null;
       String[] customer = null;
       product = list.get(0).split(",");
       for (int indx = 1; indx < list.size() - 2; indx++) {
           customer = list.get(indx + 1).split(",");
           rating = list.get(indx + 2).split(",");
           for (int j = 0; j < 5; j++) {
               arrayStr[j][0] = product[j + 1];
               arrayStr[j][1] = rating[j];
           }
           Customer customerObj = null;
           if ("n".equals(customer[0])) {
               customerObj = new NationalCustomer();
               customerObj.setCustomerID(Integer.parseInt(customer[1]));
               customerObj.setFirstName(customer[2]);
               customerObj.setLastName(customer[3]);
               ((NationalCustomer) customerObj).setLicensseplateNumber(Integer
                       .parseInt(customer[4]));
               ((NationalCustomer) customerObj).setOccupation(customer[5]);
           } else if ("i".equals(customer[0])) {
               customerObj = new InternationalCustomer();
               customerObj.setCustomerID(Integer.parseInt(customer[1]));
               customerObj.setFirstName(customer[2]);
               customerObj.setLastName(customer[3]);
               ((InternationalCustomer) customerObj).setCity(Integer
                       .parseInt(customer[4]));
               ((InternationalCustomer) customerObj).setCountry(customer[5]);
           }
           Main.map.put(customerObj, arrayStr);
       }
       Iterator<Entry<Customer, String[][]>> actualEntrySet = map.entrySet()
               .iterator();
       while (actualEntrySet.hasNext()) {
           Entry<Customer, String[][]> entry = actualEntrySet.next();
           System.out.println("Customer " + entry.getKey() + " ");
           System.out.print("Product : ");
           for (int indx = 0; indx < entry.getValue().length; indx++) {
               System.out.println(entry.getValue()[indx][0] + " "
                       + " Rating : " + entry.getValue()[indx][1] + " ");
           }
       }
   }
   /**
   *
   * @param fileNameWithPath
   * @return
   */
   public static List<String> readFile(String fileNameWithPath) {
       List<String> list = new ArrayList<String>();
       try (BufferedReader br = new BufferedReader(new FileReader("d:\"
               + fileNameWithPath + ".txt"))) {
           String sCurrentLine;
           while ((sCurrentLine = br.readLine()) != null) {
               list.add(sCurrentLine);
           }
       } catch (IOException e) {
           e.printStackTrace();
       }
       return list;
   }
}

Customer.java
---------------------
package chegg.customer;
public class Customer {
   private int customerID;
   private String firstName;
   private String lastName;
   public Customer() {
   }
   public Customer(Customer customer) {
       this.customerID = customer.getCustomerID();
       this.firstName = customer.getFirstName();
       this.lastName = customer.getLastName();
   }
   public Customer(int customerID, String firstName, String lastName) {
       this.customerID = customerID;
       this.firstName = firstName;
       this.lastName = lastName;
   }
   public int getCustomerID() {
       return customerID;
   }
   public void setCustomerID(int customerID) {
       this.customerID = customerID;
   }
   public String getFirstName() {
       return firstName;
   }
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }
   public String getLastName() {
       return lastName;
   }
   @Override
   public String toString() {
       return "Customer [customerID=" + customerID + ", firstName="
               + firstName + ", lastName=" + lastName + "]";
   }
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + customerID;
       result = prime * result
               + ((firstName == null) ? 0 : firstName.hashCode());
       result = prime * result
               + ((lastName == null) ? 0 : lastName.hashCode());
       return result;
   }
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Customer other = (Customer) obj;
       if (customerID != other.customerID)
           return false;
       if (firstName == null) {
           if (other.firstName != null)
               return false;
       } else if (!firstName.equals(other.firstName))
           return false;
       if (lastName == null) {
           if (other.lastName != null)
               return false;
       } else if (!lastName.equals(other.lastName))
           return false;
       return true;
   }
}

NationalCustomer.java
-------------------------------
package chegg.customer;
public class NationalCustomer extends Customer {
   private int licensseplateNumber;
   private String occupation;
   public NationalCustomer() {
       super();
   }
   public NationalCustomer(NationalCustomer nationalCust) {
       super((Customer) nationalCust);
       this.licensseplateNumber = nationalCust.getLicensseplateNumber();
       this.occupation = nationalCust.getOccupation();
   }
   public NationalCustomer(int licensseplateNumber, String occupation) {
       super();
       this.licensseplateNumber = licensseplateNumber;
       this.occupation = occupation;
   }
   public int getLicensseplateNumber() {
       return licensseplateNumber;
   }
   public void setLicensseplateNumber(int licensseplateNumber) {
       this.licensseplateNumber = licensseplateNumber;
   }
   public String getOccupation() {
       return occupation;
   }
   public void setOccupation(String occupation) {
       this.occupation = occupation;
   }
   @Override
   public String toString() {
       return "NationalCustomer [licensseplateNumber=" + licensseplateNumber
               + ", occupation=" + occupation + "]";
   }
}

InternationalCustomer.java
-----------------------------------
package chegg.customer;
public class InternationalCustomer extends Customer {
   private int city;
   private String country;
   public InternationalCustomer() {
       super();
   }
   public InternationalCustomer(InternationalCustomer internationalCustomer) {
       super((Customer) internationalCustomer);
       this.city = internationalCustomer.getCity();
       this.country = internationalCustomer.getCountry();
   }
   public InternationalCustomer(int city, String country) {
       super();
       this.city = city;
       this.country = country;
   }
   public int getCity() {
       return city;
   }
   public void setCity(int city) {
       this.city = city;
   }
   public String getCountry() {
       return country;
   }
   public void setCountry(String country) {
       this.country = country;
   }
   @Override
   public String toString() {
       return "InternationalCustomer [city=" + city + ", country=" + country
               + "]";
   }
}

Output

---------------

Customer null

Product : A   Rating : 5

b   Rating : 2

c   Rating : 1

D   Rating : 4

E   Rating : 3

Customer InternationalCustomer [city=35, country=doctor]

Product : A   Rating : 5

b   Rating : 2

c   Rating : 1

D   Rating : 4

E   Rating : 3