Answer to Question #167620 in Java | JSP | JSF for ayyappan

Question #167620

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.


1
Expert's answer
2021-02-28T13:42:50-0500
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();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog