Homework 7-1 In this assignment you will be writing multiple methods that work with arrays. These methods will perform specific functions and, in most cases, return results. Your class should be named...

1 answer below »
.


Homework 7-1 In this assignment you will be writing multiple methods that work with arrays. These methods will perform specific functions and, in most cases, return results.   Your class should be named Grades. Your program will have the following methods: 1. public static int readGrades() 2. public static int sum(int[] arr) 3. public static int sum(int[] arr, int firstIndex, int lastIndex) 4. public static double average(int[] arr) 5. public static int maxValue(int[] arr) 6. public static int maxValue(int[] arr, int firstIndex, int lastIndex) 7. public static int indexOfFirstMaxValue(int[] arr) 8. public static int minValue(int[] arr) 9. public static int minValue(int[] arr, int firstIndex, int lastIndex) 10. public static int indexOfFirstMinValue(int[] arr) 11. public static int numberOfBelowAverageElements(int[] arr) 12. public static int numberOfAboveAverageElements(int[] arr)  13. public static void rotateElements(int[] arr) 14. public static void rotateElements(int[] arr, int rotationCount) 15. public static void reverseArray(int[] arr) 16. public static void main(String[] args)
Answered Same DayApr 26, 2021

Answer To: Homework 7-1 In this assignment you will be writing multiple methods that work with arrays. These...

Aditya answered on Apr 26 2021
124 Votes
import java.util.Scanner;
public class Grades {
public static void main(String[] args) {
int [] grades = new int[20];
int numberOfGrade = read
Grades(grades);
}
public static int readGrades(int[] grades)
{
Scanner scanner = new Scanner(System.in);
int count = 0;
int number;
while(true)
{
System.out.print("Enter a grade: ");
number = scanner.nextInt();
if (number >= 0)
{
grades[count] = number;
count++;
}
else
{
break;
}
}
scanner.close();
return count;
}
public static int sum(int[] arr)
{
int total =0;
for(int i =0;i {
total = total + arr[i];
}
return total;
}
public static int sum(int [] arr, int firstIndex, int lastIndex)
{
if(firstIndex < lastIndex)
{
int total =0;
for(int i =firstIndex;i<= lastIndex;i++)
{
total = total + arr[i];
}
return total;
}
else
{
return -666;
}
}
public static double average(int arr[])
{
double total =0;
for(int i =0;i {
total = total + arr[i];
}
return total/arr.length;
}
public static int maxValue(int [] arr)
{
int maxValue =arr[0];
for(int i =1;i {
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here