Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a class called Account which defines a modified banking account that c

ID: 3548321 • Letter: I

Question

Implement a class called Account which defines a modified banking account that can be created with a given balance and account name. It must be able to perform the following operations in the public interface:

? Accepts an amount to deposit the balance

? Withdraws an amount from the balance

? Returns its balance

? Returns its name

? Displays its name and balance

Write a Java application called AccountSystem to simulate an instance of the class. You need to use deposit and withdrawal methods in this program.

Explanation / Answer

public class account{

int balance;

String accountName;


account(){

balance = 0;

}


account(int x,String name){

balance = x;

accountName = name;

}


void acceptAmount(int x){

balance += x;

}


int withDrawAmount(int x){

if(balance > x){

balance -= x;

return 1;

}

else{

return 0;

}

}


int getBalance(){

return balance;

}


String getName(){

return accountName;

}


void print(){

System.out.println("balance = " + balance);

System.out.println("accountName = " + accountName);

}

};


class accountSystem{

public static void main(String []args){

account a = new account(100,"john");


a.acceptAmount(2000);


int x = a.withDrawAmount(500);


a.print();

}

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote