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

There are two java questions, thank you very much! R39. NEFA 11:30 Chi Zhan lab0

ID: 3837376 • Letter: T

Question

There are two java questions, thank you very much! R39. NEFA 11:30 Chi Zhan lab01 pdf (M 11 M. H 13 M) nan Question 3 Average of an array We now want to add a new to our computeAverage, has one parameter, an array of type double. It returns a value of type double which is the average of the values contained in the array. From the main of your prog you need to call the method computeAverage and store the returned value in some variable of type double. You then need to print out the result. When I call it with the array valuesArray as parameter, mine prints out the following: The average is 72.14285714285714 11 Modify the program ArrayTool to include the method computeAverage described above. In your main, after calling the method computeAverage, call the method printHigherorLower using the computed average as the "cutOffValue". Question 4 ava Scanner

Explanation / Answer

Q3.

import java.io.*;

public class ArrayTool{
  
public static void main(String []args) throws IOException{
  
double[] valuesArray = new double[10];
double avg;
int i;
InputStreamReader ISR = new InputStreamReader(System.in);
BufferedReader BR = new BufferedReader(ISR);
ArrayTool ob = new ArrayTool();
  
System.out.println("Enter values for double type array:");
for(i = 0; i < 10; i++)
valuesArray[i] = Double.parseDouble(BR.readLine());
  
avg = ob.computeAverage(valuesArray);
ob.printHigherOrLower(valuesArray, avg);
}

double computeAverage(double[] arr){
float avg, sum = 0;
int i;
for(i = 0; i < arr.length; i++)
sum += arr[i];
avg = sum / arr.length;
System.out.println("The average is " + avg);
return avg;
}

void printHigherOrLower(double[] arr, double avg){
int i;
for(i = 0; i < arr.length; i++){
if(arr[i] < avg)
System.out.println("Lower");
else
System.out.println("Higher");
}
}
}

Q4.

import java.util.Scanner;

public class VotingRight{
  
public static void main(String []args){

int age, diff;
Scanner ob = new Scanner(System.in);
  
System.out.print("How old areyou? ");
age = ob.nextInt();
  
if(age < 18){
diff = 18 - age;
System.out.print("You will be allowed to vote in " + diff);
if(diff == 1)
System.out.println(" year.");
else
System.out.println(" years.");
}
else
System.out.println("You have the right to vote!");
}
}