Answered step by step
Verified Expert Solution
Question
1 Approved Answer
*Java Create a Person class to implement both the Measurable Interface and the Comparable interface. A person should have a first name, a last name
*Java
Create a Person class to implement both the Measurable Interface and the Comparable interface.
A person should have a first name, a last name and an age. The measure should be done by age. The Comparable will be done by first name. Add a static method to the Data class to find the person with the smallest age.
Test the new class by creating several Person objects then fine the Person with the smallest age. Sort the Person objects.
These five files should be helpful for the problem.
*Please do it with java
* 1 2 A bank account has a balance that can be changed by deposits and withdrawals. TE 6 public class BankAccount implements Measurable ={ private double balance; Constructs a bank account with a zero balance. public BankAccount() balance = 0; Constructs a bank account with a given balance. @param initialBalance the initial balance public BankAccount(double initialBalance) balance = initialBalance; Deposits money into the bank account. @param amount the amount to deposit public void deposit(double amount) balance = balance + amount; Withdraws money from the bank account. @param amount the amount to withdraw public void withdraw(double amount) balance = balance - amount; 46 Gets the current balance of the bank account. @return the current balance public double getBalance() I return balance; public double getMeasure() return balance; 57 } Measurable.java + x 1 9/** 2 | Describes any class whose objects can be measured. 3 */ 4 public interface Measurable ovou Computes the measure of the object. @return the measure double getMeasure(); Measurable Tester.java + x 1 E ** 2 This program demonstrates the measurable BankAccount and Country classes. 3 */ 4 public class MeasurableTester 5 B{ 6 7 public static void main(String[] args) Measurable[] accounts = new Measurable[3]; accounts[0] = new BankAccount(); accounts[1] = new BankAccount(10000); accounts[2] = new BankAccount(2000); double averageBalance = Data.average (accounts); System.out.println("Average balance: " + averageBalance); System.out.println("Expected: 4000"); Measurable[] countries = new Measurable[3]; countries[0] = new Country("Uruguay", 176220); countries[1] = new Country (Thailand", 513120); countries[2] = new Country("Belgium", 30510); double averageArea = Data.average (countries); System.out.println("Average area: " + averageArea); System.out.println("Expected: 239950"); Data.java + x 1 public class Data 2 ${ Computes the average of the measures of the given objects. @param objects an array of Measurable objects @return the average of the measures public static double average (Measurable[] objects) double sum = 0; for (Measurable obj : objects) THEHEBO VOLAW sum = sum + obj.getMeasure(); if (objects.length > 0) { return sum / objects.length; } else { return 0; } Country.java + x 1 E ** 2 A country with a name and area. 3 */ 4 public class Country implements Measurable 5 ${ private String name; 7 private double area; 6 11 Constructs a country. @param aName the name of the country @param anArea the area of the country public Country(String aName, double anArea) name = aName; area = anArea; Gets the country name. @return the name public String getName() return name; Gets the area of the country. @return the area public double getArea() return area; public double getMeasure() return area; 41 [1 ]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started