Answer to Question #281523 in Java | JSP | JSF for jhadz

Question #281523

·        Ask the first name, middle initial and last name of the student.

·        Prompt the user to select between old student and new student by pressing either O (old student) or N (new student).

·        If O is pressed, ask the student to enter the following grades per term:

o  Prelim

o  Midterm

o  Prefinals

o  Finals

·        Compute the final grade of the student by using given formula: FG = ((Prelim * 20%) + (Midterm * 20%) + (Prefinals * 20*) + (Finals * 40%)). Display the full name of the student with his/her accumulated grade using the format given.

·        If N is pressed, ask the student to enter his/her average grade then display the full name grade.

·        Grade Format:

o  1.00 = 99 – 100

o  1.25 = 96 – 98

o  1.50 = 93 – 95

o  1.75 = 90 – 92

o  2.00 = 87 – 89

o  2.25 = 84 – 86

o  2.50 = 81 – 83

o  2.75 = 76 – 80

o  3.00 = 75

o  5.00 = Below 75

·        If an invalid letter is pressed, display an error message.


1
Expert's answer
2021-12-20T12:37:37-0500
import java.util.Scanner;

public class Main {

    public static void accumulatedGrade(double grade) {
        if (grade >= 99) {
            System.out.println("1.00");
        } else if (grade >= 96) {
            System.out.println("1.25");
        } else if (grade >= 93) {
            System.out.println("1.50");
        } else if (grade >= 90) {
            System.out.println("1.75");
        } else if (grade >= 87) {
            System.out.println("2.00");
        } else if (grade >= 84) {
            System.out.println("2.25");
        } else if (grade >= 81) {
            System.out.println("2.50");
        } else if (grade >= 76) {
            System.out.println("2.75");
        } else if (grade == 75) {
            System.out.println("3.00");
        } else {
            System.out.println("5.00");
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("First name: ");
        String firstName = in.nextLine();
        System.out.print("Middle initial: ");
        String middleInitial = in.nextLine();
        System.out.print("Last name: ");
        String lastName = in.nextLine();
        System.out.print("O(old student) | N(new student): ");
        String type = in.nextLine();
        if (type.equalsIgnoreCase("O")) {
            System.out.print("Prelim: ");
            double prelim = Double.parseDouble(in.nextLine());
            System.out.print("Midterm: ");
            double midterm = Double.parseDouble(in.nextLine());
            System.out.print("Prefinals: ");
            double prefinals = Double.parseDouble(in.nextLine());
            System.out.print("Finals: ");
            double finals = Double.parseDouble(in.nextLine());
            double finalGrade = prelim * 0.2 + midterm * 0.2 + prefinals * 0.2 + finals * 0.4;
            System.out.print(firstName + " " + middleInitial + " " + lastName + " ");
            accumulatedGrade(finalGrade);
        } else if (type.equalsIgnoreCase("N")) {
            System.out.print("Average grade: ");
            double averageGrade = Double.parseDouble(in.nextLine());
            System.out.println(firstName + " " + middleInitial + " " + lastName + " ");
            accumulatedGrade(averageGrade);
        } else {
            System.out.println("Invalid letter.");
        }
    }
}

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