程序代写代做代考 Java Lab 8 page 1

Lab 8 page 1

QQuueeeenn MMaarryy
UUnniivveerrssiittyy ooff LLoonnddoonn

SScchhooooll ooff EElleeccttrroonniicc EEnnggiinneeeerriinngg aanndd CCoommppuutteerr SScciieennccee

EBU5304: Software Engineering

Lab 8: Design Principles

(This lab exercise is not assessed)

Consider the following Java interface type:

interface Logger

{

public void log(String name, int change);

public String display(String name, int number);

}

The idea is that an object of a class which implements this interface can be used to keep a

record or “log” of the changes made to a set of named numerical values. The first argument to

the two methods is set to the name of a particular numerical value. The method log is called

whenever a named numerical value is changed, its second argument should be set to the value

of the change. The method display is used to obtain the record of changes made, with its

second argument set to the number of changes to be displayed.

For example, if we have an object of type Logger, and the following method calls have been

made on it in this order:

log(“John”,3), log(“Mary”,5), log(“John”,-4), log(“John”,10),

log(“Fred”,14), log(“John”,-2), log(“John”,7), log(“Mary”,5)

then calling display(“John”,3) on the object will return the String value “+10 -2 +7”.

1) Write a class which implements this interface. You will need to choose a suitable
internal representation for objects of that class so that they give the required behaviour.

2) Write ANOTHER class which implements this interface. It should differ from the first
class by having a different internal representation, but its external behaviour should be

the same as the first class.

3) Modify the code you wrote for your previous lab exercises so that bank accounts are

linked to a Logger object. Whenever funds are deposited or withdrawn from an

account, there should be a call of the method log on the Logger object, with its first

argument set to the name of the account holder and its second argument set to the amount

by which the balance of the account has changed.

Consider the extent to which you have been able to keep to the design principles covered in the

lectures in making the modifications asked for in question 3).

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *