Long-Distance Call Cost Calculator
Long-Distance Call Cost Calculator
GITALASSIGNMENT
SRI
HARSHITHADEEPALA
19BCE7406
SLOT-G1+TG1
[Link] i
teapr ogram t hatcomput esthecostofal ong-distancecal l
.Thecostoft hecal li
sdet ermined
accor dingtot hef ollowingr ateschedul e:
[Link] lstartedbet ween8: 00am and6: 00pm, Monday
throughFr i
day ,i
sbi ll
edatar ateof$0. 40permi [Link] lstartingbef or e8:
00am oraf t
er6:00
pm, Mondayt hroughFr i
day ,i
schar gedatar ateof$0. 25permi nut [Link] lstartedonaSat urday
orSundayi schar gedatar ateof$0. 15permi [Link] nputwi llconsi stoft hedayoft heweek, t
he
ti
met hecal lstarted, andthel engthoft hecalli
nmi nut [Link] putwi llbet hecostoft hecall
.The
ti
mei st obei nputi n24-hournot at
ion,sothet i
me1: 30pm i sinputas13: 30Thedayoft heweekwi ll
ber eadasoneoft hef oll
owi ngpairsofchar actervalues,whi char est oredint wov ari
ablesoft ype
char :
MoTuWeThFrSaSuBesur et oall
owt heusert ouseei therupper caseorl ower casel et
tersora
combi nati
onoft het [Link] nuteswi l
lbei nputasav alueoft ypei nt.(Youcanassume
thattheuserr oundst heinputt oawhol enumberofmi nutes.)Yourpr ogram shoul di ncl
udeal oop
thatlet stheuserr epeatthiscal cul
ationunti
l t
heusersay ssheorhei sdone.
[Link] i
teaprogr am thatacceptsay earwri
ttenasafour-
digitAr
abic(or
dinar
y)numeral andout puts
theyearwr i
tteninRomannumer [Link] al
sareVf or5,Xfor10,Lf or50,Cf or
100,Df or500, andM for1,[Link]
hatsomenumber sarefor
medbyusi ngakindofsubt raction
ofoneRoman“ digit
”;f
orexample,IVis4pr oducedasVmi nusI,XLis40,CM i
s900,[Link] ew
sampley ears:MCM i s1900, MCMLi s1950, MCMLXi s1960,MCMXLi s1940,MCMLXXXI Xis1989.
Assumet hey eari [Link] ogr
am shouldincl
udealoopthatletstheuser
repeatthi
scal culati
onuntil
theusersay ssheorheisdone.
[Link]
eris0.
[Link]
teapr ogram t
hatwi l
lreadinthenumberofli
tersofgasoline
consumedbyt heuser’
scarandt henumberofmi lestravel
ledbythecarandwillthenoutputthe
numberofmi l
espergall
ont hecardeliv
[Link] shouldal
lowtheusertorepeatt hi
s
cal
culati
onasoftenastheuserwi [Link]
neaf uncti
on/methodtocomputet henumberofmi les
pergall
[Link]
am shoulduseagl oball
ydefinedconstantfort
henumberofl it
erspergallon.
[Link] i
teapr ogram togauget herateofi nfl
ationforthepasty [Link] asksforthepriceof
anitem (suchasahotdogora1- caratdiamond)bot honey earagoandt [Link]
imatesthe
i
nflati
onr ateast hedi
ff
er enceinpricedividedbyt hey ear-
agopr i
[Link] shoul
dal l
owt he
usertor epeatt hiscal
culationasof t
enast heuserwi [Link]
on/met hodtocomput ethe
rat
eofi [Link]
lat i
onrateshouldbeav al
ueoft ypedoubl egi
vingtherateasaper cent,f
or
exampl e5. 3f or5.3per
cent .
[Link] i
teaprogr am tostoreapolynomialexpressioninanar rayanddi spl
ayi t
.Taket henumberof
ter
msandcoef fi
cient&exponentofeacht er
m( star
tingf r
om highestexponentt olowest )fr
om user.
Storecoeffi
cientandexponentinconsecut i
vel ocati
onsi narray
.[Link] ession5x3-2x2+x-5should
bestoredasi narraywher eval
uesatev enpositions(0,2,4.
..
.)ar
ecoef fi
cientsandv aluesinlocati
ons
tothei
rright(1,3,
.
..)ar
[Link] :Enterthenumberoft er
ms: 3Entercoef fi
cient1:5
Enterexponent1: 3Ent ercoef
fi
cient2: -
2Ent erexponent2: 2Entercoef f
ici
ent3: 5Ent erexponent
3: 0Hencet heExpr essi
onis5x3-2x2+5 (as5x0=5)
[Link]
eapr ogram tocal
culatetheaveragesalar
yf ordi
ff
erentagegroups25- 29,30-34andmor e
thanorequalto35anddi splayit
.Ini
ti
ali
zethearraywithfol
lowingdata,whereindexr eferst
othei
dof
[Link]:Lett
heagegr oupsbe25- 29,30-34and>=35ageSal ary
2515000
3015850
2616750
3517850
3114200
3316150
3517650
3414100
2714500
4517800
Output
: Avgforagegroup(25-29)is:15416.666666667Av gforagegr oup(30-34)is: 15075Avgfor
agegroup(=35)i s:17766.666666667
[Link] i
teaprogr
am t oarrangetheelementsofanar rayi
nsuchawayt hattheevenelement sar
e
placedatevenindexandoddel ementsareplacedatoddi [Link]
lowhappens( i
.[Link]
even/oddelement saremor et
hant heavai
lablerespect
iveindices)
,ignoretheel
ement sanddispl
ay
theupdatedarr
ay .Incontr
ast,i
ftheindi
cesar eempt yt
henst orezerointhoselocat
[Link]
notedthatzer
othi ndexisconsider
edasev en.
[Link]
it
eapr
ogr
am t
odi
spl
ayt
hef
oll
owi
ngpy
rami
dst
ruct
ureusi
ngmet
[Link]
urnar
gument
[Link]
ormul
aforcomput
ingt
henumberofway
sofchoosi
ng‘
r’
dif
fer
entt
hingsf
rom asetof‘
n’
thi
ngsisthedef i
neasC( n,r
)=n!/
(r!*(n–r )
!).Writ
eamet hod,st
ati
cdoublecom(intn,i
ntr)tofi
nd
theval
ueoft heC(n, r
).Thi
smethodfurtheri
nv okesarecursi
vemethod,
stati
cintfac(
intn).Her
e,
methodstatici
ntf ac(
intn)r
ecur
sivel
yfindsfactori
alofanumberpassedasanar gument .Wri
tethe
completeprogram.
[Link]
ndTr
ansposeofanar
rayusi
ngmet
hod.
[Link]
aPr
ogr
am t
oSor
ttheAr
rayi
nanAscendi
ngOr
derandDescendi
ngOr
derusi
ngmet
hod.
[Link]
chi
ngofanel
ementi
nar
rayusi
ngmet
hod.
1.
i
mpor tjav a.
ut i
l.
* ;
publi
ccl assMai n{
publi
cst aticv oidmai n( Stri
ngar gs[]
){
Scannersc=newScanner (Sy
stem. in)
;
System. [Link]("
Ent erthemi nute")
;
i
ntmi n=sc. next Int(
);
System. [Link]("
Ent erthelengthoft hecall
")
;
i
ntlen=sc. next Int()
;
System. [Link]("
Ent ertheDay ");
Stri
ngday =sc. next()
;
doubler ate=0;
i
f(min>=800&&mi n<=1800){
i
f([Link] s("Mn" )|
|day .
equals("Tu")
||
[Link]
s("
We"
)|
|day
.equal
s("
Th"
)|
|day
.equal
s("
Fr"
)){
System. out .
pr i
ntln("Rateis"+len*0.4);
}
}
el
se{
i
f([Link]("
Mn")||
[Link] s(
"Tu")|
|day.
equal
s("
We"
)|
|day
.equal
s("
Th"
)|
|day
.equal
s("
Fr"
)){
System. out.
pri
ntl
n("Rateis"+len*0.25);
}
}
i
f(day=="Sa"||
day=="Su"){
System. out.
pri
ntl
n("Rateis"+len*0.15);
}
}
}
OUTPUT:
2.
i
mpor
tjav
[Link]
il
.Scanner
;
publi
cclassMain
{
publi
cstati
cvoi
dmai
n(St
ri
ng[]ar
gs)
{
Scanneri
n=newScanner
(Syst
em.i
n);
charchoice=' y'
;
whil
e( choice=='y'
)
{
i
ntyr=i [Link]
Int
();
i
ntlen=( i
nt)Math.
log10(yr
)+1;
i
ntyAr r
ay [
]=newi nt[
len]
;
f
or(
inti
=len-
1;i
>=0;
i-
-){y
Arr
ay[
i]=y
r%10;
yr/
=10;
}
i
ntmul t=1000;
Str
ingr es=" ";
for
(inti :yArr
ay)
{
i
f(mul t==1000)f or(i
ntk=0;k<i;k++)res+="M";
el
sei f(mult==100)
{
if
(i ==4)res+=" CD";
elseif(i==9)res+=" CM";
elseif(i<5){for(i
ntk=0; k<i;
k++)res+="C";}
else{r es+="D";for(i
ntk=0;k<i-5;
k++)res+="C";}
}
el
sei f(mult==10)
{
if
(i ==4)res+=" XL";
elseif(i==9)res+=" XC";
elseif(i<5){for(i
ntk=0; k<i;
k++)res+="X";}
else{r es+="L";for(
intk=0;k<i-
5;k++)res+="X";}
}
el
se
{
if
(i ==4)res+=" I
V" ;
elseif(i==9)res+=" IX"
;
elseif(i<5){for(i
ntk=0; k<i;
k++)res+="I"
;}
else{r es+="V";for(i
ntk=0;k<i-5;
k++)res+="I"
;}
}
mul
t/=10;
}
Sy
stem.
out
.pr
int
ln(
res)
;
Syst
[Link]
.pr
int
("Doy
ouwantt
otr
yagai
n?(
y/n):
");
choi
ce=in.
next(
).
char
At(
0);
}
}
}
OUTPUT:
3.
i
mpor
tjav
[Link]
il
.Scanner
;
publi
cclassMai n
{
publi
cst at
icv oidmai n(Str
ing[]args)
{doubl ebal ance=0;
doublemont hlypayasinter
est=0;
Scannerob=newScanner ([Link])
;
i
ntpr i
ncipal ,i
ntrat,hmuwi ll
pay permonth,
noof
ye;
//t
aki
ngi
nputofpr
inci
pal
amountofl
oan,
i
nterestrate&numberofy ears
pri
ncipal=ob. next I
nt()
;
i
ntrat=ob. nextInt()
;
hmuwi ll
pay permont h=ob. nextInt(
);
noofye=ob. nextInt
();
f
or(i
nti=1; i
<=( noofye*12);
i++)
{
monthl
ypayasinter
est=(principal*(intr
at/100)
)/12;
doubl
emont hl
ypay=hmuwi l
lpayper month-mont hl
ypayasi
nterest;
bal
ance=pr i
ncipal-monthlypay ;
monthl
ypayasi
nterest=monthlypay asi
nterest+monthly
pay asi
nt er
est
;
}
Syst
[Link].
pri
ntln(
"BALANCEI S:"+balance);
Syst
[Link].
pri
ntln(
"MONTHLYPAYMENTASI NTEREST:"+mont hly
payasi
nter
est
);
}
}
OUTPUT:
4.
i
mpor [Link]
.Scanner;
cl
assMai n{
staticdoubl eCal culat
ion(
){
Scanneroc=newScanner (
Sy st
[Link])
;
Sy stem. [Link]
ntl
n("Ent
[Link]
tr
esofGasoli
neconsumed:
")
;
intL=oc. next I
nt()
;
Sy stem. [Link]
ntl
n("Ent
[Link]
rav
ell
ed:"
);
intM=oc. next I
nt(
);
doubl eg=0. 264179;
doubl eMPG=M/ (
L*g);
returnMPG;
}
publ i
cst aticvoidmai n(St
ri
ng[]
args){
Scanneroc=newScanner (Sy
[Link])
;
doubleans=Cal culati
on();
[Link].
pri
nt l
n( "
[Link]
onis"
+ans);
[Link].
pri
nt l
n( "
Doy ouwantt ocont
inue?
" )
;
charch=[Link]().
char At(
0);
do{
doublet=Calculation()
;
[Link].
pr i
ntln("
[Link]
onis"+t
);
}
whil
e(ch=='y'
&&ch==' Y');
}
}
OUTPUT:
5.
i
mpor tjav [Link]
.Scanner ;
publi
ccl assMai n{
publicst aticdoubl ei nfl
ationRat e(doublepr eyrcost,
doublecurcost)
{
return((curcost -prey r
cost )
/ curcost);
}
publicst aticvoi dmai n(String[ ]
args){
doubl epr ey rcost,curcost;
Scannerscan=newScanner (
Sy st
em. i
n);
Sy stem. [Link] i
ntln("Thepr ev i
ousy earcostofpr oductis:
")
;
preyrcost =scan. next Doubl e();
System. [Link]
n( "
Thecur rectcostofpr oductis:
")
;
curcost =scan. next Doubl e();
System. [Link]
n( i
nfl
at i
onRat e(preyrcost,curcost
)*100+"per
cent
");
}
}
OUTPUT:
6.
i
mpor tjav a.
io.* ;
i
mpor tjav a.
ut il
.*;
publ
iccl assMai n{
publicst aticv oi
dmai n(Str
ingargs[]
){
Scannerob=newScanner (
[Link])
;
System. out .
print
("Enterthenumberoft erms:
");
i
ntn=ob. next Int(
);
i
nta[ ]=newi nt[n]
;
i
ntb[ ]
=newi nt[n]
;
for(i
nti =0;i<n;i
++) {
Sy stem. out.
print(
"Entercoeffi
ci
ent1:");
a[i]=[Link] Int
();
Sy stem. out.
print(
"Enterexponent1: "
);
b[i]=ob. nextInt
();
}
for(i
nti =0;i<n;i
++) {
Sy stem. out.
print(
a[i]
+"");
Sy stem. out.
print(
b[i]
+"");
}
}
}
OUTPUT:
7.
i
mportj
[Link]
il
.*
;
publ
i
cclassMain
{
publ
icstaticv oidmai n(Stri
ng[
]args)
{
Scannerin=newScanner (Syst
[Link])
;
i
ntsal;
doubleavg;
i
ntx=0,y=0,z=0, p=0,q=0,r
=0;
Syst
em. [Link](
"enterthenumberofper
son"
);
i
ntn=[Link]();
i
nt[]
[]a=newi nt[n][
2];
for(
inti =0;i<n;i
++)
{
Sy stem. out .
print
ln(
"ent
ertheageofperson"+i+1);
a[i][
0]=[Link] I
nt(
);
}
for(inti=0; i
<n;i++)
{
Sy stem. out .
print
ln(
"ent
erthesal
aryofperson"+i+1);
a[i][
1]=[Link] I
nt(
);
}
for(inti=0; i
<n;i++)
{
if
(a[ i
][0]<=29)
{
x=x+a[ i
][
1];
p=p+1;
}
elsei f(a[i]
[0]
<=34)
{
y=y +a[i]
[1]
;
q=q+1;
}
else
{
z=z+a[ i]
[1];
r=r+1;
}
}
avg=x/ p;
System. out .
pri
ntln(
"Avgforagegroup(25-29)i
s:"
+avg);
avg=0;
avg=y /q;
System. out .
pri
ntln(
"Avgforagegroup(30-34)i
s:"+avg)
;
avg=0;
avg=z/ r;
System. out .
pri
ntln(
"Avgforagegroup(=35)is:"
+avg);
}
}
OUTPUT:
8.
i
mpor tjav a.i
o.*;
i
mpor tjav [Link]
l.
*;
publ
iccl assMai n{
publicst aticvoidmai n(Str
ingargs[]
){
Scannerob=newScanner (
[Link])
;
System. [Link]
int
("Enterthestart
ingpoint:
");
i
nts=ob. nextI
nt(
);
System. [Link]
int
("Entertheendingpoint:"
);
i
nte=ob. nextI
nt(
);
whi l
e( e>s){
intt emp=1, sum1=0, cou=1,
sum=0;
whi le(s>cou){
if(s%cou==0) {
sum=sum+cou;
}
cou++;
}
whi le(sum>t emp) {
if(sum%t emp==0) {
sum1=sum1+t emp;
}
temp++;
}
if(s==sum1) {
if(sum<=e&&sum>=s) {
[Link]
intl
n(s+"&"+sum+"arefull
pai
r.
")
;
}
else{
System.
out
.pr
int
ln(
s+"i
shal
fpai
r.
")
;
}
}
s++;
}
}
}
OUTPUT:
9.
i
mpor
tjav
[Link]
il
.*
;
cl
assTest{
publ
i
cst
aticvoidmai n(Stri
ng[]args){
Scannersc=newScanner (Syst
em.
in);
[Link] .pri
nt("Ent
ernumberofel ementi
nar
ray:
");
i
ntn=sc. nextI
nt();
i
ntar r
[]=newi nt[n];
i
ntodd[ ]=newi nt[n];
i
ntev en[]=newi nt[n]
;
i
nti =0, j=0,k=0;
for(i=0; i <n;i
++){
i
ntnum =sc. nextInt(
);
i
f( num%2==1){
odd[j
++]=num;
}else{
even[k++]=num;
}
}
k=0;
j=0;
f
or(i
=1;i
<=n;
i++){
i
f(i
%2==1){
ar
r[
i-
1]=odd[k++]
;
}el
se{
ar
r[
i-
1]=even[j
++]
;
}
}
Sy
stem.
out
.pr
int
ln(
"Out
put
")
;
f
or(
i=0;
i<n;
i++)Sy
stem.
out
.pr
int
ln(
arr
[i
])
;
}
}
OUTPUT:
10.
i
mpor tjav [Link].
Scanner ;
publi
ccl assMai n{
publi
cst aticv oidpat tern(){
Scannerscan=newScanner (
Syst
em.i
n);
System. out .
pr i
nt l
n("Enterthenumberofrows")
;
i
ntr ows=scan. nextInt()
;
System. out .
pr i
nt l
n("**Pri
ntingthepat
ter
n**
");
for
(inti =1; i
<=r ows;i++) {
for(intj =1;j<=i;
j++) {
i
f(j%2==0) {
Sy stem. [Link]
nt("1"
);
}
else{
Sy stem. [Link]
nt("0"
);
}
}
for(intj =i
* 2;j
<r ows* 2;
j++){
Sy stem. out .
print("");
}
for(intm=1; m<=i ;
m++) {
i
f(m%i ==0) {
Sy stem. [Link]
nt("1"
);
}
el
se{
Sy
stem.
out
.pr
int
("
0")
;
}
}
Syst
em.
out
.pr
int
ln(
);
}
publ
i
cst
ati
cvoi
dmai
n(St
ri
ng[
]ar
gs)
{
pat
ter
n()
;
}
}
OUTPUT:
11.
i
mpor tj av [Link].
Scanner;
publi
ccl assMai n
{
publicst aticv oi
dmai n(Stri
ng[
]args)
{
i
ntn, p;
Scannerscan=newScanner (Syst
[Link])
;
Sy stem. out .
pri
ntl
n("Enteranumber ")
;
n=scan. nextInt
();
p=per fect orNot(
n);
i
f(p==n)
Sy stem. out .
pri
ntl
n(n+"isaper f
ectnumber"
);
else
Sy stem. out .
pri
ntl
n(n+"isnotaper f
ectNumber"
);
}
publicst aticintperfectorNot(
intnum)
{
i
ntsum=0;
for(inti =1;i<=num/ 2;
i++)
{
if(num%i ==0)
{
sum+=i ;
}
}
retur nsum;
}
}
OUTPUT:
12.
i
mpor tj
[Link]
il
.Scanner
;
publ
icclassMai n{
st
ati
cdoublecom(i
ntn,intr
)
{
r
etur
nfact(
n)/(
fact
(r)*
fact(
n-r
));
}
st
ati
cintfact
(i
ntn)
{
i
ntm =1;
f
or(inti
=2; i
<=n;i
++)
m =m *i
;
r
eturnm;
}
publicstati
cvoidmain(Str
ing[
]args){
i
ntn, r;
Scannerscan=newScanner (System.
in)
;
n=[Link]
nt(
);
r=[Link]
Int
();
Sy st
em. out
.pri
ntl
n(com(n,r
));
}
}
OUTPUT:
13.
i
mpor [Link]
l.
Scanner;
publi
ccl assMai n{
publi
cst ati
cv oi
dmai n(
Str
ing[
]ar
gs)
{
Scanneri n=newScanner(Sy
stem.
in)
;
i
ntm=i n.
nextInt
();
i
ntn=[Link]
nt()
;
i
nta[][
]=newi nt
[m][
n];
i
ntb[][
]=newi nt
[m][
n];
f
or(i
nti=0;i
<m; i
++){
f
or(i
ntj=0;j
<n;j
++)
{
a[
i][
j]
=in.
nextI
nt()
;
}
}
t
ranspose(a,b);
}
publ
icst aticv oidtr
anspose(intc[
][
],
i
ntd[
][
])
{
f
or(inti=0; i
<c.l
ength;i
++){
for(
intj =0;j
<d.l
ength;j
++){
d[i][
j]
=c[ j
][
i]
;
Sy stem. out.
pri
ntln(
d[i
][
j]
+"")
;
}
System. out.
pri
ntln(
);
}
}
}
OUTPUT:
14.
i
mpor tjav [Link] i
l.
Scanner ;
publi
ccl assMai n
{
publi
cst aticv oi
dmai n( St
ri
ng[]args){
Scannerscan=newScanner (System.i
n);
i
ntn=scan. nextInt(
);
System. out .
pri
ntln("Ar r
aysize:"
+""+n)
;
i
ntar ray []
=newi nt[ n];
System. out .
pri
ntln("theelement sofarrayar
e")
;
for
(i
nti =0;i<n;i
++) {
ar ray [i
]=[Link] Int()
;
Sy st em. out .
printl
n( arr
ay[
i]+"")
;
}
System. [Link] intln("");
descendi ng( array ,
n);
System. [Link] intln("");
ascending( ar ray ,n);
}
publi
cst aticv oi ddescendi ng(i
ntx[
],
intp){
i ntt ;
f or
(inti=0;i<p; i++) {
f or(
intj=i +1; j<p;j
++){
if
(x[i]
<x[ j]){
t=x[ i]
;
x[i]=x[ j
];
x[j]=t;
}
}
}
Sy stem. out .print l
n("DescendingOrder:
");
f or
(inti=0;i<p; i++) {
Sy stem. out .pr i
ntl
n(x[i
]+"")
;
}
}
publi
cst aticv oi dascendi ng(i
nty[
],
i
ntq) {
i ntm;
f or
(inti=0;i<q; i++) {
f or(
intj=i +1; j<q;j
++){
if
(y [
i]
>y [j]){
m=y [
i];
y [
i]
=y [
j];
y [
j]
=m;
}
}
}
Sy stem. out .print l
n("Ascendingorder:
")
;
f or
(inti=0;i<q; i++) {
Sy stem. out .pr i
ntl
n(y[i
]+""
);
}
}
}
OUTPUT:
15.
i
mpor tjav [Link]
l
.* ;
publ
iccl assMai n{
publicst aticvoi dmai n(Stri
ng[
]args){
Scannerscan=newScanner (
Sy stem.i
n);
Syst em. [Link]("
[Link] sinthearray:")
;
i
ntn=scan. next I
nt()
;
i
nta[ ]
=newi nt[n];
Syst em. [Link]
n("Enteral
ltheel ementinanAr r
ay: "
);
i
ntcount ;
for(inti =0;
i<n;i++)
{
a[i]=scan. nextInt()
;
}
Syst em. [Link]("
Entertheelementt ofi
ndi nanAr r
ay: "
);
i
ntm=scan. nextInt(
);
Syst em. [Link]
n("")
;
i
ntj =0;
for(inti =0;
i<n;i++)
{
if(a[i]
==m) {
j=1;
Sy stem. [Link]
ntl
n("Your
sel ementiffoundinindex: "
+i)
;
}
}
i
f(j!
=1) {
Sy stem. out .
printl
n("Yourselementisnotf ound."
);
}
}
}
OUTPUT: