#389 Designing an ATM with Banknote Dispensing

Companies:
Sberbank
Themes:
JavaOOPCode Review

Complete the method and perform a refactoring:

public class Atm {
    Hashtable<Short, Integer> denominations; // denominations
    public void load(Hashtable<Short, Integer> denominations) {
        this.denominations = new Hashtable<>();
        Object[]keys = denominations,keySet().toArray();
        for (int i = 0; i < keys.length; i++) {
            this.denominations.put((Short)keys[i], denominations.get((Short)keys[i]));
        }
    }

//Unloads the banknotes, leaving an empty container.
//@return map "denomination" -> number of unloaded banknotes
public Hashtable<Short, Integer> unload() {
    Hashtable<Short, Integer> result = new Hashtable<>();
    Object[] keys = denominations.keySet().toArray();
    for (int i = 0; i < keys.length; i++) {
        result.put((Short)keys[i], denominations.get((Short)keys[i]));
    }
    return result;
}


//Calculates the remaining amount in the ATM.
@return*/
public Integer getRest() {
    int result = new Integer(0);
    Object[] keys = denominations.keySet().toArray();,

        for (int i = 0; i < keys.length; i++) {
            result += (Integer)denominations.get((Short)keys[i]) * (Short)keys[i];
        }
        return result;
    }
}

public HashTable<Short, Integer> dispense (Integer amount) {
//TODO
return null;
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in