Advertisement
Ishmam_Rahman

Java.3

May 5th, 2021
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. // Online Java Compiler
  2. // Use this editor to write, compile and run your Java code online
  3. import java.util.*;
  4.  
  5. class MyAccount {
  6.     private String password = "Riya108";
  7.     private double cash=0;
  8.    
  9.     private double deposite(double amount){
  10.         cash+=amount;
  11.         System.out.println(cash);
  12.         return amount;
  13.     }
  14.    
  15.     private double withdraw(double amount){
  16.         if(amount<=cash){
  17.             cash-=amount;
  18.             System.out.println(cash);
  19.         }
  20.         return amount;
  21.     }
  22.    
  23.     public double cash_deposite(double amount){
  24.         Scanner sc= new Scanner(System.in);
  25.        
  26.         System.out.println("Enter password:");
  27.         String pass= sc.nextLine();
  28.        
  29.         if(pass.equals(password)==true){
  30.             return deposite(amount);
  31.         }
  32.         else return cash;
  33.     }
  34.    
  35.     public double cash_withdraw(double amount){
  36.         Scanner sc= new Scanner(System.in);
  37.        
  38.         System.out.println("Enter password:");
  39.         String pass= sc.nextLine();
  40.        
  41.         if(pass.equals(password)==true){
  42.             return withdraw(amount);
  43.         }
  44.         else return cash;
  45.     }
  46. }
  47.  
  48. class HelloWorld {
  49.     public static void main(String[] args) {
  50.         MyAccount obj = new MyAccount();
  51.        
  52.         obj.cash_deposite(3330);
  53.         obj.cash_withdraw(330);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement