0% found this document useful (0 votes)
55 views

Programming With JAVA

1) The document contains code for a Java program that calculates electricity charges based on total units consumed. It defines an Elect class with fields for total units and name. 2) The compute() method calculates the charge based on slab rates for different unit ranges and applies a 15% discount if charge exceeds Rs. 2500. 3) The main() method gets user input for name and units, creates an Elect object and calls compute() to display the charge.

Uploaded by

Toukit Hossain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Programming With JAVA

1) The document contains code for a Java program that calculates electricity charges based on total units consumed. It defines an Elect class with fields for total units and name. 2) The compute() method calculates the charge based on slab rates for different unit ranges and applies a 15% discount if charge exceeds Rs. 2500. 3) The main() method gets user input for name and units, creates an Elect object and calls compute() to display the charge.

Uploaded by

Toukit Hossain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

OF ENGINEERTNG

DUMKAL TNSTJTUTE
&
TECHMoLOY

WITH JAVA
PROGRAMING LAB

STREAM- RCA SEM Hth


BCAN-492
PAPER CODE

NAME TOUKIT HOssAIN


Roll NO 331012/901|

PATE OF SuBMISSoN-21/o8/21
Write a program to take two teger vajve and peatoem

adition, Subtraetion, division usng Class and objeet.

Solution
Class Commpu

int a
imt b
void add ()

imt S-atb;
(Adhdion of To Nmba is
System 0ut.poitrtlbn
)
void Svb ())

R int d=atb
System.ovt. pirtbr Substraetion s: 4

Void mu ()

int m= afb
System.ovt.paintln ("Multiplication
is : "+m).
void dv ()

intf-0/bh
Syslem .ovt. prtnlln ("Division is : "4{);

Public clss ass 1

puble Statie vwd main (ting L]orgs) J


Compu C= New Compu (;
c.0-0;
C-b 5;

C.add C);
CSub );
C.mult C
C. div 0,

Output
Java ass 1
D IJa bap
Number t3 5
Addition of Tuo
Substraution is:5
Multiplication is : 50
Division is 2
5 Creafe a class Big nd defime fwo-member tunefion
owill dake tao nt egca duta Hem trom
Ome fumefion
the and by use of anmother mem br funcBi
input
dha esvt.
biggest Ovt of two and dlsplay
Caleulate the

Soution:
ScaIMer ;
mpoat java .unit.

clossblg

it a
intb

nt
big (t2X, y)

by

Vold max ()

if o )

("value of A is bia"
System ovt. printbn
else

System.oul.pint ("volue of B big ),


is

puble clasS ass12


pulie statk void
main (Sthg L]args){
ScamCr Se= new >eanner (System .in);
C'enrvalve fo a");
Syslem out- prhtla
im m= Sce-nertJnt );
Syslem Out. pontl» Cenla valve fab');
mt n= St.nertInt ();

bt b1-new big (n,n);


l.may);

OUtput
JovL OSSI2. Java
D =\Jabap >
D:1 jabep Java as 12
Enter valve for a
5
énler valve for b

yalve ot A is bi
CAn electoieily boatd changes she vale to domertic værs
o discovnage luuge Corsumption of enengy

Solujon-
mpor t java.util.Seamer
ClaSS eleet

int rotal nmts;


Steing mame ;

elet nd x, Aing y)
tofal units =X

masme

vold Compute ()
doble mn chaaif= (00. 00, tharge= 00.

f (tatl umits= 100)


harg.-min
d
thange 4 Gotal units *An )
f (tota vnrs L= z0o)
Charge-mn chage +(10o 40)4 (Hojol_uwits-
50)
f (tobl units>= oo)
Cha ge =mn charg4 (oof, 40H(2005N (fotok, unr's )

it (charge >250, 00)


Chaoge charge4 cha 15;
System.ovt. porinlln (" cherge is: "f Chargc)

publc tlss ass 15

public Stafic void main (tring [I orga)y


Seame Sc= new Seamr Sptem.i
System .out. paintn (zntea Name');
Sting n= Se. nutline ()
System ovt.printb» (Ertr totol. nil
intp Sc.nuxtInt ():
eleet e = n4 elott (Pn);
eL. eompu tei);
D:1jabPjavat ass15. java
D:\Jabap>Java aSS 15
Entr Nane
Jahirvelin

Enter total vnts

250
The charg U:
2/5.0

You might also like