question archive Create class called BankAccount that keeps track of the account holder's name, the account number, and the balance in the account
Subject:Computer SciencePrice: Bought3
Create class called BankAccount that keeps track of the account holder's name, the account number, and the balance in the account. Create 2 constructors, a toString() method, and withdraw(amount) and deposit(amount) methods. Use the this keyword in the constructor and methods. Test your class in a main method.
class Account{
private double balance;
private String name;
private long acctNum;
public String getName ()
{
return this.name;
}
public void setName (String owner)
{
this.name = owner;
}
public double getBalance ()
{
return this.balance;
}
public void setBalance (double amt)
{
this.balance = amt;
}
public Account(double initBal, String owner, long number)
{
this.balance = initBal;
this.name = owner;
this.acctNum = number;
}
public void withdraw (double amount)
{
if (this.balance >= amount)
this.balance -= amount;
else
System.out.println("Insufficient funds");
}
public void deposit (double amount)
{
this.balance += amount;
}
public String toString ()
{
return "Account holder's name: " + this.name +"nAccount Number: " + this.acctNum+ " Account Balance: " +balance;
}
}
public class BankAccount {
public static void main(String[] args)
{
Account acct1 = new Account(10000, "priscilla" , 115286);
System.out.println(acct1);
acct1.deposit(2000);
System.out.println("Balance in "+acct1.getName()+" account after deposit is: "+acct1.getBalance());
acct1.withdraw(5000);
System.out.println("Balance in "+acct1.getName()+" account after withdrawl is: "+acct1.getBalance());
Account acct2 = new Account(30000, "Rudra Pratap", 118866);
acct2.deposit(15000);
System.out.println("Balance in "+acct2.getName()+" account after deposit is: "+acct2.getBalance());
acct2.withdraw(5000);
System.out.println("Balance in "+acct2.getName()+" account after withdrawl is: "+acct2.getBalance());
System.out.println(acct2);
System.out.println();
}
}
-Checking Private Instance Variable(s). Expected 3 Private.
-Checking 3 parameter constructor pass
Hi there ! Please help me to solve this code with 3 Private instance variable and pass the 3 parameter constructor. Thanks!