In C#, complete each individual exercise separately: 1.)A method IncreaseSalary
ID: 3670097 • Letter: I
Question
In C#, complete each individual exercise separately:
1.)A method IncreaseSalary has been defined. It accepts a single parameter of type int. Assume that a variable Salary of type int has been declared and initialized. Invoke the method IncreaseSalary and pass it the variable Salary by reference.
2.)Write the definition of a public method printGrade, which has a char parameter and returns nothing. The method prints on a line by itself the message string Grade: followed by the char parameter (printed as a character) to standard output. Don't forget to put a new line character at the end of your line.
3.)Given the integer variables x and y, write a fragment of code that assigns the larger of x and y to another integer variable max.
4.)Write the definition of a method min that has two int parameters and returns the smaller.
5.)Write the definition of a public method printLarger, which has two int parameters and returns nothing. The method prints the larger value of the two parameters to standard output on a single line by itself.
Explanation / Answer
4)
public int min (int x,int y)
{
return Math.min(x,y);
}
5)
private void printLarger(int val1, int val2)
{
if(val1 > val2)
{
Console.WriteLine("The largest value is: " + val1.ToString());
}
else
{
Console.WriteLine("The largest value is: " + val2.ToString());
}
}
2)
Public void printGrade(char character)
{
System.out.print("Grade: ");
System.out.println(character);
}