Advance lab-3
Lab test and code of 3rd Advance Programming Lab. Pritom Banik Date : 22/9/2024unknown
plain_text
a year ago
3.1 kB
22
Indexable
//We all know that java is an object-oriented programming language. Suppose you are
//assigned to develop a banking system using the basic concepts of OOP in java. The
//system consists of a class named BankAccount which has the following private
//attributes (depositorName, typeOfAccount, AccountNumber and Balance) and
//public methods (constructor, depositAmmount, withdrawAmmount,
//displayNameAndBalance). There will be two types of account for 3 banks (Agrani,
//Sonali, Janata) in consideration: Savings and FixedDeposit. The interest rate for
//savings is 1% for all banks. Whereas, the interest rate for Fixed Deposit account is 3%
//for Agrani Bank, 2.5% for Janata Bank and 2% for Sonali Bank.
import java.util.Scanner;
class BankAccount{
private String name;
private int account_no;
private boolean typeOfAccount; // savings = 0 fixed deposit =1;
private double balance;
public BankAccount(){
name="";
account_no=0;
typeOfAccount=false;
balance=0;
}
public BankAccount(String name,int account_no,boolean typeOfAccount,double balance){
this.name=name;
this.account_no=account_no;
this.typeOfAccount=typeOfAccount;
this.balance=balance;
}
public void OpenNewAccount(){
Scanner input =new Scanner(System.in);
System.out.println("Wellcome in our Bank");
System.out.print("Give your name : ");
name=input.nextLine();
System.out.print("Give a number for your account :");
account_no=input.nextInt();
System.out.print("Type of account (0 = savings , 1 = fixed deposit) : ");
typeOfAccount=input.nextBoolean();
System.out.print("Write the ammount number you want to start with : ");
balance=input.nextDouble();
input.close();
}
public void depositAmmount(double ammount){
balance=balance+ammount;
}
public void withdrawAmmount(double ammount){
balance=balance-ammount;
}
public void displayNameandBalance(){
System.out.println("Name : "+name);
System.out.println("Account Number : "+account_no);
System.out.println("Balance : "+balance);
}
}
class Agrani extends BankAccount{
Agrani(){
super();
}
Agrani(String name,int account_no,boolean typeOfAccount,double balance){
super(name,account_no,typeOfAccount,balance);
}
}
class Sonali extends BankAccount{
Sonali(){
super();
}
Sonali(String name,int account_no,boolean typeOfAccount,double balance){
super(name,account_no,typeOfAccount,balance);
}
}
class Janata extends BankAccount{
Janata(){
super();
}
Janata(String name,int account_no,boolean typeOfAccount,double balance){
super(name,account_no,typeOfAccount,balance);
}
}
public class Main{
public static void main(String[] args){
System.out.println("Hello World");
Janata ac=new Janata("Pritom Banik",52,false,100);
ac.displayNameandBalance();
}
}Editor is loading...
Leave a Comment