Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lat;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- class Account
- {
- public int id;
- public double balance;
- public Account()
- {
- id=0;
- balance=0;
- }
- public Account(int a, double b)
- {
- id=a;
- balance=b;
- }
- public double getBalance()
- {
- return balance;
- }
- public void deposit(double a)
- {
- balance=balance+a;
- }
- public void withdraw(double a)
- {
- if(a<=balance)
- {
- balance=balance-a;
- }
- else
- {
- System.out.println("Not enough money");
- }
- }
- }
- public class lat
- {
- public static void main(String args[])
- {
- Account[] account=new Account[10];
- for(int i=0; i<10; i++)
- {
- account[i]=new Account(i,100);
- }
- while(true)
- {
- Scanner s=new Scanner(System.in);
- System.out.print("Enter your account ID: ");
- int id=s.nextInt();
- while(id > 10 || id < 0)
- {
- System.out.print("Please try again: ");
- id=s.nextInt();
- }
- while(true)
- {
- System.out.println("\nWelcome!!!");
- System.out.println("1: Current balance");
- System.out.println("2: Withdraw");
- System.out.println("3: Deposit");
- System.out.println("4: Exit");
- int choice=s.nextInt();
- if(choice==1)
- {
- System.out.println("Your current balance: $"+account[id].getBalance());
- }
- else if (choice==2)
- {
- System.out.print("Enter the amount to deposit: ");
- double deposit=s.nextDouble();
- account[id].deposit(deposit);
- }
- else if(choice==3)
- {
- System.out.print("Enter the amount to withdraw: ");
- double withdraw=s.nextDouble();
- account[id].withdraw(withdraw);
- }
- else if(choice==4)
- {
- System.out.println("Logging out...");
- System.out.print("Enter your ID: ");
- int fid=s.nextInt();
- while(fid!=id)
- {
- System.out.print("Please try again: ");
- id=s.nextInt();
- }
- System.out.println("Successfully logged out. Thank you for banking with Longitude Banking.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement