4. Customer.java
Don't use plagiarized sources. Get Your Custom Essay on
Question: 4. Consider a Customer class that contains a double money variable, along with a getMoney) method……
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
public class Customer {
// Data member
private double money;
// Parameterized constructor to initialize money variable
public Customer(double money) {
this.money = money;
}
// Getter method for money
public double getMoney() {
return money;
}
public boolean isRicher(Customer other) {
if(this.money > other.getMoney()) {
return true;
}else {
return false;
}
}
public Customer findRichest(Customer[] customers) {
// Assume, first customer i.e. customer at index 0
// has more money than any other customer
Customer cust = customers[0];
double max_money = customers[0].getMoney();
// Iterate through customers array
// If max_money < current customer’s money
// set max_money = current customer’s money
// and set cust to current customer
for(int i = 1;i<customers.length;i++) {
if(max_money<customers[i].getMoney()) {
max_money = customers[i].getMoney();
cust = customers[i];
}
}
// return cust
return cust;
}
}
5. Business.java and Employee.java
NOTE – Since you haven’t provided the Employee class, I have assumed it’s data members and method. And have implemented Business class methods accordingly. Make changes as per your requirement
Employee.java
public class Employee {
private double salary;
private double tax;
// Parameterized constructor
public Employee(double salary, double tax) {
this.salary = salary;
this.tax = tax;
}
public double getSalary() {
return salary;
}
public double getTax() {
return tax;
}
}
Business.java
public class Business {
private Employee[] employees;
public Business(Employee[] employees) {
this.employees = employees;
}
public Employee getHighestPaid() {
Employee emp = employees[0];
double max_salary = employees[0].getSalary();
// Iterate through employee array
// If max_salary < current Employee’s money
// set max_salary = current Employee’s money
// and set emp to current Employee
for (int i = 1; i < employees.length; i++) {
if (max_salary < employees[i].getSalary()) {
max_salary = employees[i].getSalary();
emp = employees[i];
}
}
return emp;
}
public Employee getHighestTaxed() {
Employee emp = employees[0];
double max_tax = employees[0].getTax();
// Iterate through employee array
// If max_tax < current Employee’s money
// set max_tax = current Employee’s money
// and set emp to current Employee
for (int i = 1; i < employees.length; i++) {
if (max_tax < employees[i].getTax()) {
max_tax = employees[i].getTax();
emp = employees[i];
}
}
return emp;
}
}
6.
ExamplePaneDriver.java class to check ExamplePane class
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class ExamplePaneDriver extends Application{
public ExamplePaneDriver() {}
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
ExamplePane root = new ExamplePane();
stage.setScene(new Scene(root, 250, 250));
// Set stage title and show the stage.
stage.setTitle(“Operations”);
stage.show();
}
}
OUTPUT
