
Create a Bank class with methods deposit & withdraw. The deposit method would accept attributes amount & balance & returns the new balance which is the sum of amount & balance. Similarly, the withdraw method would accept the attributes amount & balance & returns the new balance ?balance ? amount? if balance > = amount or return 0 otherwise.

Hi Friend,
Try the following code:
import javax.swing.*;
class Customer{
int bal;
Customer(int bal) {
this.bal = bal;
}
int deposit(int amt) {
if (amt < 0) {
System.out.println("Invalid Amount");
return 1;
}
bal = bal + amt;
return 0;
}
int withdraw(int amt) {
if (bal < amt) {
System.out.println("Not sufficient balance.");
return 1;
}
if (amt < 0) {
System.out.println("Invalid Amount");
return 1;
}
bal = bal - amt;
return 0;
}
void check() {
JOptionPane.showMessageDialog(null,"Balance:" + Integer.toString(bal));
}
}
public class Bank{
public static void main(String[]args){
Customer Cust=new Customer(1500);
String st1=JOptionPane.showInputDialog(null,"Enter the amount to deposit:");
int dep=Integer.parseInt(st1);
int bal1=Cust.deposit(dep);
Cust.check();
String st2=JOptionPane.showInputDialog(null,"Enter the amount to withdraw:");
int with=Integer.parseInt(st2);
int bal2=Cust.withdraw(with);
Cust.check();
}
}
Thanks