0% found this document useful (0 votes)
5 views9 pages

SC 4

Uploaded by

MONICA NAHAK
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)
5 views9 pages

SC 4

Uploaded by

MONICA NAHAK
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/ 9

Dt : 27/7/2023

wap to read employee bSal and calculate totSal?

I/p : bSal,hra,da

calculation : totSal = bSal+((float)(hra/100)*bSal)+((float)(da/100)*bSal);

i
Conditions :

thi
bSal mut be min 12000/-

hra and da must be in b/w 1 to 100

ipa
Program : DemoMethods4.java

import java.util.Scanner;
Ma
class Salary
sh
{
ate

float cal(int bSal,int hra,int da)

{
nk

float tSal = bSal+((float)(hra*bSal)/100)+((float)(da*bSal)/100);

return tSal;
Ve

class DemoMethods4

public static void main(String[] args)


{

Scanner s = new Scanner(System.in);

System.out.println("Enter Employee-bSal:");

int bS = s.nextInt();

if(bS>=12000)

i
{

thi
System.out.println("Enter HRA:(1 to 100)");

int hra = s.nextInt();

ipa
System.out.println("Enter DA:(1 to 100)");

int da = s.nextInt();
Ma
if((hra>=1 && hra<=100) && (da>=1 && da<=100))

{
sh
Salary ob = new Salary();
ate

float totSal = ob.cal(bS,hra,da);

System.out.println("Employee-TotSal="+totSal);
nk

else
Ve

System.out.println("Invalid hra or da...");

else
{

System.out.println("Invalid bSal...");

i
o/p:

thi
Enter Employee-bSal:

18000

ipa
Enter HRA:(1 to 100)

51

Enter DA:(1 to 100)


Ma
93
sh
Employee-TotSal=43920.0
ate

===================================================================
===

Assignment:
nk

wap to read Six sub marks of a Student and calculate "totMarks and Per"
Ve

I/p : 6 Sub marks

Calculation : totMarks and per

Condition:

All SubMarks must be in b/w 0 to 100,then calculate "totMarks" and "per"


SubClass : Percentage

=>float per(totMarks)

MainClass : StuMainClass

=>main()

i
=>read 6 sub marks

thi
=>calculate totMarks

ipa
o/p:

totMarks =

per =
Ma
===================================================================
sh
=========

Ex-program:
ate

wap to read two integer values and display the following based on user choice:

1.GreaterValue
nk

2.SmallerValue
Ve

Program : DemoMethods5.java

import java.util.Scanner;

class GreaterValue

{
int greater(int x,int y)

if(x>y)

return x;

i
}

thi
else

ipa
return y;

}
}
Ma
}
sh
class SmallerValue
ate

int smaller(int x,int y)


nk

if(x<y)
Ve

return x;

else

{
return y;

class DemoMethods5

i
{

thi
public static void main(String[] args)

ipa
Scanner s = new Scanner(System.in);
Ma
System.out.println("Enter int value-1:");

int v1 = s.nextInt();

System.out.println("Enter int value-2:");


sh
int v2 = s.nextInt();
ate

if(v1==v2)

{
nk

System.out.println("The values are equal...");

}
Ve

else

System.out.println("****Choice****");

System.out.println("1.GreaterValue\n2.SmallerValue");

System.out.println("Enter the Choice:");


int choice = s.nextInt();

switch(choice)

case 1:

GreaterValue gv = new GreaterValue();

i
int r1 = gv.greater(v1,v2);

thi
System.out.println("GreaterValue:"+r1);

break;

ipa
case 2:
Ma
SmallerValue sm = new SmallerValue();

int r2 = sm.smaller(v1,v2);

System.out.println("SmallerValue:"+r2);
sh
break;
ate

default:

System.out.println("Invalid Choice....");
nk

}
Ve

o/p:

Enter int value-1:


12

Enter int value-2:

13

****Choice****

1.GreaterValue

i
2.SmallerValue

thi
Enter the Choice:

ipa
GreaterValue:13
Ma
===================================================================
======

faq:
sh
define switch-case statement?

=>switch-case statement is used to select one from multiple available options


ate

or

cases.
nk

syntax:

switch(value)
Ve

case 1 : statements;

break;

case 2 : statements;
break;

...

case n : statements;

break;

default : default_statements;

i
}

thi
Execution behaviour:

ipa
=>The switch-value is compared with available cases and,if match occurs the
Ma
statements are executed and switch-case is stopped using 'break'

=>If the switch-value is not compared with any available cases then 'default' is

executed.
sh
===================================================================
=====
ate
nk
Ve

You might also like