inheritance, classes, instance methods, constructors A cash processing company h
ID: 663485 • Letter: I
Question
inheritance, classes, instance methods, constructors
A cash processing company has a class called Account used to process transactions:
Account objects interact with Transaction objects, which have many methods including:
The company wishes to create a slight modification to the Account class that filters out zero-valued transactions. Design a new class called FilteredAccount whose instances can be used in place of an Account object but which include the extra behavior of not processing transactions with a value of 0. More specifically, the new class should indicate that a zero-valued transaction was approved but shouldn't call the process method in the Account class to process it. Your class should have a single constructor that accepts a parameter of type Client, and it should include the following method:
Assume that all transactions enter the system by a call on the process method described above.
Related Files:
Account.java
Method/Constructor Description public Account(Client c) constructs an account using client information public boolean process(Transaction t) processes the next transaction, returning true if transaction was approved, falseotherwiseExplanation / Answer
added percentFiltered class and also included constructor and method which returns double value 0.00 to 100.00. please have a look
.....
public class Account {
public boolean __processCalled;
public Account(Client c) {//account constructor
__processCalled = false;
}
public boolean process(Transaction t) {//method process which returns value between -100 to 1000000
__processCalled = true;
return t.value() > -100 && t.value() < 1000000;
}
public class Client {}
public class Transaction {
private int value;
public Transaction(int v) {//transaction constructor
value = v;
}
public int value() {//method to return value
return value;
}
}
public class FilteredAccount {//filteredAccount constructor
private double value;
public FilteredAccount(Client c) { //FilteredAccount constructor
__processCalled = false;
}
public double percentFiltered(Transaction t){ //method percentFiltered returns double value
if(__processCalled==false){ // transaction occurs
return t.value() > 0.0 && t.value() < 100.00;
}
return 0.0; //if no trnasition occurs
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.