import java.util.*;
public class Account
{
int choice,initbal,amt,total,withdraw;
int ch;
void Initbal()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Initial Balance (>200) : ");
initbal=Integer.parseInt(sc.nextLine());
while(initbal<200)
{
System.out.println("LOW BALANCE!!!Balance should be greater than Rs.200");
System.out.println("Enter again : ");
initbal=Integer.parseInt(sc.nextLine());
}
}
void Detail()
{
Scanner sc=new Scanner(System.in);
System.out.println("***************MENU***************");
System.out.println("1. Deposit");
System.out.println("2. Withdrawl");
System.out.println("3. Account Details");
System.out.println("4. Exit");
System.out.println("Enter Choice : ");
ch=Integer.parseInt(sc.nextLine());
switch(ch)
{
case 1:
{
System.out.println("Enter Amount : ");
amt=Integer.parseInt(sc.nextline());
System.out.println("Amount Deposited Successfully!!!");
total=initbal+amt;
System.out.println("Total Balance = Rs." +total);
break;
}
case 2:
{
System.out.println("Enter amount to be withdrawn : ");
withdraw=Integer.parseInt(sc.nextLine());
left=total-withdraw;
if(left<=200)
{
System.out.println("Transaction Failed!!!");
System.out.println("Your minimum balance should be Rs.200");
}
else
{
System.out.println("Transaction Successfull!!!");
System.out.println("Your remaining balance is Rs." +left);
}
break;
}
case 3:
{
System.out.println("----------ACCOUNT DETAILS----------");
System.out.println("NAME : " +name);
System.out.println("AGE : " +age);
if(choice==1)
{
System.out.println("SAVINGS");
}
else if(choice==2)
{
System.out.println("CURRENT");
}
else if(choice==3)
{
System.out.println("FIXED DEPOSIT");
}
else if(choice==4)
{
System.out.println("RECURRING DEPOSIT");
}
else
{
System.out.println("NULL");
}
System.out.println("ACCOUNT TYPE : " +choice);
System.out.println("BALANCE :Rs." +total);
break;
}
case 4:
{
System.out.println("EXIT.....");
break;
}
default:
{
System.out.println("WRONG CHOICE!!!");
}
}
int showData()
{
Scanner sc=new Scanner(System.in);
System.out.println("------ACCOUNT TYPE------");
System.out.println("1. Savings");
System.out.println("2. Current");
System.out.println("3. Fixed Deposit");
System.out.println("4. Recurring Deposit");
System.out.println("Enter Choice : ");
choice=Integer.parseInt(sc.nextLine());
switch(choice)
{
case 1:
{
System.out.println("-----WELCOME TO YOUR SAVINGS ACCOUNT-----");
Initbal();
Detail();
break;
}
case 2:
{
System.out.println("-----WELCOME TO YOUR CURRENT ACCOUNT-----");
Initbal();
Detail();
break;
}
case 3:
{
System.out.println("-----WELCOME TO YOUR FIXED DEPOSIT ACCOUNT-----");
Initbal();
Detail();
break;
}
case 4:
{
System.out.println("-----WELCOME TO YOUR RECURRING DEPOSIT ACCOUNT-----");
Initbal();
Detail();
break;
}
default:
{
System.out.println("ERROR!!!");
System.exit(0);
break;
}
}
public class Bank extends Account
{
public static void main(String args[])
{
Account obj=new Account();
Scanner sc=new Scanner(System.in);
System.out.println("$$$$$$$$$$$$------WELCOME TO ABC BANK------$$$$$$$$$$$$");
System.out.println("Enter Name : ");
String name=sc.nextLine();
System.out.println("Enter Age : ");
int age=Integer.parseInt(sc.nextLine());
while(age<18)
{
System.out.println("Age is less than 18!!!");
System.out.println("Enter Age again : ");
age=Integer.parseInt(sc.nextLine());
}
obj.showData();
}
}
simransuri -4 Newbie Poster
Recommended Answers
Jump to PostUnless there's some other code somewhere else, this code creates an Account object and updates it IN MEMORY. When the program exits, all that info is lost, so next time you run it you are back to square 1 again.
To keep the account info from one run to the …
Jump to PostIt's your code, and you have to fix it. Have a variable for current balance and for every transaction of every kind, update the current Balance.
All 5 Replies
jon.kiparsky 326 Posting Virtuoso
simransuri -4 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
simransuri -4 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.