Define the class bankAccount to implement the basic properti

Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). Add appropriate member functions to manipulate an object. Your program only needs to deal with one account. Write a test program to illustrate how to use your class.

As an example, a sample run should look similar to the following (realize the same functionalities):

1: Enter 1 to add a new customer.

2: Enter 2 for an existing customer.

3: Enter 3 to print customer’s data.

9: Enter 9 to exit the program.

1

Enter customer\'s name: zhu wang

Enter account type (checking/savings): checking

Enter the account number you would like to use: 12345

Enter amount to be deposited to open account: 300

Enter interest rate (as a percent): 0.8

1: Enter 1 to add a new customer.

2: Enter 2 for an existing customer.

3: Enter 3 to print customer’s data.

9: Enter 9 to exit the program.

2

Enter account number:

123

Invalid customer id.

1: Enter 1 to add a new customer.

2: Enter 2 for an existing customer.

3: Enter 3 to print customer’s data.

9: Enter 9 to exit the program.

2

Enter account number:

12345

1: Enter 1 to make a deposit.

2: Enter 2 to withdraw.

3: Enter 3 to check balance.

9: Enter 9 to exit.

1

Enter amount to be deposited: 20

1: Enter 1 to make a deposit.

2: Enter 2 to withdraw.

3: Enter 3 to check balance.

9: Enter 9 to exit.

3

Account Holder Name: zhu wang

Account Type: checking

Account Number: 12345

Balance: $320.00

Interest Rate: 0.80%

1: Enter 1 to make a deposit.

2: Enter 2 to withdraw.

3: Enter 3 to check balance.

9: Enter 9 to exit.

2

Enter amount to be withdrawn: 160

1: Enter 1 to make a deposit.

2: Enter 2 to withdraw.

3: Enter 3 to check balance.

9: Enter 9 to exit.

3

Account Holder Name: zhu wang

Account Type: checking

Account Number: 12345

Balance: $160.00

Interest Rate: 0.80%

1: Enter 1 to make a deposit.

2: Enter 2 to withdraw.

3: Enter 3 to check balance.

9: Enter 9 to exit.

9

1: Enter 1 to add a new customer.

2: Enter 2 for an existing customer.

3: Enter 3 to print customer’s data.

9: Enter 9 to exit the program.

3

Account Holder Name: zhu wang

Account Type: checking

Account Number: 12345

Balance: $160.00

Interest Rate: 0.80%

1: Enter 1 to add a new customer.

2: Enter 2 for an existing customer.

3: Enter 3 to print customer’s data.

9: Enter 9 to exit the program.

9

Solution

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;


