This code is implemented by Pankaj kumar Gupta/BRANCH ECE/NIT, Arunachal pradesh
# Save this class inside Bank.java file #
import java.io.*;
public class Bank{
private int customer_id;
private String customer_name;
private float customer_amount;
public void information(int id,String name,float amt){
customer_name=name;
customer_id=id;
customer_amount=amt;
}
public void deposit(float amt){
customer_amount+=amt;
System.out.println("Dear "+customer_name+" Your amount "+amt+" Rs are sucessfully deposited in your account "+customer_id+" \nThank you");
}
public void enquiry(){
System.out.println("Dear "+customer_name+" Your amount account "+customer_id+" have total balance= "+customer_amount+"\nThank you");
}
public void Withdrawl(float amt){
if(customer_amount>=amt){
customer_amount-=amt;
System.out.println("Dear "+customer_name+" Your amount "+amt+" Rs are sucessfully withdrawn from your account "+customer_id+"\nand your current balance is "+customer_amount+"rs \nThank you");
}
else
System.out.println("you don't have sufficient ammount in your account");
}
}
# Save this class inside Customer.java file #
import java.util.*;
public class Customer{
public static void main(String[] arg){
Scanner sc=new Scanner(System.in);
Scanner sc1=new Scanner(System.in);
Bank bank=new Bank();
System.out.println("Please enter customer id");
int id = sc.nextInt();
System.out.println("Please enter customer Name");
String name = sc1.nextLine();
System.out.println("Please enter customer Intital account balance");
float bal = sc.nextFloat();
bank.information(id,name,bal);
String temp="y";
boolean condition=true;
while(condition){
System.out.println(".......Menu..........");
System.out.println("Press 1 for deposit");
System.out.println("Press 2 for withdrawn balance");
System.out.println("Press 3 for balance enquiry");
int choice=sc.nextInt();
switch(choice){
case 1:
System.out.println("Enter the ammount that you want to deposit ");
float amt=sc.nextFloat();
bank.deposit(amt);
System.out.println("Do you want to continue(y/n)");
temp=sc.next();
if(temp.equalsIgnoreCase("y"))
condition=true;
else
condition=false;
break;
case 2:
System.out.println("Enter the ammount that you want to withdrawn ");
float wdn=sc.nextFloat();
bank.Withdrawl(wdn);
System.out.println("Do you want to continue(y/n)");
temp=sc.next();
if(temp.equalsIgnoreCase("y"))
condition=true;
else
condition=false;
break;
case 3:
bank.enquiry();
System.out.println("Do you want to continue(y/n)");
temp=sc.next();
if(temp.equalsIgnoreCase("y"))
condition=true;
else
condition=false;
break;
default :
System.out.println("sorry!! you entered wrong choice");
System.out.println("Do you want to continue(y/n)");
temp=sc.next();
if(temp.equalsIgnoreCase("y"))
condition=true;
else
condition=false;
}
}
System.out.println("Thank you for using bank");
}
}
No comments:
Post a Comment