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

1. Create a Customer<T> java class so that you can have the flexibility of havin

ID: 3596207 • Letter: 1

Question

1. Create a  Customer<T> java class so that you can have the flexibility of having a generic type attribute "t" in your objects.   You may retain your previous customer class.

     In this new Customer<T> class, add a new data field  " T t; ", add at least one constructor with T as an input, add a getter/setter for the attribute "t".

2.   Create another class (called CustomerComparator.java) to compare 2 customer using a criteria of your choice (e.g., credit score, transaction list size, or even using generic attribute T; but please only choose one).

3.   In a main method, create a java Map<Customer, Integer> object (called it "customeCounts"), then create a dozen customer objects to populate the customerCounts object.   You may choose your own criteria for the Integer key according to your design of the Customer class.     Please use java comments to explain your choice.

Explanation / Answer

import java.util.*;

import java.lang.*;

import java.io.*;

class Customer<T>{
  
private T t;
public int Customer_ID;
public int creditScore;

//constructor with T type data as input arguments
public Customer(T t, int ID ,int score){
    this.t = t;
    this.Customer_ID = ID;
    this.creditScore = score;
}

//getter for T type data
public T get(){
       return this.t;
   }
//setter function for T type data
   public void set(T input){
       this.t = input;
   }
  
  
}

class CustomerComparator{
  
public Customer<Integer> customer1;
public Customer<Integer> customer2;

//function to compare customer<Integer> based on creditScore
public void compareCustomers(){
   if(customer1.creditScore > customer2.creditScore ){
   System.out.println("Customer 1 has higher Credit Score")   ;
   }else if(customer2.creditScore > customer1.creditScore){
System.out.println("Customer 2 has higher Credit Score")   ;
   }else{
   System.out.println("Both have equal Credit Score");  
   }
}
}

public class Main
{
   public static void main (String[] args) throws java.lang.Exception
   {
      
//creating dozens of customer with unique ID and random credit Score
   Customer<Integer> customer1 = new Customer<Integer>(new Integer(1),1,554);
   Customer<Integer> customer2 = new Customer<Integer>(new Integer(2),2,3453);
   Customer<Integer> customer3 = new Customer<Integer>(new Integer(3),3,453);
   Customer<Integer> customer4 = new Customer<Integer>(new Integer(4),4,345);
   Customer<Integer> customer5 = new Customer<Integer>(new Integer(5),5,766);
   Customer<Integer> customer6 = new Customer<Integer>(new Integer(6),6,1246);
   Customer<Integer> customer7 = new Customer<Integer>(new Integer(7),7,5645);
   Customer<Integer> customer8 = new Customer<Integer>(new Integer(8),8,1554);
   Customer<Integer> customer9 = new Customer<Integer>(new Integer(9),9,135);
   Customer<Integer> customer10 = new Customer<Integer>(new Integer(10),10,7635);
   Customer<Integer> customer11 = new Customer<Integer>(new Integer(11),11,2332);
   Customer<Integer> customer12 = new Customer<Integer>(new Integer(12),12,324);
     
     
   HashMap<Customer<Integer>,Integer> map = new HashMap<>();
     
   //we will store in hashmap the customer along with it's ID
   map.put(customer1,customer1.Customer_ID);
   map.put(customer2,customer2.Customer_ID);
   map.put(customer3,customer3.Customer_ID);
   map.put(customer4,customer4.Customer_ID);
   map.put(customer5,customer5.Customer_ID);
   map.put(customer6,customer6.Customer_ID);
   map.put(customer7,customer7.Customer_ID);
   map.put(customer8,customer8.Customer_ID);
   map.put(customer9,customer9.Customer_ID);
   map.put(customer10,customer10.Customer_ID);
   map.put(customer11,customer11.Customer_ID);
   map.put(customer12,customer12.Customer_ID);
   }
}

Output:

No output as only Customer class objects are created and put into HashMap.