Q.2.4 When the Process Report menu item is clicked, capture the selected agent location,

estate agent name, property price, and commission percentage, and display the estate
agent report. The commission is calculated by multiplying the property price by the
commission percentage.Q.2.5 When the Save Report menu item is clicked, save the estate agent report to a text file
named report.txt.Q.2.6 When clicking the Clear Menu item, set the text fields and text area to the default
state.
Q.2.7 Make use of a class named EstateAgent that contains methods to calculate the estate
agent commission and validate the data. Only valid data should be captured in the
application; the validation rules are:
VALIDATION RULE
Agent Location It cannot be empty.
Agent Name It cannot be empty.
Property Price Cannot be less than or equal to zero (0)
Commission Percentage Cannot be less than or equal to zero (0)
The EstateAgent class must implement an IEstateAgent interface that contains the
following:
public interface IEstateAgent {
double CalculateCommission(String propertyPrice, String agentCommission);
boolean ValidateData(Data dataToValidate);..IN JAVA
include import method

import java.io.FileWriter;

import java.io.IOException;
import java.text.DecimalFormat;

public interface IEstateAgent {

double CalculateCommission(String propertyPrice, String agentCommission);
boolean ValidateData(Data dataToValidate);

class EstateAgent implements IEstateAgent {

private String agentLocation;
private String agentName;
private double propertyPrice;
private double commissionPercentage;

public EstateAgent(String agentLocation, String agentName, double propertyPrice, double commissionPercentage) {
this.agentLocation = agentLocation;
this.agentName = agentName;
this.propertyPrice = propertyPrice;
this.commissionPercentage = commissionPercentage;
}

public double CalculateCommission(String propertyPrice, String agentCommission) {
double price = Double.parseDouble(propertyPrice);
double commission = Double.parseDouble(agentCommission);
return price * commission;
}

public boolean ValidateData(Data dataToValidate) {
if (dataToValidate.getAgentLocation().isEmpty() || dataToValidate.getAgentName().isEmpty()) {
return false;
}

if (dataToValidate.getPropertyPrice() <= 0 || dataToValidate.getCommissionPercentage() <= 0) {
return false;
}

return true;
}

public void generateReport() {
DecimalFormat df = new DecimalFormat("#.##");
double commission = CalculateCommission(dataToValidate.getPropertyPrice(), dataToValidate.getCommissionPercentage());

String report = "Agent Location: " + dataToValidate.getAgentLocation() + "\n"
+ "Estate Agent Name: " + dataToValidate.getAgentName() + "\n"
+ "Property Price: $" + dataToValidate.getPropertyPrice() + "\n"
+ "Commission Percentage: " + dataToValidate.getCommissionPercentage() + "%" + "\n"
+ "Commission: $" + df.format(commission);

System.out.println(report);
}

public void saveReport() {
DecimalFormat df = new DecimalFormat("#.##");
double commission = CalculateCommission(dataToValidate.getPropertyPrice(), dataToValidate.getCommissionPercentage());

String report = "Agent Location: " + dataToValidate.getAgentLocation() + "\n"
+ "Estate Agent Name: " + dataToValidate.getAgentName() + "\n"
+ "Property Price: $" + dataToValidate.getPropertyPrice() + "\n"
+ "Commission Percentage: " + dataToValidate.getCommissionPercentage() + "%" + "\n"
+ "Commission: $" + df.format(commission);

try {
FileWriter writer = new FileWriter("report.txt");
writer.write(report);
writer.close();
System.out.println("Report saved successfully!");
} catch (IOException e) {
System.out.println("Error saving report: " + e.getMessage());
}
}

public void clearFields(Data dataToClear) {
dataToClear.setAgentLocation("");
dataToClear.setAgentName("");
dataToClear.setPropertyPrice(0);
dataToClear.setCommissionPercentage(0);
}
}
}