import java.util.Hashtable; import java.util.Iterator; public class Bank { priva
ID: 3698075 • Letter: I
Question
import java.util.Hashtable;
import java.util.Iterator;
public class Bank {
private Hashtable<String, Customer> customers;
private static int MAXCUSTOMERS = 30;
private static double INTEREST_RATE = .03;
public Bank() {
customers = new Hashtable<String, Customer>();
}
public boolean addCustomer(Customer aCustomer) {
int numberOfCustomers = customers.size();
if (numberOfCustomers >= MAXCUSTOMERS)
return false;
customers.put(aCustomer.getAccountNu... aCustomer);
return true;
}
public void removeCustomer(Customer aCustomer) {
customers.remove(aCustomer.getAccoun...
}
public void addInterest() {
Iterator<Customer> i = customers.values().iterator();
while (i.hasNext()) {
Customer aCustomer = i.next();
aCustomer.deposit(aCustomer.getBala... * INTEREST_RATE);
}
}
public void showCustomers() {
Iterator<Customer> i = customers.values().iterator();
while (i.hasNext()) {
Customer aCustomer = i.next();
System.out.println(aCustomer.toStri...
}
}
public static void main(String[] args) {
Customer customer1 = new Customer("Bob", "1", 100.00);
Customer customer2 = new Customer("Bill", "2", 100.00);
Customer customer3 = new Customer("Benny", "3", 100.00);
Customer customer4 = new Customer("Bubba", "4", 100.00);
Customer customer5 = new Customer("Bertha", "5", 100.00);
Customer customer6 = new Customer("Betty", "6", 100.00);
Bank aBank = new Bank();
aBank.addCustomer(customer1);
aBank.addCustomer(customer2);
aBank.addCustomer(customer3);
aBank.addCustomer(customer4);
aBank.addCustomer(customer5);
aBank.addCustomer(customer6);
aBank.showCustomers();
aBank.addInterest();
aBank.showCustomers();
}
}
here are the errors i get when i compile:
Bank.java:17: error: ')' expected
customers.put(aCustomer.getAccountNu... aCustomer);
^
Bank.java:17: error: not a statement
customers.put(aCustomer.getAccountNu... aCustomer);
^
Bank.java:17: error: ';' expected
customers.put(aCustomer.getAccountNu... aCustomer);
^
Bank.java:22: error: ')' expected
customers.remove(aCustomer.getAccoun...
^
Bank.java:29: error: ')' expected
aCustomer.deposit(aCustomer.getBala... * INTEREST_RATE);
^
Bank.java:29: error: illegal start of expression
aCustomer.deposit(aCustomer.getBala... * INTEREST_RATE);
^
Bank.java:29: error: ';' expected
aCustomer.deposit(aCustomer.getBala... * INTEREST_RATE);
^
Bank.java:37: error: ')' expected
System.out.println(aCustomer.toStri...
I dont understand why i get these.
Explanation / Answer
Hi, I have modified your code. It is not error free. Highlighted areas are the code changes.
Bank.java
package smith20;
import java.util.Hashtable;
import java.util.Iterator;
public class Bank {
private Hashtable<String, Customer> customers;
private static int MAXCUSTOMERS = 30;
private static double INTEREST_RATE = .03;
public Bank() {
customers = new Hashtable<String, Customer>();
}
public boolean addCustomer(Customer aCustomer) {
int numberOfCustomers = customers.size();
if (numberOfCustomers >= MAXCUSTOMERS)
return false;
customers.put(aCustomer.getAccountNumber(), aCustomer);
return true;
}
public void removeCustomer(Customer aCustomer) {
customers.remove(aCustomer.getAccountNumber());
}
public void addInterest() {
Iterator<Customer> i = customers.values().iterator();
while (i.hasNext()) {
Customer aCustomer = i.next();
aCustomer.deposit(aCustomer.getBalance() * INTEREST_RATE);
}
}
public void showCustomers() {
Iterator<Customer> i = customers.values().iterator();
while (i.hasNext()) {
Customer aCustomer = i.next();
System.out.println(aCustomer.toString());
}
}
public static void main(String[] args) {
Customer customer1 = new Customer("Bob", "1", 100.00);
Customer customer2 = new Customer("Bill", "2", 100.00);
Customer customer3 = new Customer("Benny", "3", 100.00);
Customer customer4 = new Customer("Bubba", "4", 100.00);
Customer customer5 = new Customer("Bertha", "5", 100.00);
Customer customer6 = new Customer("Betty", "6", 100.00);
Bank aBank = new Bank();
aBank.addCustomer(customer1);
aBank.addCustomer(customer2);
aBank.addCustomer(customer3);
aBank.addCustomer(customer4);
aBank.addCustomer(customer5);
aBank.addCustomer(customer6);
aBank.showCustomers();
aBank.addInterest();
aBank.showCustomers();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.