In: Computer Science
Complete the following Customer class below. Also, add the equals method that would compare each field.
Please pay attention to the format of the equals method as it needs to have the same format as shown below.
public class Customer {
private int id; //customer id
private String name; //customer's name
private int discount; //discount rate in percent
//construct a new customer
public Customer(int id, String name, int discount) {
}
//returns the field values
public int getId () {
}
public String name () {
}
public int discount () {
}
//returns String for customer. Eg: "Mary, id:1111, discount 10%"
public String toString () {
}
public boolean equals (Object other) {
if (other instanceof some_class) {
//do casting
return logical_statement_for_comparison;
} else {
return false;
}
}
package assignment1; public class Customer { private int id; //customer id private String name; //customer's name private int discount; //discount rate in percent public Customer(int id, String name, int discount) { this.id = id; this.name = name; this.discount = discount; } //returns the field values public int getId() { return id; } public String name() { return name; } public int discount() { return discount; } //returns String for customer. Eg: "Mary, id:1111, discount 10%" public String toString() { return name+", id:"+id+", discount "+discount+"%"; } public boolean equals(Object other) { if (other instanceof Customer) { //do casting other = (Customer) other; return (((Customer) other).id == id) && (((Customer) other).discount == discount) && (((Customer) other).name.equals(name)); } else { return false; } } }