Determines whether to accept an object.

Assignment Help C/C++ Programming
Reference no: EM13939848

Declare an interface Filter as follows:

public interface Filter
{
boolean accept(Object x);
}

Modify the implementation of the DataSet class in Section to use both a Measurer and a Filter object. Only objects that the filter accepts should be processed. Demonstrate your modification by having a data set process a collection of bank accounts, filtering out all accounts with balances less than $1,000.

You need to supply the following class in your solution:
DataSet

Use the following class as your tester class:
/**
This program tests the use of a Measurer and a Filter.
*/
public class DataSetTester
{
public static void main(String[] args)
{
class BankMeasurer implements Measurer
{
public double measure(Object anObject)
{
BankAccount ba = (BankAccount) anObject;
return ba.getBalance();
}
}

class BankFilter implements Filter
{
public boolean accept(Object x)
{
BankAccount ba = (BankAccount) x;
return ba.getBalance() > 1000;
}
}

Measurer m = new BankMeasurer();
Filter f = new BankFilter();
DataSet data = new DataSet(m, f);

data.add(new BankAccount(1));
data.add(new BankAccount(100));
data.add(new BankAccount(2000));
data.add(new BankAccount(950));
data.add(new BankAccount(4000));

System.out.println("Average balance: " + data.getAverage());
System.out.println("Expected: 3000");

BankAccount b = (BankAccount) data.getMaximum();
double balance = b.getBalance();
System.out.println("Highest balance: " + balance);
System.out.println("Expected: 4000");
}
}

DO NOT MODIFY THE FOLLOWING
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount
{
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)
{
double newBalance = balance + amount;
balance = newBalance;
}

/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
}

/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
}
DO NOT MODIFY THE FOLLOWING
/**
Describes any class whose objects can measure other objects.
*/
public interface Measurer
{
/**
Computes the measure of an object.
@param anObject the object to be measured
@return the measure
*/
double measure(Object anObject);
}

DO NOT MODIFY THE FOLLOWING

public interface Filter
{
/**
Determines whether to accept an object.
@param x the object to be filtered
@return true to accept an object, false otherwise
*/
boolean accept(Object x);
}
DO NOT MODIFY THE FOLLOWING

/**
This program tests the use of a Measurer and a Filter.
*/
public class DataSetTester
{
public static void main(String[] args)
{
class BankMeasurer implements Measurer
{
public double measure(Object anObject)
{
BankAccount ba = (BankAccount) anObject;
return ba.getBalance();
}
}

class BankFilter implements Filter
{
public boolean accept(Object x)
{
BankAccount ba = (BankAccount) x;
return ba.getBalance() > 1000;
}
}

Measurer m = new BankMeasurer();
Filter f = new BankFilter();
DataSet data = new DataSet(m, f);

data.add(new BankAccount(1));
data.add(new BankAccount(100));
data.add(new BankAccount(2000));
data.add(new BankAccount(950));
data.add(new BankAccount(4000));

System.out.println("Average balance: " + data.getAverage());
System.out.println("Expected: 3000.0");

BankAccount b = (BankAccount) data.getMaximum();
double balance = b.getBalance();
System.out.println("Highest balance: " + balance);
System.out.println("Expected: 4000.0");
}
}

Reference no: EM13939848

Questions Cloud

Experience working in a technical analyst role : Demonstrated experience working in a Technical Analyst role; Ability to perform under pressure and to tight deadlines; Demonstrated experience working within a Security conscious environment; Demonstrated experience working in a Defence environmen..
Evaluating my own experience performance asclinical educator : Evaluating my own experience performance as a clinical educator by reflecting on the experience and referring to current relevant educational literature.
Projects that may be adjusted if a recession is on horizon : Pick any industry that you would like to know more about (automobile industry). What are some examples of short term versus long term projects that may be adjusted if a recession is on the horizon? Write in detail with descriptive examples.
Dividends are expected to grow at rate : Synovec Co. is growing quickly. Dividends are expected to grow at a rate of 25 percent for the next three years, with the growth rate falling off to a constant 4 percent thereafter. If the required return is 10 percent, and the company just paid a di..
Determines whether to accept an object. : Modify the implementation of the DataSet class in Section to use both a Measurer and a Filter object. Only objects that the filter accepts should be processed.
What is asymmetric warfare : Explain the following; specific security challenges in the Port Maritime Environment, Risk Management activity, Components of Port Security Planning, and Asymmetric Warfare, Megaports Initiative, and the Secure Freight Initiative. What is Asymmetr..
Bullish on a particular security : You are bullish on a particular security and have $500 to invest. The stock is trading for $100. Call options with a strike price of $100 are trading for $1.00. You decide to invest your entire $500 by purchasing call options. How many options contra..
Cost accounting systems used by manufacturing : Cost accounting systems used by manufacturing companies are based on the: Periodic inventory system.
Issued dividend of per share on its common stock : The Muse Co. just issued a dividend of $3.45 per share on its common stock. The company is expected to maintain a constant 7.10 percent growth rate in its dividends indefinitely. If the stock sells for $69 a share, what is the company’s cost of equit..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program to open a file for reading

Write a program to open a file for reading that has twenty (20) rows and in each row there are three (3) columns.

  Write c program that forks two child processes

Write a C program that forks two child processes. The parent process will print all prime numbers up to 229, the first child process will print the first 50 Fibonacci numbers.

  You are the admissions office at abc medical university

You are the Admissions Office at ABC Medical University. You have a large number of applicants for a very few number of available openings at your school. As a result, you need to set some high admission standards. To be accepted, a student ..

  Compares the number of possible sequences

A c++ program that compares the number of possible sequences of the length L that can be generated uinder the following assumptions. Given an alphabet of size N=9. The program must output a formatted list comparing the number of possible sequences..

  Program that prompts the user to input

Write a program that prompts the user to input three numbers.

  Consider an l1 cache with an access time of 1 ns

Suppose that we can change the cache design (size of cache, cache organization) such that we increase H to 0.97, but increase access time to 1.5 ns. What conditions must be met for this change to result in improved performance?

  Sequence of numbers

What sequence of numbers would be printed if the following procedure were executed with the value of N being 0

  Function that shifts the stored value of five character

Write a function that shifts the stored value of five character variables in a circular fashion. Your function should work in the following way. Suspose that C1, C2, C3, C4, C5 are variables of type char, and suspose that the values of these varia..

  Write a program that keeps track of important birthdays

Write a program that keeps track of important birthdays. You can implement it with a one-dimensional array with enumeration type indices, a two-dimensional array, or with parallel arrays.

  Nbspyou are to insert the missing code in the c program

nbspyou are to insert the missing code in the c program given for combinational equivalence checking. this program will

  Implementation of matrix multiplication

Show the matrix product and implementation of matrix multiplication. Please show me all the working and provide the answer.

  Write a program to multiply two matrices.

The values of matrices in your program can be hard-coded and any numbers you like(including the numbers of columns/rows and the values of matrices), which means you do not have to ask user to input those numbers. Of course you can do this if you w..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd