0% found this document useful (0 votes)
72 views3 pages

Gforcetest

Uploaded by

api-693861260
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views3 pages

Gforcetest

Uploaded by

api-693861260
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;

public class GForceTest {

/* =====================================
===== Challenge 5.2 - G-Force Test =====
========================================

We need to figure out how many G's our astronauts can handle and apply a grade
of,
"Excel, Pass, or Fail" depending on what those scores are when we put them in
the
centrifuge. Write a program that asks the user to enter the G's applied when
the
astronaut candidate passes out. The program should display a grade for each
test.
It should then get the average score and display it in G's and give a total
grade.
If somehow, the astronaut makes it past 9.0 G's, the centrifuge should shut
down
automatically as it is dangerous for the astronaut to endure more than 9.0 G's
and
you should output a warning notification so that our staff can correct the
problem.

Use the following methods in the program.


- calcAverage - This method should accept the five scores as arguments and
return
the average of the scores.
- determineGrade - This method should accept a score as an argument and return
a
grade for the score based on the following score:

Score Grade
==================
Over 9.1 Warning
6.1-9.0 Excel
3.1-6.0 Pass
1.0-3.0 Fail

Things you will need to pass the tests:


Input 1 - "Enter the first score: "
Input 2 - "Enter the second score: "
Input 3 - "Enter the third score: "
Input 4 - "Enter the fourth score: "
Input 5 - "Enter the fifth score: "
Output 1 - "Here are the grades and the average:
Score 1: [grade1]
Score 2: [grade2]
Score 3: [grade3]
Score 4: [grade4]
Score 5: [grade5]
Average score: [averageScore]
Average Grade: [averageGrade]

All calculations should round to the second decimal.

*/
public static void main(String[] args) {

// Create a scanner object to read input from the user.


Scanner keyboard = new Scanner(System.in);

// Get the five test scores in order.


System.out.print("Enter the first score: ");
double score1 = keyboard.nextDouble();

System.out.print("Enter the second score: ");


double score2 = keyboard.nextDouble();

System.out.print("Enter the third score: ");


double score3 = keyboard.nextDouble();

System.out.print("Enter the fourth score: ");


double score4 = keyboard.nextDouble();

System.out.print("Enter the fifth score: ");


double score5 = keyboard.nextDouble();

// Calculate the average score.


double averageScore = calcAverage(score1, score2, score3, score4, score5);

// Determine the grade for each score.


String grade1 = determineGrade(score1);
String grade2 = determineGrade(score2);
String grade3 = determineGrade(score3);
String grade4 = determineGrade(score4);
String grade5 = determineGrade(score5);

// Determine the average grade.


String averageGrade = determineGrade(averageScore);

// Display the grades, average score, and average grade.


System.out.print("Here are the grades and the average:\n");
System.out.println("Score 1: " + grade1);
System.out.println("Score 2: " + grade2);
System.out.println("Score 3: " + grade3);
System.out.println("Score 4: " + grade4);
System.out.println("Score 5: " + grade5);
System.out.printf("Average score: %.2f\n",averageScore);
System.out.println("Average Grade: " + averageGrade);
keyboard.close();
}

// Calculate the average of the five scores.


public static double calcAverage(double score1, double score2, double score3,
double score4, double score5) {
return (score1 + score2 + score3 + score4 + score5) / 5;
}

// Determine the grade for a score.


public static String determineGrade(double score) {
if (score > 9.1) {
return "Warning";
} else if (score >= 6.1 && score <= 9.0) {
return "Excel";
} else if (score >= 3.1 && score <= 6.0) {
return "Pass";
} else if (score >= 1.0 && score <= 3.0) {
return "Fail";
} else {
return "Invalid score";

}
}
}

You might also like