Answer to Question #193864 in Java | JSP | JSF for Shema Derrick

Question #193864

write a java program that assigns grades


1
Expert's answer
2021-05-15T17:53:55-0400


import java.util.Scanner;


public class Grades {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);


		System.out.print("Enter the nubmer of students in group and press Enter: ");
		int[] scores = new int[scan.nextInt()];
		char[] grades = new char[scores.length];


		System.out.print("Enter " + scores.length + " scores: ");
		for (int i = 0; i < scores.length; i++) {
			scores[i] = scan.nextInt();
		}
		scan.close();


		getGrades(scores, grades);


		for (int i = 0; i < scores.length; i++) {
			System.out.println("Student " + i + " score is " + scores[i] + " and grade is " + grades[i]);
		}
	}


	public static int max(int[] array) {
		int max = array[0];
		for (int i = 1; i < array.length; i++) {
			if (array[i] > max)
				max = array[i];
		}
		return max;
	}


	public static void getGrades(int[] scores, char[] grades) {
		int best = max(scores);
		for (int i = 0; i < scores.length; i++) {
			if (scores[i] >= best - 10)
				grades[i] = 'A';
			else if (scores[i] >= best - 20)
				grades[i] = 'B';
			else if (scores[i] >= best - 30)
				grades[i] = 'C';
			else if (scores[i] >= best - 40)
				grades[i] = 'D';
			else
				grades[i] = 'F';
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS