Hi,
I'm fairly new to java, this code is for an assignment in an intro to CompSci class. I've had help (as can be seen in some comments) for some of this code but I'm having trouble with the last bit. The last of the assignment spec's are here
Print the results in exactly the following format:
3.[Last Name], [First Name]
Student ID: [Student ID]
Homework: [Homework Score]
Quizzes: [Quizzes Score]
Midterm: [Midterm Score]
Final: [Final Score] AND, on another line, Grade: [Final Grade]
4.Prompt the user to either enter another student or to quit. Continue the process until the user chooses to quit.
the code so far is here
import java.util.*; public class GradeCount{ public static void main(String[] args) { boolean quit = false; /** * Initialize student data variables */ int studentId; String firstName; String lastName; double assignments, quizzes, midterm, finalExam; int totalScore; String letterGrade; Scanner keyboard = new Scanner(System.in); /** * Prompt user to enter another student or to quit * continue process until the user chooses to quit */ while(quit == false) { // Get student information studentId = getStudentId(keyboard); firstName = getFirstName(keyboard); lastName = getLastName(keyboard); assignments = getAssignments(keyboard); quizzes = getQuizzes(keyboard); midterm = getMidterm(keyboard); finalExam = getFinalExam(keyboard); // Calculate student grade totalScore = getTotalScore(assignments, quizzes, midterm, finalExam); letterGrade = getLetterGrade(totalScore); // Display results to the user displayresults(studentId, firstName, lastName, assignments, quizzes, midterm, finalExam, totalScore, letterGrade); quit = promptContinue(); } } public static int getStudentId(Scanner keyboard) { System.out.println("Please enter the student id"); System.out.print("> "); int studentId = keyboard.nextInt(); // Skip the newline keyboard.nextLine(); return studentId; } public static String getFirstName(Scanner keyboard) { System.out.println("Please enter the student first name"); System.out.print("> "); return keyboard.nextLine(); } public static String getLastName(Scanner keyboard) { System.out.println("Please enter the student last name"); System.out.print("> "); return keyboard.nextLine(); } public static int getAssignments(Scanner keyboard) { System.out.println("Please enter the student assignments"); System.out.print("> "); return keyboard.nextInt(); } public static int getQuizzes(Scanner keyboard) { System.out.println("Please enter the student quiz score"); System.out.print("> "); return keyboard.nextInt(); } public static int getMidterm(Scanner keyboard) { System.out.println("Please enter the student midterm score"); System.out.print("> "); return keyboard.nextInt(); } public static int getFinalExam(Scanner keyboard) { System.out.println("Please enter the student final exam score"); System.out.print("> "); return keyboard.nextInt(); } public static int getTotalScore(double assignments, double quizzes, double midterm, double finalExam) { // Use a double to get full accuracy double totalScore = (assignments + quizzes + midterm + finalExam) / 4; // Cast it back to an int which makes more sense with our logic return (int) totalScore; } /** * Calculate a total score for the student & assign a letter grade * 90 - 100 = A * 80 - 89 = B * 70 - 79 = C * 60 - 69 = D * 59 and below = E */ public static String getLetterGrade(int totalScore) { if(totalScore >= 90 && totalScore <= 100) { return "A"; } else if(totalScore >= 80 && totalScore <= 89) { return "B"; } else if(totalScore >= 70 && totalScore <= 79) { return "C"; } else if(totalScore >= 60 && totalScore <= 69) { return "D"; } else if(totalScore <= 59) { return "E"; } // This should never happen return "N/A"; } /** * Print the results in the following format * [Last Name], [First Name] * Student ID: [Student ID] * Homework: [Homework Score] * Quizzes: [Quizzes Score] * Midterm: [Midterm Score] * Final: [Final Score] * Grade: [Final Grade] */ public static void displayResults() { // Use print and / or println to display the final results for the students System.out.print([lastName], [firstName]); System.out.println(studentId); System.out.println(assignments); System.out.println(quizzes); System.out.println(midterm); System.out.println(finalExam); System.out.println(totalScore); System.out.println(letterGrade); } /** * Prompt the user to continue or quit * @return */ public static boolean promptContinue() { // Put an actual method here; do an if-then, check for "Y" or "N", then return appropriate boolean if() return false; } }
I appreciate any help at all,
-thanks much
--- Update ---
I get an error on the first line of the the display results and I tested some code (that I took out) for the boolean portion that hopefully I can get suggestions on. HOpe answers to this thread help other's as well