Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Object Oriented Programming Lab (Java) - OOPL

(EC – 695A)
ECE – 6th Sem. – 3rd Year

1. Write a Program in Java to print the bank details of two persons using method.

Program:
File Name: BankAcc.java

public class BankAcc


{
String name;
float amount;

public void setValue(String nm, float amnt)


{
name=nm;
amount=amnt;
}

public void getValue()


{
System.out.println("Your Name: " +name);
System.out.println("Your amount is: " +amount +"\n");
}

public static void main(String args[])


{
BankAcc obj1;
obj1=new BankAcc();

obj1.setValue("Soumen Pal",7000);

BankAcc obj2=new BankAcc();


obj2.setValue("Animesh Mondal",8000.50f);

obj1.getValue();
obj2.getValue();
}
}

OUTPUT:
E:\JAVA\JAVA_FILES>javac BankAcc.java

E:\JAVA\JAVA_FILES>java BankAcc
Your Name: Soumen Pal
Your amount is: 7000.0

Your Name: Animesh Mondal


Your amount is: 8000.5
Assignment No. – I Page - 1 Khatibur Rahman, 17/ECE/63, ECE Dept, FIEM
Object Oriented Programming Lab (Java) - OOPL
(EC – 695A)
ECE – 6th Sem. – 3rd Year

2. Write a Program in Java to show the bank details using method overloading.

Program:
File Name: BankAcc1.java

public class BankAcc1


{
String name;
float amount;

public void setValue(String nm, float amnt)


{
name=nm;
amount=amnt;
}

public void setValue(String nm)


{
name=nm;
}

public void setValue(float amnt)


{
amount=amnt;
}

public void getValue()


{
System.out.println("Your name: " +name);
System.out.println("Your amount is: "+amount+"\n");
}

public static void main(String args[])


{
BankAcc1 obj1=new BankAcc1();
obj1.setValue("abhijit kumar",7000);

BankAcc1 obj2=new BankAcc1();


obj2.setValue("Soumen Pal",8000.50f);

BankAcc1 obj3=new BankAcc1();

Assignment No. – I Page - 2 Khatibur Rahman, 17/ECE/63, ECE Dept, FIEM


Object Oriented Programming Lab (Java) - OOPL
(EC – 695A)
ECE – 6th Sem. – 3rd Year

obj1.getValue();
obj2.getValue();
obj3.getValue();

obj3.setValue("Animesh Mondal");
obj3.getValue();

obj3.setValue(10000.50f);
obj3.getValue();
}
}

OUTPUT:

E:\JAVA\JAVA_FILES>javac BankAcc1.java

E:\JAVA\JAVA_FILES>java BankAcc1
Your name: abhijit kumar
Your amount is: 7000.0

Your name: Soumen Pal


Your amount is: 8000.5

Your name: null


Your amount is: 0.0

Your name: Animesh Mondal


Your amount is: 0.0

Your name: Animesh Mondal


Your amount is: 10000.5

Assignment No. – I Page - 3 Khatibur Rahman, 17/ECE/63, ECE Dept, FIEM


Object Oriented Programming Lab (Java) - OOPL
(EC – 695A)
ECE – 6th Sem. – 3rd Year

3. Write a Program in Java to show the current amount and the amount withdrawn.

Program:
File Name: BankAcc2.java

public class BankAcc2


{
public void getValue()
String name;
{
float amount;
System.out.println("Your name:"+name);
System.out.println("Your
public void setValue(String account balance is: "+amount+"\n");
nm, float amnt)
{ }
name=nm;
amount=amnt;
} public static void main(String args[])
{
BankAcc2 obj1=new
public void depositAmount(float BankAcc2();
amt)
{ obj1.setValue("Soumen pal",1000.0f);
obj1.getValue(); previous account balance is:" +amount);
System.out.println("Your
System.out.println("Your deposit amount is:"+amt);
obj1.depositAmount(10000.50f);
obj1.withdrawlAmount(2000.50f);
amount=amount+amt;
obj1.depositAmount(1000);
System.out.println("After deposit your account balance is:"+amount);
} obj1.withdrawlAmount(12000);
}
}
public void withdrawlAmount(float amt)
{
System.out.println("Your previous account balance is: "+amount);
System.out.println("Your withdrawl amount is: "+amt);
if(amount<amt)
{
System.out.println("Insufficient balance !!! Withdrawl not possible.");
}
else
{
amount=amount-amt;
System.out.println("After withdrawl your account balance is :" +amount);
}
}

OUTPUT:
Assignment No. – I Page - 4 Khatibur Rahman, 17/ECE/63, ECE Dept, FIEM
Object Oriented Programming Lab (Java) - OOPL
(EC – 695A)
ECE – 6th Sem. – 3rd Year

E:\JAVA\JAVA_FILES>javac BankAcc2.java

E:\JAVA\JAVA_FILES>java BankAcc2
Your name:Soumen pal
Your account balance is: 1000.0

Your previous account balance is:1000.0


Your deposit amount is:10000.5
After deposit your account balance is:11000.5
Your previous account balance is: 11000.5
Your withdrawl amount is: 2000.5
After withdrawl your account balance is :9000.0
Your previous account balance is:9000.0
Your deposit amount is:1000.0
After deposit your account balance is:10000.0
Your previous account balance is: 10000.0
Your withdrawl amount is: 12000.0
Insufficient balance !!! Withdrawl not possible.

Assignment No. – I Page - 5 Khatibur Rahman, 17/ECE/63, ECE Dept, FIEM

You might also like