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

Question: Code: public class Employee { public String name; public double salary

ID: 3549866 • Letter: Q

Question

Question:


Code:


public class Employee {
    
    public String name;
    public double salary;
    
    Employee(String n, double s)
    {
        
        this.name=n;
        this.salary=s;
        
    }
    
    public double getSalary()
    {
        
        return salary;
        
    }
    
    public String getName()
    {
        
        return name;
        
    }
    
    
}


import java.util.Scanner;
import java.text.*;

public class RealEstateAgent extends Employee
{
    
    public static double totalSales;
    public static double commision;
    
    RealEstateAgent(String n, double s)
    {
        
        super(n,s);
        
    }
    
    public double getTotalSales(double sales[])
    {
        
        double totalSales=0;
        

        for(int i=0; i<sales.length; i++)
        {
            
            totalSales= totalSales + sales[i];
            
        }
        
        return totalSales;

    }
    
    public double getCommision()
    {
        
        if(totalSales>600000)
        {
            commision = 1 * totalSales;
            
        }
        
        else if(totalSales>450000 && totalSales<599999)
        {
            
            commision = 0.7 * totalSales;
            
        }
        
        else if(totalSales>250000 && totalSales<449999)
        {
            
            commision = 0.5 * totalSales;
            
        }
        
        else if(totalSales<250000)
        {
            
            commision = 0;
            
        }
        
        else
        {
            commision = 0;
        }
        
        return commision;
        
    }
    
    public double getSalary()
    {
        
        return salary;
        
        
    }
    
    public static void main(String [] args)
    {
        
        String name="";
        double salary=0;
        int housenum=0;
        double sales[]=new double[100];
        double totalSales=0;
        double total=0;
        
        
        Scanner input = new Scanner(System.in);
        DecimalFormat df = new DecimalFormat("#.00");
        
        System.out.print("Enter Agent Name: ");
        name = input.nextLine();
        
        System.out.print("Enter basic salary: $");
        salary = input.nextDouble();
        
        System.out.print("House sold: ");
        housenum = input.nextInt();
        
        System.out.println("Enter the price of the houses: ");
        
        for(int i=0; i<housenum; i++)
        {
            System.out.print("House "+(i+1)+" : ");
            sales[i]=input.nextDouble();
        }
        
        System.out.println(" Summary Report");
        System.out.println("------------------");
        
        System.out.println("Agent: "+name);
        System.out.println("Basic Salary: RM"+salary);


        totalSales=getTotalSales(sales[]);
        
        System.out.println("Total Sales: RM"+totalSales);
        System.out.println("Total Commision: RM"+commision);
        
        total=commision+salary;
        
        System.out.println("Total Salary: RM"+total);


       RealEstateAgent rsa = new  RealEstateAgent();
        
    }
   
}


Please correct my code, and using comment to explain.
How to declare REALESTATEAGENT object and get totalsalary and get commision.

A real estate firm, MYHARTA Sdn Bhd provides services in buying, selling and leasing properties for clients. MYHARTA has many negotiators. A negotiator is a salesperson employed by real estate firms, also known as real estate agent. Agents earn basic salary and get commission based on the sales that they have made. Write two classes named Employee and RealEstateAgent based on the UML class diagrams shown in Figure Q2a. RealEstateAgent class Constructor RealEstateAgent () constructs an object by calling the superclass's constructor with parameters: n and s. Method get Total Sales () is used to calculate the total sales of houses sold by the agent. The method will accept an array as the parameter. Method getCommission () is used to calculate the commission earned by the agent based on the total sales, as shown below: The method should return the amount of the commission and the formula used is: Commission = commission rate times total sales. Method getSalary () will override the method getSalary () from Employee class. This method will return the new salary, which is their salary added with the commission that the agent received. Now write a client program to test the RealEstateAgent class. In the client program, prompt the user to key-in the agent's name, basic salary, and quantity of houses sold. User must also enter the price of the houses, which will be stored in an array. Create a RealEstateAgent object with the name and basic salary fields to represent the agent. Finally, display the name of the agent and basic salary, together with the total sales of houses sold, total commission, and total salary. You may refer to the example output shown in Figure Q2b:

Explanation / Answer

import java.util.Scanner;
import java.text.*;

public class Employee
{
// from UML Diagram following variables should be private not public.
// because in UML - symbol is there.
private String name;
private double salary;
Employee(String n, double s)
{
this.name=n;
this.salary=s;
}
public double getSalary()
{
return salary;
}
public String getName()
{
return name;
}
}

public class RealEstateAgent extends Employee
{
// from UML Diagram following variables should be private not public.
// because in UML - symbol is there.
private double totalSales;
private double commision;
RealEstateAgent(String n, double s)
{
super(n,s);
}
public double getTotalSales(double sales[])
{
// no need to declare separately here..totalSales already member of class.
totalSales=0;
for(int i=0; i<sales.length; i++)
{
totalSales= totalSales + sales[i];
}
return totalSales;
}
public double getCommision()
{
if(totalSales>600000)
{
commision = 0.01 * totalSales;
}
else if(totalSales>450000 && totalSales<599999)
{
commision = 0.007 * totalSales;
}
else if(totalSales>250000 && totalSales<449999)
{
commision = 0.005 * totalSales;
}
else if(totalSales<250000)
{
commision = 0;
}
else
{
commision = 0;
}
return commision;
}
public double getSalary()
{
// here u have to call base class salary and add commission to that.
return (super.getSalary()+commision);
}
}

//write separate CLient code with main method.
public class client_code
{
public static void main(String [] args)
{
String name="";
double salary=0;
int housenum=0;
double totalSales=0;
double total=0;
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.00");
System.out.print("Enter Agent Name: ");
name = input.nextLine();
System.out.print("Enter basic salary: $");
salary = input.nextDouble();
//once we got name and salary create RealEstateAgent object.
RealEstateAgent rsa = new RealEstateAgent(name,salary);
System.out.print("House sold: ");
housenum = input.nextInt();
// create array based on hourses sold.
double[] sales=new double[housenum];
System.out.println("Enter the price of the houses: ");
for(int i=0; i<housenum; i++)
{
System.out.print("House "+(i+1)+" : ");
sales[i]=input.nextDouble();
}
System.out.println(" Summary Report");
System.out.println("------------------");
System.out.println("Agent: "+name);
System.out.println("Basic Salary: RM "+salary);
// call getTotalSales on RealEstateAgent object by passing sales array.
System.out.println("Total Sales: RM "+rsa.getTotalSales(sales));
// call getCommision on RealEstateAgent object.
System.out.println("Total Commision: RM "+rsa.getCommision());
// call getSalary on RealEstateAgent
System.out.println("Total Salary: RM "+rsa.getSalary());
}
}

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