CS2514 Lab 2


You will be writing a class definition called ATM, which represents simplified ATMs (automated teller machines, i.e. hole-in-the-wall cash dispensers) for an international bank. Machines in different countries will be loaded with banknotes of different denominations depending on the currency of the country.

Here's some 'client' code:

int[] euroDenoms = {5, 10, 20, 50}; // denominations, i.e. what kinds of notes we use
ATM atm1 = new ATM("euro", euroDenoms); // create an ATM

int[] kronurDenoms = {1000, 5000, 500, 2000, 10000}; // note: don't assume the notes are in a particular order
ATM atm2 = new ATM("Icelandic kronur", kronurDenoms); // create another ATM for a different currency

atm1.load(1, 5); // load it with 1 x 5 euro notes
atm1.load(3, 20); // load it with 3 x 20 euro notes
atm1.load(2, 50); // load it with 2 x 50 euro notes
System.out.println(atm1.getQty(20)); // print how many 20 euro notes the ATM contains
System.out.println(atm1); // display the contents
atm1.dispense(1, 50); // dispense 1 x 50 euro note to a customer
System.out.println(atm1.getTotal() + " " + atm1.getCurrency()); // print total and currency

From the above you will realise we need one constructor and six instance methods. A few words about some of the less obvious methods:

You'll want to write a main method, e.g. in a file called ATMTester.java, to test your ATM class. And, if you've any sense at all, you'll use it to try out more than the few things in the 'client' code shown above.


Deadline: 4pm, Friday 5th February 2016.

Put both ATM.java and ATMTester.java into a directory called lab2. To submit:

Challenge exercise

Remember that challenge exercises are always optional. They do not form part of your year's work and they are not worth any marks. They are designed for those students who finish the main exercise quickly and easily, and wish to explore further. You may need to use things not covered so far in lectures.

When you are convinced that your ATM program is superb (correct, efficient, elegant), make a copy of it in ATMChallenge.java. Modify this copy by adding an additional dispense method (yes, you can have two with the same name), as follows: