167k views
2 votes
This assignment requires you to write a well documented Java program to calculate the total and average of three scores, the letter grade, and output the results. Your program must do the following:

Prompt and read the users first and last name
Prompt and read three integer scores
Calculate the total and average
Determine a letter grade based on the following grading scale - 90-100 A; 80-89.99 B; 70-79.99 C; below 70 F
Use the printf method to output the full name, the three scores, the total, average, and the letter grade, properly formatted and on separate lines.
Within the program include a pledge that this program is solely your work and the IDE used to create/test/execute the program. Please submit the source code/.java file to Blackboard. Attached is a quick reference for the printf method.

User Foxan Ng
by
5.3k points

1 Answer

2 votes

Answer:

The solution is given in the explanation section

Don't forget to add the pledge before submitting it. Also, remember to state the IDE which you are familiar with, I have used the intellij IDEA

Follow through the comments for a detailed explanation of each step

Step-by-step explanation:

/*This is a Java program to calculate the total and average of three scores, the letter grade, and output the results*/

// Importing the Scanner class to receive user input

import java.util.Scanner;

class Main {

public static void main(String[] args) {

//Make an object of the scaner class

Scanner in = new Scanner(System.in);

//Prompt and receive user first and last name;

System.out.println("Please enter your first name");

String First_name = in.next();

System.out.println("Please enter your Last name");

String Last_name = in.next();

//Prompt and receive The three integer scores;

System.out.println("Please enter score for course one");

int courseOneScore = in.nextInt();

System.out.println("Please enter score for course two");

int courseTwoScore = in.nextInt();

System.out.println("Please enter score for course three");

int courseThreeScore = in.nextInt();

//Calculating the total scores and average

int totalScores = courseOneScore+courseTwoScore+courseThreeScore;

double averageScore = totalScores/3;

/*Use if..Else statements to Determine a letter grade based on the following grading scale - 90-100 A; 80-89.99 B; 70-79.99 C; below 70 F */

char letterGrade;

if(averageScore>=90){

letterGrade = 'A';

}

else if(averageScore>=80 && averageScore<=89.99){

letterGrade = 'B';

}

else if(averageScore>=70 && averageScore<=79.99){

letterGrade = 'C';

}

else{

letterGrade ='F';

}

//Printing out the required messages

System.out.printf("Name: %s %s\\", First_name, Last_name);

System.out.printf("scores: %d %d %d: \\", courseOneScore, courseTwoScore, courseThreeScore);

System.out.printf("Total and Average Score is: %d %.2f: \\", totalScores, averageScore);

System.out.printf("Letter Grade: %C: \\", letterGrade);

// System.out.printf("Total: %-10.2f: ", dblTotal);

}

}

User ZZZ
by
6.1k points