Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="/Users/Rohan/Documents/GitHub/ATM-Project/src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
57 changes: 40 additions & 17 deletions src/ATM.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
import java.util.*;
mport java.util.HashMap;

public class ATM {
HashMap<String, Integer> map;

public ATM() {
map = new HashMap<String, Integer>();
private HashMap <String, Double> database;

public ATM()
{
database = new HashMap <String, Double> ();
}

public void deposit(String id, int amt) {
map.put(id, amt);

public void deposit(String userID, double amount) throws Exception
{
if (database.containsKey (userID))
{
double currBalance= database.get(userID);
database.replace(userID, currBalance + amount);
}
else
{
database.put(userID,amount);

}
}


@Override
public String toString() {
return "ATM [map=" + map + "]";

public void withdraw (String userID, double amount) throws Exception
{
double currBalance = database.get(userID);
if (amount> currBalance)
{
throw new Exception();
}
else
{
database.replace(userID, currBalance - amount);

}
}

public static void main (String [] args) {
ATM chase = new ATM();
chase.deposit("COLINYUAN01", 1000000);
System.out.println(chase.toString());
public double checkBalance (String userID) throws Exception
{
if (!database.containsKey (userID))
{
throw new Exception();

}
return database.get(userID);
}
}
17 changes: 17 additions & 0 deletions src/ATMTester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

public class ATMTester {
public static void main (String[] args) {
ATM chase = new ATM();
chase.deposit("Winfrey", 10.0);
chase.deposit("Bezos", 5.0);
chase.deposit("Bezos", 2.0);
chase.deposit("MrTheiss",13.0);
chase.withdraw("Bezos", 2.0);
chase.withdraw("MrTheiss", 15.0);
System.out.println(chase.checkBalance("Bezos"));
System.out.println(chase.checkBalance("Winfrey"));
System.out.println(chase.checkBalance("YoMama"));
System.out.println(chase.checkBalance("MrTheiss"));

}
}