[go: up one dir, main page]

0% found this document useful (0 votes)
51 views8 pages

CP2 Assignment

1) The document describes a program that takes user input for an employee's age, gender, marital status, and prints appropriate messages based on the input. 2) It also includes functions to check the speed of drivers and assign demerit points, and to calculate an employee's salary based on their base salary, hours worked, and other factors. 3) The last section describes a program to take a full name as input and display the initials with the surname, and includes a class to represent points with x and y coordinates.

Uploaded by

Hrishikesh Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views8 pages

CP2 Assignment

1) The document describes a program that takes user input for an employee's age, gender, marital status, and prints appropriate messages based on the input. 2) It also includes functions to check the speed of drivers and assign demerit points, and to calculate an employee's salary based on their base salary, hours worked, and other factors. 3) The last section describes a program to take a full name as input and display the initials with the surname, and includes a class to represent points with x and y coordinates.

Uploaded by

Hrishikesh Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

M.

STi Vyshnav
21STUCHHO1OHI12

CP-2 Assignment Sec-D

HSk uses te enter age, Gen des (M ol) matial Status Cyo
their plate o
and then
uxing
Aing tollowinq u l s print
Seuice in wban
employee is Jemale, then she wilu wok
enly
aLas
male. and is in bebween 20 to40
iemployee a a aqe
then he may wctk in anyusheie betwe en uoto 60
i male and age i in
6tmployec Only
uban auas
will wolk in
then he prird "ERROR"
should prind
And any othes input of age
d)
ProgYam
impovtjava. util Scanner;
class Wok

static
void
main ( Shing[] asgs
public
ScanntiCSystem in);
ntus
Scannes in
=
age");
println ("EnteY
System out d
in.next Int ();
int age
System.out
=

príntln ("En ter


Scx M/F)2
M/F );
(o);
next chasAt
in.
i'nt Sex
=

Ave you
mauied ? V/):
Syskm.Ot printtn
mauied in next().chaiAt(o)
fnt
Sex =='F)

" You will wolk enly


in wban aieas")
stem.Out
Sy println

it (Se M)
it (Cage>-20) 44(age< uo)
cusie eut printnMou may weik anjushere"
else 4 (Cage >=uo) à& (agee6o))
wban aleas .
Systern.eut.println (You will weik enly in

else

Systerm.out println C"ERROR");

Output
Enter age: 50
Enter Sex:M/FF
Are yeu maied?: V/N;N
You wil weik Only in wban aiea

HWtte a tuncion tol checking the Specd of dstvess. This


uncon sheuld have ene pakameter Speed

aISpeed is Less than +0, it Should poînt "OK"


Dtheawise, evey skm above the Speed timit 40, t
dermeit point and print the
should give the drives n e

total nuwbet of dementt points. FoY exarnple, i the


Speed i 8o, it sheuld prínt: "Potnts 2
I the diive gets mele than 12 point, the
tunctin Should pirct" Lfcense Suspended"

Next Page
rogmam
inpelt java. util.
class Speed

public static void main (Sting ags[D

int Speed, point =O


ScanneA in neuw Scannei (Syslem.in);
Speed in- next Int ();
i Speedee 10)
Syskm.out piintln ("oK");
else
point ( Speed- 10)/s,
System- eut println
CPotnt: + point);
if (point > 12)
C"License Suspended");
System.out println

Output-
150
Poinh 6
License Suspendled
Wrtte a prCasam by Cieating an. 'Employee' clats bavíng.

the methods and print the inal Salay.


tolowing houns of
which takes the Salay, nuumber of
1-qetInto) as paiametei
woik peA day o epleyee of the employee
adds$IO te Salay
2-AddS al () which
soo.
ih t fs less -th an to Salay of the t
Addhwetk () which
adds S
3-
hour of woik
pei day
enployee ithe nunmber o
mele than G heurs lext Page
Proqxanm-
import java util. Scanner
class Employee5

Ploat Salay, ho_ofhous


Void qetInfo Ploat no-of-howns, float Sala)

this. Salay e
Salay,
this. no-othous =Ho_of-hoUs;

Votd addSal()

t CSalaaut 2 Soo)

Salay+ lo

Votd addwok )

tt (no-oB_houu>6)

Salay +=S

Void printSalay)

oB the emplDyee=+Salany"
Systen out príntln "Anal Salany

public static void main CSting args )

Scannei SC =
Scannet (Systerm-in);
neuo

SystemOut println("Ente the Salant o Em ploye e ");


Ploat Sal = Se- next Float ();
System-Ot printl ("Ent the no.oh wetking hBuub)
float no-ofhouus SC. nextflbot ()
Empleyee ehp = neuo Ermployee2();
enp getInto (no_of-hout, Sal);
ernp add Sal ();
eup adduwdik()
emp. printSalay ( )

Output-
Entey the Salauy of Ennployec: ho0

Ente he ho.of w01kng heum 4


HI5.OD
Final Salay of the Ermployee
=

nave al nput and


Waite apioqam -that takes yoi Jull
middlis n a m t
he obbrevlationu of the tust and
dieplays is
which displayed as it
except the latt nane

Kogram
public class SaMple

publ'e static void main (Stting algs[ )

Stung name "Masam Svi Nyshnavi


a

("Initials with Suiname ) ;


System.out.println
int lenname,length (),
Mame hame ttim ) ;
Sthina si " n,

for Cint i=O; ic len; i+ +)

cha ch name-chaiAt(i);
HCch1-)
$1 S1+ch;

elue

printtn
System.Out p
system.out (characker. to Uppekdase
chaAA(o).
) =
1 "

Stting sa
fot(int jeD; j< 61. length (): j++)
if Cj--o)
SR= S2 + Chaiact.toUppexCase (S1-chasAt (o)
else
Sa- $2+ ChajactAtolowenCase (s1.chaiAtG);

System.out print Ln ($);

Output:- 1

Initials with SuAnarme: M.S yshnavi


clais Called MyPoint, which modek a 20 point wtth
and y Co-Ovdinats, is x

Contain
desiqned as qiven beloue. I
aTwO tutance vatablw xCint) and y Cind)
b)o"ne-aqument" CengtiuCto that Constucts a point atl
dd Cosltucio that CBnstiuct a
point with the
X Qnd y Co-oldinatts qive
d)A te Stking C) mcthod that ittuuw
o the instance in a
the Aoimat "Cxyp Stinq deiciphi
deiciptin
) AWEthod Caled
A talled distänce
distance Cd
1Sem his point
AStande em (tvd x,k, int
we. y)
u) ahat
-to
ansther
ansther pout thot ebuuns
Aetuns the
(-oidinatis
potutt at the
the Code
the classo given
giwen pyp
hite

M(Called Test MyPoint) te MyPotint


due whtle a t
ned in the cla. teet all the methods
hogiam-

class MyPbintt

int X,
MyPoiut ()

y:D
MyPoint Cint x, fnt )
thi's.X= X
his.y = 4

Void tostung C)
yStem-ouctp r i r t l n ( " + x + " + y + " ) " ) ;

int y1)
distance (int x1,
Void
int xdi X-x1;
-y1;
int ydtb =

"Math.sqat((x-x1)'(x-x1)+(y-v1)
("distance:
Systerm out príntln (4-v1)

ctass Tett MyPoint


votd m a i n (skhing
ags ti)
public Stabc

neuo Myfoirt ();


My Point M
M distance (4, 5)

Output
distance: 8.6023

You might also like