Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help Correct my code: its not Input 2 5 , 7 5 , - 1 5 , 1 0 , 2 0 , 3 0

Help Correct my code: its not
Input
25,75,-1
5,10,20,30,40,50,60,70,80,90,100,-1
19,15,14,33,76,46,88,78,69,79,75,73,72,-1
-1
Your output
Enter a grade: Enter a grade: Enter a grade: Number of Grades =2 Maximum Exam Grade =75
Minimum Exam Grade =25
Enter a grade :
Enter a grade :
Enter a grade :
Number of Grades =2
Maximum Grade =754
Minimum Grade =25
4
Enter a grade : 4
Enter a grade :
Enter a grade :
Enter a grade: 4
Enter a grade : d
Enter a grade :
Enter a grade :
Enter a grade : 4
Enter a grade : 4
Enter a grade :
Enter a grade :
Enter a grade : 4
Number of Grades =11d
Maximum Grade =100d
Expected output
Minimum Grade =5d//package Grades;
import java.util.Arrays;
import java.util.Scanner;
public class Grades {
// Studying values from the consumer
public static int[] readGrades(){
Scanner read = new Scanner(System.in);
System.out.print("Input the number of grades: ");
int length = read.nextInt();
int[] grades = new int[length];
for (int i =0; i length; i++){
System.out.print("Input "+(i +1)+"th grade: ");
int grade = read.nextInt();
grades[i]= grade;
}
read.close();
return grades;
}
// Calculating the sum of grades in the array
public static int sum(int[] arr){
int sum =0;
for (int i =0; i arr.length; i++){
sum = sum + arr[i];
}
return sum;
}
// Calculating the sum of grades at the first and last index
public static int sum(int[] arr, int firstIndex, int lastIndex){
return arr[firstIndex]+ arr[lastIndex];
}
// Calculating the average of grades in the array
public static double average(int[] arr){
int sum =0;
for (int i =0; i arr.length; i++){
sum = sum + arr[i];
}
return (double) sum / arr.length;
}
// Finding the maximum grade in the array of grades
public static int maxValue(int[] arr){
int max = arr[0];
for (int i =1; i arr.length; i++){
if (max arr[i]){
max = arr[i];
}
}
return max;
}
// Finding the minimum grade in the array of grades
public static int minValue(int[] arr){
int min = arr[0];
for (int i =1; i arr.length; i++){
if (min > arr[i]){
min = arr[i];
}
}
return min;
}
// Main approach
public static void main(String[] args){
int[] arr;
arr = readGrades();
System.out.println("Sum: "+ sum(arr));
System.out.println("Sum of the first index and last index values: "+ sum(arr,0, arr.length -1));
System.out.println("Average of grades: "+ average(arr));
System.out.println("Maximum Grade: "+ maxValue(arr));
System.out.println("Minimum Grade: "+ minValue(arr));
}
}
------
For example, if the input is:
2575-1
5,10,20,30,40,58,60,70,80,90,100,-1
19,15,14,33,76,46,88,78,69,79,75,73,72,-1
-1
The output will be:
Enter a grade:
Enter a grade:
Enter a grade:
Number of Grades =2
Maximum Exam Grade =75
Minimum Exam Grade =25
Enter a grade:
Enter a grade :
Enter a grade:
Enter a grade:
Enter a grade :
Enter a grade:
Enter a grade:
Enter a grade :
Enter a grade:
Enter a grade:
Enter a grade:
Enter a grade :
Number of Grades =11
Maximum Exam Grade =100
Minimum Exam Grade =5
Enter a grade:
Enter a grade:
Enter a grade :
Enter a grade :
Enter a grade:
Enter a grade:
Enter a grade:
Enter a grade:
Enter a grade:
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade :
Enter a grade:
Number of Grades =13
Maximum Exam Grade =88
Minimum Exam Grade =14
Enter a grade:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

At what level(s) was this OD intervention scoped?

Answered: 1 week ago