Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Online Java Compiler
- // Use this editor to write, compile and run your Java code online
- import java.util.*;
- class MyAccount {
- private String password = "Riya108";
- private double cash=0;
- private double deposite(double amount){
- cash+=amount;
- System.out.println(cash);
- return amount;
- }
- private double withdraw(double amount){
- if(amount<=cash){
- cash-=amount;
- System.out.println(cash);
- }
- return amount;
- }
- public double cash_deposite(double amount){
- Scanner sc= new Scanner(System.in);
- System.out.println("Enter password:");
- String pass= sc.nextLine();
- if(pass.equals(password)==true){
- return deposite(amount);
- }
- else return cash;
- }
- public double cash_withdraw(double amount){
- Scanner sc= new Scanner(System.in);
- System.out.println("Enter password:");
- String pass= sc.nextLine();
- if(pass.equals(password)==true){
- return withdraw(amount);
- }
- else return cash;
- }
- }
- class HelloWorld {
- public static void main(String[] args) {
- MyAccount obj = new MyAccount();
- obj.cash_deposite(3330);
- obj.cash_withdraw(330);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement