import java.util.Scanner;
/**
* Students in a course take four exams and earn a letter grade (A, A-, B+, B,
* B-, C+, C, C-, D+, D, D-, or F) for each of them. The course grade is
* determined by dropping the lowest grade and averaging the three remaining
* grades. To average grades, first convert them to number grades, using the
* usual scheme A = 4.0, A- = 3.7, B+ = 3.3, . . ., D- = 0.7, F = 0. Then
* compute their average and convert it back to the closest letter grade. For
* example, an average of 3.51 would be an A-.
*
* Your task is to read inputs of
* the form: letterGrade1 letterGrade2 letterGrade3 letterGrade4
* For example, A- B+ C A
*
* For each input line, your output should be letterGrade where the
* letter grade is the grade earned in the course, as just described.
* For example, A
*
* The end of inputs will be indicated by a letterGrade1 field of -.
*
* @author smitra
*
*/
public class grades {
/**
* The program starts executing in the main method. It keeps calling processALine
* method until it returns false.
*
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Please enter four letter grades: ");
double letterGrade1;
double letterGrade2;
double letterGrade3;
double letterGrade4;
letterGrade1 = in.nextDouble();
letterGrade2 = in.nextDouble();
letterGrade3 = in.nextDouble();
letterGrade4 = in.nextDouble();
}
/**
* Processes one line of input.
* @return true if the sentinel (the - character) was not encountered
*/
static boolean processALine(Scanner in)
{ if (letterGrade1 != "-")
return true;
return false; // this line is just a placeholder
}
/**
* Returns the smallest of four numbers.
*
* @param a a number
* @param b a number
* @param c a number
* @param d a number
* @return the smallest of a, b, c, and d
*/
public static double min(double a, double b, double c, double d)
{
// TODO: write code for this method
return 0; // this line is just a placeholder
}
/**
* Converts a number to the nearest letter grade using the
* usual scheme A = 4.0, A- = 3.7, B+ = 3.3, . . ., D- = 0.7, F = 0.
*
* For example, if x is the number grade, then we have:
* 2.5 ² x < 2.85: B-
* 2.85 ² x < 3.15: B
* 3.15 ² x < 3.5: B+
*
* Similarly, for other numbers.
*
* @param x a number between 0 and 4
* @return the nearest letter grade
*/
public static String numberToGrade(double x) {
if (n == "A") return "4.0";
if (n == "A-") return "3.7";
if (n == "B+") return "3.3";
if (n == "B") return "3.1";
if (n == "B-") return "2.8";
if (n == "C+") return "2.4 ";
if (n == "C") return "2.0 ";
if (n == "C-") return "1.7 ";
if (n == "D+") return "1.3 ";
if (n == "D") return "1.0 ";
if (n == "D-") return "0.7";
if (n == "F") return "0.0";
return ""; // this line is just a placeholder
}
/**
* Converts a letter grade to a number using the
* usual scheme A = 4.0, A- = 3.7, B+ = 3.3, . . ., D- = 0.7, F = 0.
*
* @param grade a letter grade (A+, A, A-, . . ., D-, F)
* @return the equivalent number grade
*/
public static double gradeToNumber(String grade)
{
if (n == "A") return "4.0";
return 0; // this line is just a placeholder
}
} // end of class Grades
Can someone help me out. Am i on the right track when it comes to the main method? Also going into the boolean method i'm not sure what i'm asked to do..any help would be appreciated

New Topic/Question
Reply



MultiQuote




|