0% found this document useful (0 votes)
8 views3 pages

My_Handwritten_Questions_To_Practtice_Coding

The document outlines a Java class named 'Examplee' with various methods for different functionalities, including printing personal details, calculating sums of odd and even numbers, and determining salary based on age and experience. It includes methods for returning values such as salary, name, date of birth, and total marks, as well as methods that perform calculations and return boolean results based on conditions. The class is designed to be executed in an anonymous window to analyze the outputs of the methods defined.

Uploaded by

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

My_Handwritten_Questions_To_Practtice_Coding

The document outlines a Java class named 'Examplee' with various methods for different functionalities, including printing personal details, calculating sums of odd and even numbers, and determining salary based on age and experience. It includes methods for returning values such as salary, name, date of birth, and total marks, as well as methods that perform calculations and return boolean results based on conditions. The class is designed to be executed in an anonymous window to analyze the outputs of the methods defined.

Uploaded by

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

Q25:- Create a Class Named Example and create all the below defined methods one by

one in this class and Run them in through


anynomous window and analyze the Output.

public class Examplee { // Public class demo{} inner class

/*(a) Create a method "create" which will print-


Name: 'Rajiv' ;
Age: 34;
City: 'Surat';
and invoke it.*/

public String rating;


public Examplee(){
rating = 'Hot';
}
public void create(){
String name = 'Rajiv';
String city = 'Surat';
Integer age = 34;
System.debug('Name:' +name);
System.debug('Age:'+age);
System.debug('city:'+city);
}

//(b) Create a method "callMe" which will print all the even numbers between 1
to 100.

Public void callMe(){


create();
for (Integer i = 1; i<=100; i++){
Integer rem = Math.mod(i,2);
if (rem == 0)
System.debug(i);
}
create();
}

//(c) Create a method "testMe" which will print sum up all the odd numbers
between 1 to 100.
public void testMe(){
Integer sum = 0;
for (Integer i=1; i<= 100; i++){
Integer rem = Math.mod(i,2);
if (rem == 1){
sum = sum+i;
}
}
System.debug('Sum:' +sum);
Sum = sum+1;
System.debug('Sum:' +sum);

}
//(d) Create a method "calculate" which will take city and place as parameters
and print them.
public void calculate(String city, String place){
System.debug('City:' +city);
System.debug('Place:' +place);
}
//(e) create a method "callMe" with name and dob as parameters and print them.
public void callMe3(String name, Date dob){
System.debug('Name:' +name);
System.debug('Date:' +dob);
}
/* (f) Create a method "invoke" which will take age and exp as input parameters
and calculate salary and bonus
if age is above 40 and exp is above 10
salary is 50k and bonus is 30k
else salary is 30k and bonus is 5k*/

public void invoke(Integer age, Integer exp){


Integer salary, bonus;
if (age >40 && exp>10){
salary = 50000;
bonus = 30000;
}else {
salary = 30000;
bonus = 5000;
}
System.debug('Salary:' +salary);
System.debug('Bonus:' +bonus);
}

/*(g) Create a method "calculate" which has 3 variables as aval,bval,cval.


assign some integer values to these variables
add aval and bval
assign above addition into cval
and finally return the value by calling this function
store that returned value in a variable named "x" in the
anynomus window after calling the method and check a condition-
if x is greater then 30 then print pass
else fail*/

public Integer calculate4( Integer aval, Integer bval){


Integer cval = aval + bval;
return cval;
}

/*Anonymous window calling


Examplee c1 = new Examplee();
Integer x = c1.calculate4(5,10);
System.debug(x);
if (x>30){
System.debug('Pass');
}else{
System.debug('Fail');
}*/

//(h) Create a method "invoke" which returns salary 1000.00 and print this
value.
public Decimal invoke(){
Decimal salary = 1000.00;
return salary;
}

//(i) create a method "show" which will return name and print this value.
public String show(){
String name = 'Shairy';
return name;
}
//(j) cerate a method "invoke1" which will return dob and print this value.
public Date invoke1(){
Date dob = Date.newInstance(1999,10,18);
return dob;
}
// (k) create a method "callMe1" which will return age and print this value.
public Integer callMe1(){
Integer age = 23;
return age;
}

/*(l) create a method "calculate" which will take age and exp as parameters
and calculate salary bonus and return the totalAmount

if exp is above 40 and age is above 30


salary is 50k and bonus 10k
else salary is 30k and bonus is 5k.*/

public Decimal calculate1(Integer age, Integer exp){


Integer salary, bonus;
if (age >30 && exp > 40){
salary = 50000;
bonus = 10000;
}else{
salary = 30000;
bonus = 5000;
}
Decimal totalAmount = salary + bonus;
return totalAmount;
}

//(m) Create a method "calculate" which will take internal marks and external
marks and return total.

public Decimal calculate2(Decimal internal_marks, Decimal external_marks){


Decimal total = internal_marks + external_marks;
return total;
}

/*(n) create a method "calculate" which will take internal marks and external marks
and
return true if total is grater then or equals 40,
false if less then 40.*/

public Boolean calculate3(Decimal internal_marks, Decimal external_marks){


Boolean flag;
Decimal total = internal_marks + external_marks;
if (total>= 40){
flag = True;
}else{
flag = False;
}
return flag;
}
}

You might also like