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

You will be given a class named Customer, and you need to implement two interfac

ID: 3538580 • Letter: Y

Question

You will be given a class named Customer, and you need to implement two interfaces in the Customer class. Customer Class:


The first interface is called Comparable, which is already defined in Java%u2019s API. The only abstract method you need to implement from the Comparable interface is the compareTo() method. Please check the header definition of the compareTo() from Java%u2019s API first before you implement it.


The second interface is what you need to create for yourself, and let%u2019s call it NetWorthEvaluator. This interface contains only one public abstract method named checkNetWorth() which takes no parameters but will return a String when implemented. Create the interface, save it and compile it. This interface is to be implemented by your Customer class.


Now modify the Customer class to implement both Comparable and NetWorthEvaluator interfaces. When you implement the compareTo() method from the Comparable interface, compare the networth instance variable of the two Customer objects to determine which Customer object is greater than, less than or equal to the other Customer object. When you implement the checkNetWorth() method from the NetWorthEvaluator interface, you check the networth instance variable to determine what string message it should return (see below):


networth < 0.0

returns %u201CNegative Net Worth - Extremely Poor Credit Rating"

0.0 <= networth < 10,000.00

returns "Net Worth Is Well Below Average - Very Poor Credit Rating"

10000.00 <= networth < 50,000.00

returns "Net Worth Is Below Average - Poor Credit Ratiung"

50,000.00<= networth < 100,000.00

returns "Average Net Worth - Acceptable Credit Rating"

100,000.00 <= networth < 200,000.00

%uF0B7 returns "Above Average Net Worth - Good Credit Rating"

200,000.00 <= networth < 1,000,000.00

%uF020%uF0B7 returns "Well Above Average Net Worth - Very Good Credit Rating"

1,000,000.00 <= networth

%uF020%uF0B7 returns "Net Worth Is Over One Million Dollars - Excellent Credit Rating"

Make sure that you call the checkNetWorth() method in the toString() method to include the string message returned as part of the String representation of the Customer object.

Here's a test program for testing the modified Customer class:


Explanation / Answer

I have update the code as you required, Please see the below code. I have run with your main method. It got work perfectly.


//Customer class - allows objects from this class to compare between
//themselves to see which Customer object has higher networth. Also
//allow to evaluate each customer's credit rating.
//

import java.text.DecimalFormat;

public class Customer implements Comparable, NetWorthEvaluator
{
     //class constants
     public static final int UNKNOWN = 99;
     public static final int MALE = 1;
     public static final int FEMALE = 2;

     //member data
     private String firstName;
     private String lastName;
     private int gender;
     private double networth;


     //default constructor
     public Customer ()
     {
             firstName = "";
             lastName ="";
             gender =UNKNOWN;
             networth=0.0;
     }


     //another constructor
     public Customer (String fname, String lname,int gender, double networth)
     {
             firstName = fname;
             lastName = lname;
             this.gender = gender;
             this.networth = networth;

     }


     //Accessors (Getter methods)
     public String getFirstName ()
     {
             return firstName;
     }

     public String getLastName ()
     {
             return lastName;
     }


     public int getGender ()
     {
             return gender;
     }

     public double getNetWorth()
     {
             return networth;
     }

     //Mutators (Setter methods)
     public void setFirstName (String fname)
     {
             if (fname.length() < 1)
             {
                     System.out.println("Bad first name found in 'setFirstName' method");
                     System.out.println("No change to the firstName field of the object!");
             }
             else
                     firstName =fname;
     }

     public void setLastName (String lname)
     {
             if (lname.length() < 1)
             {
                     System.out.println("Bad last name found in 'setLastName' method");
                     System.out.println("No change to the lastName field of the object!");
             }
             else
                     lastName =lname;
     }


     public void setGender (int gender)
     {
             if ((gender != MALE) && (gender != FEMALE) && (gender != UNKNOWN))
             {
                     System.out.println("Invalid gender value found in 'setGender' method");
                     System.out.println("No change to the gender field of the object!");
             }
             else
                     this.gender = gender;
     }

     public void setNetWorth(double asset)
     {
             networth = asset;
     }


     //ToString method

     public String toString()
     {
             String sex;
             DecimalFormat fmt = new DecimalFormat("$#,###.00");

             if (gender == MALE)
                     sex ="Male";
             else
                 if (gender == FEMALE)
                         sex ="Female";
                 else
                             sex = "Unknown";

     // modify this statement below to include the credit rating
             return "Name: " + firstName + " " + lastName + " "+
                    "Gender: " + sex + " " + "Net Worth: " + fmt.format(networth) + " "+
                    "Credit Rating:"+checkNetWorth();
     }


     //Implement compareTo method from Comparable interface here
     @Override
    public int compareTo(Object o) {
        if(!(o instanceof Customer)){
            throw new IllegalArgumentException("Argument is not Customer Object");
        }
        if(networth > ((Customer)o).getNetWorth()){
            return 1;
        }else if(networth < ((Customer)o).getNetWorth()){
            return -1;
        }else{
            return 0;
        }
    }




// Implement checkNetWorth method from NetWorthEvaluator interface here

     public String checkNetWorth(){
        if(networth < 0){
            return "Negative Net Worth - Extremely Poor Credit Rating";
        }else if(networth >= 0 && networth < 10000){
            return "Net Worth Is Well Below Average - Very Poor Credit Rating";
        }else if(networth >= 10000 && networth < 50000){
            return "Net Worth Is Below Average - Poor Credit Ratiung";
        }else if(networth >= 50000 && networth < 100000){
            return "Average Net Worth - Acceptable Credit Rating";
        }else if(networth >= 100000 && networth < 200000){
            return "Above Average Net Worth - Good Credit Rating";
        }else if(networth >= 50000 && networth < 1000000){
            return "Well Above Average Net Worth - Very Good Credit Rating";
        }else{
            return "Net Worth Is Over One Million Dollars - Excellent Credit Rating";
        }
     }

}

interface NetWorthEvaluator{
    public String checkNetWorth();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote