Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

WRITE IN JAVA Question 1: Write a method to determine the largest number in 7 nu

ID: 3552169 • Letter: W

Question

WRITE IN JAVA

Question 1:

Write a method to determine the largest number in 7 numbers. You can use the following methods. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>

int larger(int a, int b) {

            if (a > b ) {

                        return a;

            }

            return b;          

}

int largestInFive(int a, int b, int c, int d, int e) {

            int temp1 = larger(a, b);

            int temp2 = larger(c, d);

            int temp3 = larger(temp1, temp2);

            return larger(temp3, e);

}

static int largestInSeven(int a, int b, int c, int d, int e, int f, int g) {

            // the implimentation......

}


Question 2:

Write a method to change the temperature from Celsius to Fahrenheit. The signature of the method is given as below.

static double celsiusToFahrenheit(double C) {

            // the formula is F = (9/5)*C+32

}

Question 3:

Write a method to calculate the salary of the employee. If the work hours are less than or equal to 40 hours, the salary = hours * rate. However, if the hours are over 40 hours, the extra hours will be paid by 1.5* rate. The signature of the method is given as below.

static double getSalary(double hours, double rate) {

           

}

Question 4:

Given an int array, write a method to count the number of even numbers in the array.

static int numOfEvenNumber(int[] arr) {

//your implemention

Explanation / Answer

int larger(int a, int b) {

            if (a > b ) {

                        return a;

            }

            return b;          

}

int largestInFive(int a, int b, int c, int d, int e) {

            int temp1 = larger(a, b);

            int temp2 = larger(c, d);

            int temp3 = larger(temp1, temp2);

            return larger(temp3, e);

}

static int largestInSeven(int a, int b, int c, int d, int e, int f, int g) {

int temp1 = largestInFive(a,b,c,d,e);

int temp2 = larger(f,g);

return larger(temp1,temp2);

}

------------------------------------------------------------------------------------------------------------------------

static double celsiusToFahrenheit(double C) {

            // the formula is F = (9/5)*C+32

return (1.8*C + 32);

}

------------------------------------------------------------------------------------------------------------------------


static double getSalary(double hours, double rate) {

if(hours<=40){

return (hours*rate);

}

else{

double salary = 40 * rate + (hours-40)*1.5*rate;

return salary;

}

}


------------------------------------------------------------------------------------------------------------------------

static int numOfEvenNumber(int[] arr) {

int count = 0;

for(int i: arr){

if(i%2==0){

count++;

}

}

return count;

}