I need an Eclipse code, Declare a class name BankAccount . The rest of the instr
ID: 3772623 • Letter: I
Question
I need an Eclipse code,
Declare a class name BankAccount. The rest of the instructions are for this class.
Declare three instance variables. The instance variables must be private. The first variable is of type String and named accountID.
The second variable is of type double and named balance.
The third variable is of type String and named dateOpened.
Declare a public constructor that takes in three parameters. The first parameter is of type String and is used to initialize the accountID instance variable. The second parameter is of type double and is used to initialize the balance. The third variable is of type String and is used to initialize the dateOpened instance variable.
Declare and write code for a public method named deposit that takes in a double input parameter and returns a value of type double. This method adds the amount passed in the input parameter variable to the balance and returns the updated balance.
Declare and write code for a public method named withdraw that takes in a double input parameter and returns a value of type boolean. If the amount being withdrawn is greater than the existing balance, then the method returns false. Else, it subtracts the amount being withdrawn from the balance and returns true.
Declare and write code for a public method named getDateOpened that takes in no parameters and returns a value of type String which is the date the account was opened.
-Thanks
Explanation / Answer
PROGRAM:
import java.io.*;
import java.util.Scanner;
class BankAccount
{
private String AccountID;
private double balance;
private String dateOpened;
public BankAccount(String AccountID,double balance,String dateOpened)
{
this.AccountID=AccountID;
this.balance=balance;
this.dateOpened=dateOpened;
}
public double deposite(double deposit)
{
return(balance+=deposit);
}
public boolean withdraw(double amount)
{boolean act=true;
if(this.balance<amount)
act=false;
else
{
this.balance=this.balance-amount;
act=true;
}
return act;
}
public String getDateOpened()
{
return(this.dateOpened);
}
public double getBalance()
{
return(this.balance);
}
}
class TestBankAccount {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
double depo,with,select=1;
BankAccount b1=new BankAccount("987456",25000.00,"12/5/2015");
Scanner scan=new Scanner(System.in);
while(select==1)
{
System.out.println("Enter Amount to deposite");
depo=scan.nextDouble();
System.out.println("Amount After Deposite is:"+b1.deposite(depo));
System.out.println("Enter Amount to withdraw");
with=scan.nextDouble();
System.out.println("Money withdraw is: "+b1.withdraw(with));
System.out.println("Enter 1 to continue");
select=scan.nextInt();
}
System.out.println("open date: "+b1.getDateOpened()+" and final balance"+b1.getBalance());
}
}
OUTPUT:
run:
Enter Amount to deposite
29000
Amount After Deposite is:54000.0
Enter Amount to withdraw
20000
Money withdraw is: true
Enter 1 to continue
1
Enter Amount to deposite
42000
Amount After Deposite is:76000.0
Enter Amount to withdraw
50000
Money withdraw is: true
Enter 1 to continue
0
open date: 12/5/2015 and final balance26000.0
BUILD SUCCESSFUL (total time: 35 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.