Adobe Scan 15-Oct-2024
Adobe Scan 15-Oct-2024
class Calculator
result=0;
result = result + a:
result = result
result = result *
result = result / a:
class Number
num = X;
int reverse(int n)
int rev=0,r;
while(n!=0)
=n%10:
rev=rev*10+r;
n=n/10;
return(rev):
void palindrome()
int k=reverse(num);
if(k==num)
System.out.println("Number is palindrome");
else
System.out.println("Number is not palindrome"):
y)
y): in
: : :cOnsTueOr spcciticaions:
:lollowing
String
: : :private s: :Java
to to: to:privateArray Java to lo Stringopr
coTrespondingelements. nd ind tind
lind ofiaccept with usng
display
and and int and the
the a
return the displaylength to class
the return a<|following
numbers and initialize
elements sum wit h
the the the of
b|| e
maximum
as sum to the
inspecitications: number thstring
ofwell ofboth contain sring
sulation both corresponding
as of p s
of the words with
the l0
maximum he arrays
arrays. integers. X.
and corresponding in
eritance the
clements.
of string
the
435
mport java.util.*:
class Array
private int al| = new int |10):
private int b[|| = new int |10}:
public void getlist)
ali<=in.nextlnt):
b[i]=in.nextInt():
int z;
z=(x>y) ?x: y:
return(z):
void display( )
for(int j=0:j<10,j++)
Prog. 5 Vidyapati river bridge has a toll booth. Some cars passing through the
bridge stop to pay a toll of 5and are termed as go0d cars but some run
through and do not pay any toll and are termed as bad cars. Write a class
program with the following specifications:
Class name : Tollbooth
Data Members :private statiC int ncars,amount
void commission)
if( salec=l(XX0)
come5.0/100,0*sale:
it(sale> 000 && sale <= 2000)
com=10.,0/100.0*sale:
if(sale > 2000)
com=15.0/100.0*sale;
void display)
System.out.println("'Sale value"+sale);
System.out.println("Commission to the salesman" +com);
438 | Understanding
Computer Applications with BlueJ-X
illustrate Inheritance
to
proeram
in base
class
WA Writen
Coxdjava.Mil,
impor *.
cassEmployee
Stringname:
thoatbasic:
odgetdata)
new Scanner(System.in):
Scannerin =
Sstem.out.println("Enter Employee's name:"):
name=in.nextLine0:
System.out.println(("Enter Employee's basic salary:"):
basic=in.nextFloat(0:
class
Code written in derived
class Salary extends Employee
double da,hra.pf.groSs,net:
void calculate()
da=50.0/100.0*basic:
hra=15.0/100.0*basic:
pf=8.33/100.0*(basic+da);
gross=basic+da+hra;
net=gross-pf:
void display)
void calculate()
salary1: void display()
Salary
Inspect
Remove
salary1: Salary
int pno;
String name:
int qnty;
Scanner in = new Scanner(System.in):
vOid getdata()
System.out.println("Enter the values"):
pno=in.nextInt():
name=in.next():
qnty=in.nextlnt():
void shovw()
System.ou..println("Product number"+pno):
System.ou-fprintln("Product name"+name):
System.out.println("Quantity"+qnty):
/Code written in derived class
class Sale extends Product
doublc rate:
double amount:
Scanner in=new Seanner(System.in);
void input()
System.out.println("Enter rate of the item purchased");
rate=in.nextDouble();
void calculate()
amount=rate*qnty;
void display()
System.out.println("Amount to be paid" + amount);
Chapter at a Glance!
" Encapsulation is defined as wrapping of data and functions as a single unit.
" Apublic member of aclass can be access globally throughout the program.
" The access of private member is restricted within the class visibility.
Amember method declared private can't be invoked outside the class premises.
" A private method is invoked within a member method in nested form.
" Inheritance is a technique according to which a class acquires some features
from other class.
The class whose properties are inherited by another class is refer to the Base'
class whereas, a class that inherits from a 'Base' class is said to be a 'Derived
class.
" A'Base' class is derived into a sub-class by using he kevword
'extends.
" A class that inherits a base, acts as a base for another
class. is knoWI a
Nested' or 'Multilevel Inheritance.
" A class variable or static data member is
declared within a class but outo
any member method by using a
keyword 'static'.
Alocal variable is declared within a method and its accessibility remains
limited under the method block.
The class variables are declared by using the keyword 'static whereas, the
instance variables are declared without the
static' keyword.