public class BankAccount {
private double balance,interest;
private int accountNumber;
private String name,type;
  
public BankAccount(double balance,double interest,int accountNumber,String name,String type)
{
this.accountNumber = accountNumber;
this.balance = balance;
this.interest = interest;
this.name = name;
this.type = type;
}
  
public int getAccountNumber()
{
return this.accountNumber;
}
  
public String getAccountType()
{
return this.type;
}
  
public String getAccountName()
{
return this.name;
}
  
  
public double getBalance()
{
return this.balance;
}

  
public double getInterest(double interest)
{
return this.interest;
}
  
public void setAccountNumber(int accountNumber)
{
this.accountNumber = accountNumber;
}
  
public void setAccountType(String type)
{
this.type = type;
}
  
public void setBalance(double balance)
{
this.balance = balance;
}
  
public void setAccountName(String name)
{
this.name = name;
}

  
public void setInterest(double interest)
{
this.interest = interest;
}
  
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(\"Account Holder Name : \"+name + \"\ \");
sb.append(\"Account Type : \" + type + \"\ \");
sb.append(\"Account Number : \"+accountNumber + \"\ \");
sb.append(\"Balance : $\"+balance + \"\ \");
sb.append(\"Interest Rate : \"+interest + \"%\ \");
return sb.toString();
}
  
public void deposit(double balance)
{
this.balance += balance;
}
  
public void withdraw(double balance)
{
this.balance -= balance;
}
}


package chegg;

import java.util.ArrayList;
import java.util.Scanner;

public class BankAccountTest {
  
public static BankAccount addNewCustomer()
{
double balance,interest;
String name,type;
int number;
Scanner input = new Scanner(System.in);
  
System.out.println(\"Enter customer\'s name:\");
name = input.nextLine();
  
System.out.println(\"Enter account type (checking/savings):\");
type = input.nextLine();
  
System.out.println(\"Enter the account number you would like to use:\");
number = input.nextInt();
  
System.out.println(\"Enter amount to be deposited to open account:\");
balance = input.nextDouble();
  
System.out.println(\"Enter interest rate (as a percent):\");
interest = input.nextDouble();
  
return new BankAccount(balance, interest, number, name, type);
}
  
public static void showCustomerOptions(BankAccount b)
{
Scanner input = new Scanner(System.in);
int choice;
double balance;
  
do
{

System.out.println(\"1: Enter 1 to make a deposit.\ \" +
\"2: Enter 2 to withdraw.\ \" +
\"3: Enter 3 to check balance.\ \" +
\"9: Enter 9 to exit.\");
choice = input.nextInt();
  
switch(choice)
{
case 1:
System.out.println(\"Enter amount to be deposited:\");
balance = input.nextDouble();
b.deposit(balance);
break;
  
case 2:
System.out.println(\"Enter amount to be withdrawn:\");
balance = input.nextDouble();
b.withdraw(balance);
break;
  
case 3:
System.out.println(b);
break;
  
case 9:
break;
  
default:
System.out.println(\"Invalid Choice.\");
break;
}
}while(choice!=9);
  
}
  
//main method
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
BankAccount ba = null;
int accnumber;
ArrayList listAccountNumber = new ArrayList();
int choice;
do
{
System.out.println(\"1: Enter 1 to add a new customer.\ \" +
\"2: Enter 2 for an existing customer.\ \" +
\"3: Enter 3 to print customer’s data.\ \" +
\"9: Enter 9 to exit the program.\");
choice = input.nextInt();
  
switch(choice)
{
case 1:
ba = addNewCustomer();
listAccountNumber.add(ba.getAccountNumber());
break;
  
case 2:
System.out.println(\"Enter account number : \");
accnumber = input.nextInt();
if(listAccountNumber.contains(accnumber) == false)
System.out.println(\"Invalid Customer Id\");
else
showCustomerOptions(ba);
break;
  
case 3:
if(ba != null)
System.out.println(ba);
else
System.out.println(\"No customer present.\");
break;
  
case 9:
break;
  
default:
System.out.println(\"Invalid choice.\");
break;
}
}while(choice!=9);
}
}

OUTPUT:

run:
1: Enter 1 to add a new customer.
2: Enter 2 for an existing customer.
3: Enter 3 to print customer’s data.
9: Enter 9 to exit the program.
1
Enter customer\'s name:
zhu wang
Enter account type (checking/savings):
checking
Enter the account number you would like to use:
12345
Enter amount to be deposited to open account:
300
Enter interest rate (as a percent):
0.8
1: Enter 1 to add a new customer.
2: Enter 2 for an existing customer.
3: Enter 3 to print customer’s data.
9: Enter 9 to exit the program.
2
Enter account number :
123
Invalid Customer Id
1: Enter 1 to add a new customer.
2: Enter 2 for an existing customer.
3: Enter 3 to print customer’s data.
9: Enter 9 to exit the program.
2
Enter account number :
12345
1: Enter 1 to make a deposit.
2: Enter 2 to withdraw.
3: Enter 3 to check balance.
9: Enter 9 to exit.
1
Enter amount to be deposited:
20
1: Enter 1 to make a deposit.
2: Enter 2 to withdraw.
3: Enter 3 to check balance.
9: Enter 9 to exit.
3
Account Holder Name : zhu wang
Account Type : checking
Account Number : 12345
Balance : $320.0
Interest Rate : 0.8%

1: Enter 1 to make a deposit.
2: Enter 2 to withdraw.
3: Enter 3 to check balance.
9: Enter 9 to exit.
2
Enter amount to be withdrawn:
160
1: Enter 1 to make a deposit.
2: Enter 2 to withdraw.
3: Enter 3 to check balance.
9: Enter 9 to exit.
3
Account Holder Name : zhu wang
Account Type : checking
Account Number : 12345
Balance : $160.0
Interest Rate : 0.8%

1: Enter 1 to make a deposit.
2: Enter 2 to withdraw.
3: Enter 3 to check balance.
9: Enter 9 to exit.
9
1: Enter 1 to add a new customer.
2: Enter 2 for an existing customer.
3: Enter 3 to print customer’s data.
9: Enter 9 to exit the program.
3
Account Holder Name : zhu wang
Account Type : checking
Account Number : 12345
Balance : $160.0
Interest Rate : 0.8%

1: Enter 1 to add a new customer.
2: Enter 2 for an existing customer.
3: Enter 3 to print customer’s data.
9: Enter 9 to exit the program.
9
BUILD SUCCESSFUL (total time: 1 minute 4 seconds)

Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name
Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name
Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name
Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name
Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name
Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name
Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name
Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site