Created
November 30, 2017 17:24
-
-
Save toriannnn/a0f92bc8b9047b4de5ce54efe3cd2c0b to your computer and use it in GitHub Desktop.
Write a program that uses the main to read student scores from the keyboard, gets the best score using a method call to (Best), and then assigns/prints grades in another method call to (Assign)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//******************************************************************* | |
//Assignment: AssignGrades | |
//Account: TAM154 | |
// | |
//Author: Tori Murray | |
// | |
//Completion Time: 1 hour and 15 minutes | |
// | |
//Honor Code: I pledge that this program represents my own program code. | |
// | |
//******************************************************************* | |
package assigngrades; | |
import java.util.Scanner; | |
/** | |
* | |
* @author a_nog | |
*/ | |
public class AssignGrades { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
//Add a scanner | |
Scanner in = new Scanner(System.in); | |
//Ask for number of students | |
System.out.print("Enter the number of students: "); | |
int Students = in.nextInt(); | |
int[] scores = new int[Students]; | |
//Ask for the students scores | |
System.out.print("Enter " + Students + " scores: "); | |
scores[0] = in.nextInt(); | |
scores[1] = in.nextInt(); | |
scores[2] = in.nextInt(); | |
scores[3] = in.nextInt(); | |
//Go to the grades method | |
grades(scores); | |
} | |
//Method to show what the grades are | |
public static void grades(int[] grades) { | |
int highest = best(grades); | |
for (int i = 0; i < grades.length; i++) { | |
System.out.printf("Student %d score is %d and grade is %s%n", | |
i, grades[i], assign(grades[i], highest)); | |
} | |
} | |
//Assign method assigns/displays the grades | |
public static char assign(int grade, int highest) { | |
if (highest - grade <= 10) | |
return 'A'; | |
else if (highest - grade > 10 && highest - grade <= 20) | |
return 'B'; | |
else if (highest - grade > 20 && highest - grade <= 30) | |
return 'C'; | |
else if (highest - grade > 30 && highest - grade <= 20) | |
return 'D'; | |
else | |
return 'F'; | |
} | |
//Best method determines the best score | |
public static int best(int[] grades) { | |
int highest = grades[0]; | |
for (int grade : grades) { | |
if (grade > highest) | |
highest = grade; | |
} | |
return highest; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment