Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A company has developed a class called ExpenseAccount that it uses for storing e

ID: 3765360 • Letter: A

Question

A company has developed a class called ExpenseAccount that it uses for storing ex-
penses. They nd that they need to be able to control whether or not the account can
be modi ed. Rather than rewrite the code, they have decided to write a new version
called SafeExpenseAccount that extends ExpenseAccount to provide this functional-
ity. All instance variables in ExpenseAccount are private. It has the following public
methods:
public ExpenseAccount(AccountInfo info): Constructs an empty account.
public void add(Bill b): Adds a bill to the account.
public Bill
get(int index): Returns the bill at the given index.
public int size(): Returns the size of the account.
public String toString(): Returns a string summarizing the account.


You are to write a class called SafeExpenseAccount that extends this class using in-
heritance, providing the same functionality, and providing a mechanism for controlling
whether or not the account can be modi ed. When the account is set to be modi able,
the methods operate normally. When the account is set to be not modi able, any at-
tempt to modify the state of the account should generate an IllegalAccessException
(part of java.lang) | this is a checked exception and thus has to follow the Catch
or Declare" rule. The only method that changes the state of the account is the add
method.


When constructed, the account should be modiable. The new class should have the
following public methods that will allow the client to control whether or not the account
is considered modi able:


public void setModifiable(boolean value): Uses given value to set whether
or not the account is
modi able.
public boolean getModifiable(): Returns whether the account is
modiable.


You should also override the toString method to output the summary of the
expense account and add either locked" or unlocked" at the end.

Explanation / Answer

sample code:

Bill class:

public class Bill

{

}

AccountInfo class:

public class AccountInfo {

int acno;

int bal;

int bill;

}

ExpenseAccount.java

public class ExpenseAccount {

int accountno;

int bill;

int bal;

public ExpenseAccount(AccountInfo info) {

this.accountno=info.acno;

this.bill=info.bill;

this.bal=info.bal;

}

public void add(Bill b)

{

} //Adds a bill to the account.

public void Billget(int index) {

}// Returns the bill at the given index.

public int size() {

return 0;

}// Returns the size of the account.

public String toString() {

return accountno+" "+bal+" "+bill;

} //;Returns a string summarizing the account.

}

SafeExpenseAccount.java:

public class SafeExpenseAccount extends ExpenseAccount {

public SafeExpenseAccount(AccountInfo info) {

super(info);

// TODO Auto-generated constructor stub

}

public void setModifiable(boolean value)

{

//: Uses given value to set whether//or not the account is modifiable.

}

public boolean getModifiable()

{

return false;

//: Returns whether the account is modifiable.

}

public String toString() {

return accountno+" "+bal+" "+bill;

}

public static void main(String[] args)

{

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote