create java code forr class called realtor commission. fields include the sale price of a house, the house, the sales commission rate and the commission. create two constructors. each constructor requires the sales prices(expressed as double) and the commission rate. one constructor requires the commission rate to be double, such as 0.06. the other requires sale price and commission rate expressed as whole number such as 6. each constructor calculates the commission value based on the price of the house multiplied by the commission rate. the difference is that the constructor that accepts the whole number must convert it into a percentage by dividing by 100. also include display function for the fields contained in realtor commission class. write a main function that instantiate at least 2 realtor commission objects one that uses decimal and one that uses a whole number as commission rate. display the realtor commission object values.
public class RealtorCommission {
private double salePrice;
private double commissionRate;
private double commission;
public RealtorCommission(double salePrice, double commissionRate) {
this.salePrice = salePrice;
this.commissionRate = commissionRate;
commission = salePrice * commissionRate;
}
public RealtorCommission(double salePrice, int commissionRate) {
this.salePrice = salePrice;
this.commissionRate = (double) commissionRate / 100;
commission = salePrice * this.commissionRate;
}
public void display(){
System.out.println("RealtorCommission{" +
"salePrice=" + salePrice +
", commissionRate=" + commissionRate +
", commission=" + commission +
'}');
}
}
public class Main {
public static void main(String[] args) {
RealtorCommission one = new RealtorCommission(250000, 0.06);
RealtorCommission two = new RealtorCommission(250000, 6);
one.display();
two.display();
}
}
Comments
Leave a comment