ank.java import java.util.Hashtable; import java.util.Iterator; public class Ban
ID: 3695669 • Letter: A
Question
ank.java
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("Jake", "1", 100.00);
Customer customer2 = new Customer("Jack", "2", 100.00);
Customer customer3 = new Customer("John", "3", 100.00);
Customer customer4 = new Customer("Bob", "4", 100.00);
Customer customer5 = new Customer("Paul", "5", 100.00);
Customer customer6 = new Customer("Sarah", "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();
}
}
Customer.java
public class Customer {
private String name;
private String accountNumber;
private double balance;
public Customer(String name, String accountNumber, double balance) {
this.name = name;
this.accountNumber = accountNumber;
this.balance = balance;
}
public String getName() { return name; }
public String getAccountNumber() { return accountNumber; }
public double getBalance() { return balance; }
public void deposit(double amount) {
balance += amount;
}
public boolean withdraw(double amount) {
if (amount > balance)
return false;
balance -= amount;
return true;
}
public String toString() {
return "Name: " + name + " Account Number: " + accountNumber + " Balance: " + balance;
}
}
Bank.java:1: error: class, interface, or enum expected
ank.java
^
Bank.java:19: error: ')' expected
customers.put(aCustomer.getAccountNu... aCustomer);
^
Bank.java:19: error: not a statement
customers.put(aCustomer.getAccountNu... aCustomer);
^
Bank.java:19: error: ';' expected
customers.put(aCustomer.getAccountNu... aCustomer);
^
Bank.java:24: error: ')' expected
customers.remove(aCustomer.getAccoun...
^
Bank.java:31: error: ')' expected
aCustomer.deposit(aCustomer.getBala... * INTEREST_RATE);
^
Bank.java:31: error: illegal start of expression
aCustomer.deposit(aCustomer.getBala... * INTEREST_RATE);
^
Bank.java:31: error: ';' expected
aCustomer.deposit(aCustomer.getBala... * INTEREST_RATE);
^
Bank.java:39: error: ')' expected
System.out.println(aCustomer.toStri...
^
Customer.java:2: error: class, interface, or enum expected
Customer.java
^
1 error
These are my errors... what is wrong?
Explanation / Answer
Hello I can able to compiled and run this program successfully;(I have corrected errors in your program.)
Thats Why I attached the output also.
first compile the org.students.Customer.java , later compile org.students.Bank.java.here org.students is the package name. so the full name of the class is org.students.Bank.java and org.students.Customer.java
Its good practice to place the class names inside the package.
To compile the classe which are in package.
javac -d . org.students.Customer.java
javac -d . org.students.Bank.java
As the main method is present in org.students.Bank.java we have to run that program.Which results the output.
Its absolutely running and getting the output.
-----------------------------------------------------------------------------------------------------------------------------------------------
Customer.java
package org.students;
public class Customer {
private String name;
private String accountNumber;
private double balance;
public Customer(String name, String accountNumber, double balance) {
this.name = name;
this.accountNumber = accountNumber;
this.balance = balance;
}
public String getName() { return name; }
public String getAccountNumber() { return accountNumber; }
public double getBalance() { return balance; }
public void deposit(double amount) {
balance += amount;
}
public boolean withdraw(double amount) {
if (amount > balance)
return false;
balance -= amount;
return true;
}
public String toString() {
return "Name: " + name + " Account Number: " + accountNumber + " Balance: " + balance;
}
}
_______________________________________________________________________________________
Bank.java
package org.students;
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("Jake", "1", 100.00);
Customer customer2 = new Customer("Jack", "2", 100.00);
Customer customer3 = new Customer("John", "3", 100.00);
Customer customer4 = new Customer("Bob", "4", 100.00);
Customer customer5 = new Customer("Paul", "5", 100.00);
Customer customer6 = new Customer("Sarah", "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();
}
}
_______________________________________________________________________________________
output:
Name: Sarah Account Number: 6 Balance: 100.0
Name: Paul Account Number: 5 Balance: 100.0
Name: Bob Account Number: 4 Balance: 100.0
Name: John Account Number: 3 Balance: 100.0
Name: Jack Account Number: 2 Balance: 100.0
Name: Jake Account Number: 1 Balance: 100.0
Name: Sarah Account Number: 6 Balance: 103.0
Name: Paul Account Number: 5 Balance: 103.0
Name: Bob Account Number: 4 Balance: 103.0
Name: John Account Number: 3 Balance: 103.0
Name: Jack Account Number: 2 Balance: 103.0
Name: Jake Account Number: 1 Balance: 103.0
____________________________________________________________________________________
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.