In: Computer Science
Modify the Assignment program from Module 1 to read a user's first and last name read three integer scores, calculate the total and average determine the letter grade based on the following criteria - Average 90-100 grade is A, 80-89.99 grade is B, 70-79.99 grade is C, all others F (use a nested if) Output formatted results consisting of the full name, the three scores, the total, average (to 2 decimal places), and the letter grade go to step 1 if user wants to go through the above 4 steps for another student You are required to use a method for each of the steps 1-4 . This program DOES NOT involve creating a class as covered in chapter 3.
Hint: you are required to use a while loop and a nested if in this program in addition to working with methods. Method main will mainly have declarations and calls to these methods. You may call a method multiple times Include a pledge that the programs were entirely your work and specify the IDE used to write these programs
write a headerMethod to output the descriptive header
Write one nameMethod and call it twice (value returning)
write one scoresMethod and call it three times
a value returning method to retun the total
a value returning method to return the average
a value returning method to return the letterGrade
an outputMethod to output formatted results (first and last name,
the 3 scores,
total average, and letter grade
Code
import java.util.Scanner;
public class Student {
static Scanner scnr=new Scanner(System.in);
public static void main(String[] args) {
String first_name,last_name;
int score1,score2,score3,total;
double avg;
char again='y',letterGrade;
while(again=='y')
{
first_name=nameMethod ("Enter first name: ");
last_name=nameMethod ("Enter last name: ");
score1=scoresMethod(1);
score2=scoresMethod(2);
score3=scoresMethod(3);
total=getTotal(score1,score2,score3);
avg=getAverage(total);
letterGrade=getLatterGrade(avg);
outputMethod(first_name,last_name,score1,score2,score3,avg,letterGrade);
System.out.print("\nDo you want to do for another student? (y/n):
");
again=scnr.next().charAt(0);
System.out.println();
}
}
private static String nameMethod(String msg) {
System.out.print(msg);
return scnr.next();
}
private static int scoresMethod(int i) {
System.out.print("Enter score "+i+": ");
return scnr.nextInt();
}
private static int getTotal(int score1, int score2, int score3)
{
return score1+score2+score3;
}
private static double getAverage(int total) {
return total/3.0;
}
private static char getLatterGrade(double avg) {
if(avg>=90.00)
return 'A';
else if(avg>=80.00)
return 'B';
else if(avg>=70.00)
return 'C';
else if(avg>=60.00)
return 'D';
return 'D';
}
private static void outputMethod(String first_name, String
last_name, int score1, int score2, int score3, double avg, char
letterGrade) {
String fullname=first_name+" "+last_name;
String format =
"%1$-15s%2$-10d%3$-10d%4$-10d%5$-10.2f%6$-10s\n";
String format1 =
"\n%1$-15s%2$-10s%3$-10s%4$-10s%5$-10s%6$-10s\n";
System.out.format(format1,"Name","Score1","Score2","Score3","Average","Letter
Grade");
System.out.format(format,fullname,score1,score2,score3,avg,letterGrade+"");
}
}
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.