Class 1- Function and Objects.
Topic – Bank Account
public class BankAccount
{
String x;
int y;
double z;
void BankName()
{
[Link]("Bank Name - "+x);
}
void HolderName()
{
[Link]("Bank Holder Name -
"+x);
}
void AccNumber()
{
[Link]("Bank Account Number -
"+y);
}
void Amount()
{
[Link]("Amount in Bank
Account - "+z);
}
void Transferred()
{
[Link]("Amount transferred
from the Bank Account - "+z);
}
Main Code 👇
public class BankAccountMain {
public static void main(String[] args)
{
BankAccount Bank = new BankAccount();
Bank.x = "Bank of Baroda";
[Link]();
BankAccount Holder = new BankAccount();
Holder.x = "Rishul";
[Link]();
if (Holder.x == "Rishul")
{
[Link]("Correct
Username!\n");
}
else
{
[Link]("No such user
found. Please try again");
}
BankAccount Number = new BankAccount();
Number.y = 481037107;
[Link]();
BankAccount Amount = new BankAccount();
Amount.z = 6781.98;
[Link]();
BankAccount GiveorNothing = new
BankAccount();
GiveorNothing.x = "Give";
if(GiveorNothing.x == "Give")
{
BankAccount Transferred = new
BankAccount();
Transferred.z = 100;
[Link]();
if(Transferred.z <= 0)
{
[Link]("Nothing has
been transferred. Contact bank administrator\
n");
}
else
{
double result = Amount.z -
Transferred.z;
[Link]("Total amount
in your account is\n "+result);
}
}
else if (GiveorNothing.x == "Nothing")
{
[Link]("Nothing has been
transferred from your account");
}
}
}
Class 2- Polymorphism and Garbage Collection.
Topic – Bank Account
public class BankAccountClass2
{
String x;
int y;
double z;
void BankName()
{
[Link]("Bank Name - "+x);
}
void HolderName()
{
[Link]("Bank Holder Name -
"+x);
}
void AccNumber()
{
[Link]("Bank Account Number -
"+y);
}
void Amount()
{
[Link]("Initial Amount in
Bank Account - "+z);
}
double Transaction(int x, double
y)//transfer
{
double a = y-x;
//int result = (double)a;
return a;
}
double Transaction( double x, double
y)//withdraw
{
double a = y-x;
//int result = (int)a;
return a;
}
double Transaction(double x, int y)//deposit
{
double a = y+x;
//int result = (int)a;
return a;
}
Main Code 👇
public class BankAccountClass2Main
{
public static void main(String[] args)
{
BankAccountClass2 Bank_Name = new
BankAccountClass2();
Bank_Name.x = "Bank of Baroda";
Bank_Name.BankName();
/***********************************************
*************/
BankAccountClass2 Account_Holder = new
BankAccountClass2();
Account_Holder.x = "Rishul";
Account_Holder.HolderName();
if (Account_Holder.[Link]("Rishul"))
{
[Link]("Correct Account
Holder!\n");
}
else
{
[Link]("No such user
found. Please try again");
[Link](0);
}
/***********************************************
*************/
BankAccountClass2 Account_Number = new
BankAccountClass2();
Account_Number.y = 481037107;
Account_Number.AccNumber();
/***********************************************
*************/
BankAccountClass2 Initial_Amount = new
BankAccountClass2();
Initial_Amount.z = 6781.98;
Initial_Amount.Amount();
/***********************************************
*************/
BankAccountClass2 Transaction_Type = new
BankAccountClass2();
Transaction_Type.x = "Transfer";
/***********************************************
*************/
if(Transaction_Type.[Link]("Transfer"))
{
BankAccountClass2 Transferred = new
BankAccountClass2();
Transferred.z = 100;
double result =
[Link](Transferred.z,
Initial_Amount.z);
if(Transferred.z <= 0)
{
[Link]("Nothing has been
transferred. Contact bank administrator\n");
}
else
{
[Link]("Amount
transferred from your account is "+
Transferred.z);
[Link]("Balance in your
account is "+ result);
}
}
/***********************************************
*************/
else
if(Transaction_Type.[Link]("Withdrawl"))
{
BankAccountClass2 Withdrawl = new
BankAccountClass2();
Withdrawl.z = 5000;
double result =
[Link](Withdrawl.z,
Initial_Amount.z);
if(Withdrawl.z <= 0)
{
[Link]("Nothing has been
Withdrawed.\n");
}
else
{
[Link]("Amount withdrawed
from your account is "+ Withdrawl.z);
[Link]("Total amount in
your account after withdrawal is "+result);
}
}
/***********************************************
*************/
else
if(Transaction_Type.[Link]("Deposit"))
{
BankAccountClass2 Deposit = new
BankAccountClass2();
Deposit.z = 100;
double result =
[Link](Initial_Amount.z,
Deposit.z);
if(Deposit.z <= 0)
{
[Link]("Nothing has been
deposited.\n");
}
else
{
[Link]("Amount deposited
in your account is "+ Deposit.z);
[Link]("Total amount in
your account after deposition is "+result);
}
}
/***********************************************
*************/
else if
(Transaction_Type.[Link]("Nothing"))
{
[Link]("Nothing has been
transferred, withdrawed or deposited from your
account");
}
}
}
Class 3- Constructors.
Topic – Bank Account
public class BankAccountClass3
{
String Name;
int Acc_Number;
double Total_Amount;
double Amount_Transacted;
void enterBankName()
{
[Link]("Bank Name: "+Name);
}
void enterUsername()
{
[Link]("Bank Holder Name -
"+Name);
}
void enterPassword()
{
[Link]("Bank Account Password
- "+Name);
}
BankAccountClass3()
{
Acc_Number = 481037107;
}
void displayingAmount()
{
[Link]("Initial Amount in
Bank Account - "+Total_Amount);
}
BankAccountClass3(int Amount_Transferred,
double Total_Amount)//transfer
{
Amount_Transacted = Amount_Transferred;
this.Total_Amount = Total_Amount;
}
BankAccountClass3( double Amount_Withdrawed,
double Total_Amount)//withdraw
{
Amount_Transacted = Amount_Withdrawed;
this.Total_Amount = Total_Amount;
}
BankAccountClass3( double Amount_Deposited,
int Intial_Balance)//deposit
{
Amount_Transacted = Amount_Deposited;
Total_Amount = Intial_Balance;
double doCalculationforTransfer()
{
double a = Total_Amount -
Amount_Transacted;
return a;
}
double doCalculationfor_Deposition()
{
double a = Total_Amount +
Amount_Transacted;
return a;
}
}
Main Code 👇
public class BankAccountClass3Main
{
public static void main(String[] args)
{
{
BankAccountClass3 Bank_Name = new
BankAccountClass3();
Bank_Name.Name = "Bank of Baroda";
Bank_Name.enterBankName();
/***********************************************
*************/
BankAccountClass3 Account_Holder =
new BankAccountClass3();
Account_Holder.Name = "Rishul";
Account_Holder.enterUsername();
/***********************************************
*************/
BankAccountClass3 Account_Password =
new BankAccountClass3();
Account_Password.Name = "helloguys";
Account_Password.enterPassword();
if
(Account_Password.[Link]("helloguys"))
{
[Link]("Correct
Account Password!\n");
}
else
{
[Link]("Incorrect
Password. Please try again");
[Link](0);
}
/***********************************************
*************/
BankAccountClass3 Account_Number =
new BankAccountClass3();
[Link]("Account Number:
"+Account_Number.Acc_Number);
/***********************************************
*************/
BankAccountClass3 Initial_Amount =
new BankAccountClass3();
Initial_Amount.Total_Amount =
6781.98;
Initial_Amount.displayingAmount();
/***********************************************
*************/
BankAccountClass3 Transaction_Type =
new BankAccountClass3();
Transaction_Type.Name = "Withdraw";
/***********************************************
*************/
if(Transaction_Type.[Link]("Transfer"))
{
BankAccountClass3 Transferred =
new BankAccountClass3(0,
Initial_Amount.Total_Amount);
if(Transferred.Amount_Transacted <=
0)
{
double final_amount =
[Link]();
[Link]("Nothing has
been transferred. Contact bank administrator\
n");
[Link]("Balance in
your account is - "+final_amount );
}
else
{
double final_amount =
[Link]();
[Link]("Amount
transferred from your account is - "+
Transferred.Amount_Transacted);
[Link]("Balance in
your account is - "+final_amount );
}
}
/***********************************************
*************/
else
if(Transaction_Type.[Link]("Withdraw"))
{
BankAccountClass3 Transferred =
new BankAccountClass3(100,
Initial_Amount.Total_Amount);
if(Transferred.Amount_Transacted <=
0)
{
double final_amount =
[Link]();
[Link]("Nothing has
been withdrawed.\n");
[Link]("Balance in
your account is - "+final_amount );
}
else
{
double final_amount =
[Link]();
[Link]("Amount
withdrawed from your account is - "+
Transferred.Amount_Transacted);
[Link]("Balance in
your account is - "+final_amount );
}
}
/***********************************************
*************/
else
if(Transaction_Type.[Link]("Deposit"))
{
BankAccountClass3 Transferred =
new BankAccountClass3(200,
Initial_Amount.Total_Amount);
if(Transferred.Amount_Transacted <=
0)
{
double final_amount =
Transferred.doCalculationfor_Deposition();
[Link]("Nothing has
been deposited.\n");
[Link]("Balance in
your account is - "+final_amount );
}
else
{
double final_amount =
Transferred.doCalculationfor_Deposition();
[Link]("Amount
deposited in your account is - "+
Transferred.Amount_Transacted);
[Link]("Balance in
your account is - "+final_amount );
}
}
/***********************************************
*************/
else if
(Transaction_Type.[Link]("Nothing"))
{
[Link]("Nothing has been
transferred, withdrawed or deposited from your
account");
}
}
}
}
Class 4- Used Weapon class as parameter for a
new function in Soldier Class and called
function of weapon class in the new function of
Soldier Class.
Datatype with class as parameter and used it as
function to calculate value of variable.
Topic – Bank Account
[Link]
public class Person
{
String name;
int age;
String resident;
void collectingDetails()
{
[Link]("Mr. "+name+" age "+age+"
resident of "+resident);
}
//Define a overloaded activity function that
accepts a BankAccount type of object as a
//Parameter
void doingActivity(BankAccount x)
{
[Link]();
}
@Override
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
[Link]("Person Object Garbage
Collected");
}
[Link]
public class BankAccount
{
String bank;
int account;
String type;
double initial;
double amount;
BankAccount()
{
}
BankAccount(String bank, int account, String
type, double initial, double amount)
{
[Link] = bank;
[Link] = account;
[Link] = type;
[Link] = initial;
[Link] = amount;
}
void transact()
{
if(amount==0)
{
[Link]("Opened new account with
"+bank+" account number "+account+" account type
"+type+" account balance "+initial+"\n\n");
}
else if (amount > 0)
{
double result = initial+amount;
[Link]("Deposited "+amount+" ,in
account "+account+" ,of bank "+bank+" ,account
type "+type+" ,account balance "+result+"\n\n");
}
else
{
double result = initial+amount;
amount = -amount;
[Link]("Withdrawn
"+amount+" ,from account "+account+" ,of bank
"+bank+" ,account type "+type+" ,account balance
"+result);
}
BankAccount transact2(BankAccount b)
{
BankAccount b1 = new BankAccount();
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
return b1;
}
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
[Link]("Bank Account Object
Garbage Collected");
}
}
[Link]
public class PersonMain
{
public static void main(String[] args)
{
Person p1 = new Person();
[Link] = "Mohan";
[Link] = 30;
[Link] = "Delhi";
[Link]();
BankAccount b1 = new BankAccount("ICICI Bank",
123456789, "Savings", 8000.00, 0);
//call the overloaded activity function.
[Link](b1);
Person p2 = new Person();
[Link] = "Krishan";
[Link] = 45;
[Link] = "Jammu";
[Link]();
BankAccount b2 = new BankAccount("Bank of
Baroda", 00765432, "Current", 15000.00, 875.50);
//call the overloaded activity function.
[Link](b2);
Person p3 = new Person();
[Link] = "Arun";
[Link] = 25;
[Link] = "Gujrat";
[Link]();
BankAccount b3 = new BankAccount("Citibank",
123434534 , "Savings", 20000.00, -1900.50);
//call the overloaded activity function.
//BankAccount b4 = b3.transact2(b3);
// [Link](b4);
BankAccount b4 = b3.transact2(b3);
[Link](b4);
p1=p2;
[Link]();
}
}
Class 5- Static variable and Array
Topic – Bank Account
[Link]
public class Person
{
String name;
int age;
String resident;
static int totalPerson = 0;
Person()
{
Person(String name, String resident, int age)
{
[Link] = name;
[Link] = age;
[Link] = resident;
void printingDetails()
{
[Link]("Mr. "+name+" age "+age+"
resident of "+resident);
totalPerson++;
}
//Define a overloaded activity function that
accepts a BankAccount type of object as a
//Parameter
void personAction(BankAccount x)
{
[Link]();
}
@Override
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
[Link]("Person Object Garbage
Collected");
}
}
[Link]
public class BankAccount
{
String bank;
int account;
String type;
double initial;
double amount;
BankAccount()
{
}
BankAccount(String bank, int account, String
type, double initial, double amount)
{
[Link] = bank;
[Link] = account;
[Link] = type;
[Link] = initial;
[Link] = amount;
}
void transact()
{
if(amount==0)
{
[Link]("Opened new account with
"+bank+" account number "+account+" account type
"+type+" account balance "+initial+"\n\n");
}
else if (amount > 0)
{
double result = initial+amount;
[Link]("Deposited "+amount+" ,in
account "+account+" ,of bank "+bank+" ,account
type "+type+" ,account balance "+result+"\n\n");
}
else
{
double result = initial+amount;
amount = -amount;
[Link]("Withdrawn
"+amount+" ,from account "+account+" ,of bank
"+bank+" ,account type "+type+" ,account balance
"+result);
}
BankAccount transact2(BankAccount x)
{
BankAccount x1 = new BankAccount();
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
return x1;
}
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
[Link]("Bank Account Object
Garbage Collected");
}
}
[Link]
public class PersonMain {
public static void main(String[] args) {
Person details[];//PersonArray
details = new Person[3];
Person person1 = new
Person("Mohan","Delhi",30);
Person person2 = new
Person("Krishan","Jammu",45);
Person person3 = new
Person("Arun","Gujrat",25);
details[0] = person1;
details[1] = person2;
details[2] = person3;
details[0].printingDetails();
BankAccount b1 = new BankAccount("ICICI
Bank", 123456789, "Savings", 8000.00, 0);
details[0].personAction(b1);
details[1].printingDetails();
BankAccount b2 = new BankAccount("Bank of
Baroda", 00765432, "Current", 15000.00, 875.50);
details[1].personAction(b2);
details[2].printingDetails();
BankAccount b3 = new
BankAccount("Citibank", 123434534, "Savings",
20000.00, -1900.50);
BankAccount b4 = b3.transact2(b3);
details[2].personAction(b4);
[Link]("Total persons visited
today: "+[Link]);
b1 = b2;
person1 = person2;
[Link]();
}
}
Class 6- Inheritance
Topic – Box Shipment
[Link]
package box;
public class Box
{
double length,width,height;
Box()
{
length = 10;
width = 10;
height = 10;
}
Box(double length, double width, double
height)
{
[Link] = length;
[Link] = width;
[Link] = height;
}
double calculateVolume()
{
return length*width*height;
}
[Link]
package box;
public class BoxWeight extends Box
{
double weight;
BoxWeight()
{
super();//Super calls the immediate super
class constructor
weight = 10;
}
BoxWeight(double length, double width,
double height, double weight)
{
// [Link] = length;
// [Link] = width;
// [Link] = height;
super(length,width,height);//it calls the
immediate super class constructor
[Link] = weight;
}
}
//Create a class called box shipment which
extends box weight
//Create a class called box main, create a
object of box shipment and call calculate volume
function.
[Link]
package box;
public class BoxShipment extends BoxWeight
{
double price;
BoxShipment()
{
super();//Super calls the immediate super
class constructor
price = 1000;
}
BoxShipment(double length,double
width,double height,double weight,double price)
{
super(length,width,height,weight);
[Link] = price;
}
}
[Link]
package box;
public class BoxMain
{
public static void main(String[] args)
{
BoxShipment s1 = new BoxShipment();
[Link]([Link]());
}
}
Class 6- Inheritance
Topic – Bank Account
[Link]
package BankAccount;
public class BankAccount {
String bank;
int account;
String type;
double initial;
double amount;
BankAccount() {
BankAccount(String bank, int account, String
type, double initial, double amount) {
[Link] = bank;
[Link] = account;
[Link] = type;
[Link] = initial;
[Link] = amount;
}
void transact() {
if (amount == 0) {
[Link]("Opened new account
with " + bank + " account number " + account + "
account type " + type
+ " account balance " +
initial + "\n");
}
else if (amount > 0) {
double result = initial + amount;
[Link]("Deposited " +
amount + " ,in account " + account + " ,of bank
" + bank + " ,account type "
+ type + " ,account balance "
+ result + "\n");
}
else {
double result = initial + amount;
amount = -amount;
[Link]("Withdrawn " +
amount + " ,from account " + account + " ,of
bank " + bank
+ " ,account type " + type +
" ,account balance " + result);
BankAccount transact2(BankAccount x) {
BankAccount x1 = new BankAccount();
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
return x1;
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
[Link]("Bank Account Object
Garbage Collected");
}
}
[Link]
package BankAccount;
public class Person
{
String name;
int age;
String resident;
static int totalPerson = 0;
Person()
{
super();
}
Person( String name, String resident, int age )
{
[Link] = name;
[Link] = age;
[Link] = resident;
}
void printingDetails()
{
[Link]("Mr. "+name+" age "+age+"
resident of "+resident);
totalPerson++;
}
//Define a overloaded activity function that
accepts a BankAccount type of object as a
//Parameter
void personAction(BankAccount x)
{
[Link]();
}
@Override
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
[Link]("Person Object Garbage
Collected");
}
}
[Link]
package BankAccount;
public class Card {
int cardNo;
Card()
{
Card(int cardNo)
{
[Link] = cardNo;
}
}
Card_Type.java
package BankAccount;
public class Card_Type extends Card
{
String type;
Card_Type(int cardNo, String type)
{
super(cardNo);
[Link] = type;
}
void cardDetails()
{
[Link]("Using "+type+" Card
no. "+cardNo);
}
}
[Link]
package BankAccount;
public class PersonMain {
public static void main(String[] args) {
Person details[];//PersonArray
details = new Person[3];
Person person1 = new
Person("Mohan","Delhi",30);
Person person2 = new
Person("Krishan","Jammu",45);
Person person3 = new
Person("Arun","Gujrat",25);
Card_Type c1 = new Card_Type(123456789,
"Credit");
Card_Type c2 = new Card_Type(987654321,
"Debit");
Card_Type c3 = new Card_Type(192837462,
"Loan");
details[0] = person1;
details[1] = person2;
details[2] = person3;
details[0].printingDetails();
BankAccount b1 = new BankAccount("ICICI
Bank", 123456789, "Savings", 8000.00, 0);
details[0].personAction(b1);
[Link]();
[Link]();
details[1].printingDetails();
BankAccount b2 = new BankAccount("Bank of
Baroda", 00765432, "Current", 15000.00, 875.50);
details[1].personAction(b2);
[Link]();
[Link]();
details[2].printingDetails();
BankAccount b3 = new
BankAccount("Citibank", 123434534, "Savings",
20000.00, -1900.50);
BankAccount b4 = b3.transact2(b3);
details[2].personAction(b4);
[Link]();
[Link]();
[Link]("Total persons visited
today: "+[Link]);
b1 = b2;
person1 = person2;
[Link]();
}
}