Question: Customer.java: // Customer class - allows objects from this class to compare between // themselves to see which Customer object has higher networth. Also //


Customer.java:
// 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()
{
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()
{
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) + " ";
}
//Implement compareTo method from Comparable interface here
-
-
// Implement checkNetWorth method from NetWorthEvaluator interface here
-
-
}
CustomerTester.java (test the program)
// File: CustomerTester.java
// Purpose: A test harness program, to instantiate and use objects of
// the Customer class with both Comparable and NetWorthEvaluator
// interfaces implemented.
//
import java.util.Scanner;
class CustomerTester
{
public static void main (String args[])
{
Scanner scan = new Scanner(System.in);
System.out.print("Please enter the net worth for the first client (John): ");
double networth1 = scan.nextDouble();
System.out.print("Please enter the net worth for the second client (Peter): ");
double networth2 = scan.nextDouble();
Customer client1 = new Customer ("John", "Smith", Customer.MALE, networth1);
Customer client2 = new Customer ("Peter", "McMann", Customer.MALE, networth2);
if (client1.compareTo (client2) > 0)
System.out.println (client1.getFirstName() + " " + client1.getLastName() +
" has higher net worth than " + client2.getFirstName() + " " +
client2.getLastName());
else if (client1.compareTo (client2)
System.out.println (client2.getFirstName() + " " + client2.getLastName() +
" has higher net worth than " + client1.getFirstName() + " " +
client1.getLastName());
else
System.out.println (client2.getFirstName() + " " + client2.getLastName() +
" has the same amount of net worth as " + client1.getFirstName() + " " +
client1.getLastName());
System.out.println(" ");
System.out.println("Credit ratings of both customers are as follow:");
System.out.println(client1 + " " + client2);
}
}

1, 185%) You will be given a class file named Customer (available from our Moodle course page), and you need to implement two interfaces in the Customer class The first interface is called Comparable, which is already defined in Java's API. The only abstract method you need to implement from the Comparable interface is the compareTo) method. Please check the header definition of the compareTo0 from Java's API first before you implement it. The second interface is what you need to create for yourself, and let's call it NetWorthEvaluator. This interface contains only one public abstract method named checkNetWorth0 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 compareTo0 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
