Assume that all courses are 3-units. Write a program GPA.java that performs the
ID: 3933621 • Letter: A
Question
Assume that all courses are 3-units. Write a program GPA.java that performs the following, • Ask user to input the number of As, Bs, Cs, Ds and Fs a student received so far. Save these in an array. (A : 4.0 Grade points, B: 3.0, C: 2.0, D: 1.0, F: 0.0) • Find the grade that the student got the most of. • Calculate overall GPA by looping through the array • Print out result One sample output is: Enter number of A B C D and F grades for the student: 5 4 3 2 1 The grade that student got the most is: A Student Overall GPA: 2.67 (Hint: GPA calculation: (#As*4.0 + #Bs*3.0 + #Cs*2.0 + #Ds*1.0 + #Fs*0.0)/total #courses For above example (5*4.0+4*3.0+3*2.0+2*1.0+0)/15 = 2.67, you need to use a loop for calculating the GPA) Assume that all courses are 3-units. Write a program GPA.java that performs the following, • Ask user to input the number of As, Bs, Cs, Ds and Fs a student received so far. Save these in an array. (A : 4.0 Grade points, B: 3.0, C: 2.0, D: 1.0, F: 0.0) • Find the grade that the student got the most of. • Calculate overall GPA by looping through the array • Print out result One sample output is: Enter number of A B C D and F grades for the student: 5 4 3 2 1 The grade that student got the most is: A Student Overall GPA: 2.67 (Hint: GPA calculation: (#As*4.0 + #Bs*3.0 + #Cs*2.0 + #Ds*1.0 + #Fs*0.0)/total #courses For above example (5*4.0+4*3.0+3*2.0+2*1.0+0)/15 = 2.67, you need to use a loop for calculating the GPA) Assume that all courses are 3-units. Write a program GPA.java that performs the following, • Ask user to input the number of As, Bs, Cs, Ds and Fs a student received so far. Save these in an array. (A : 4.0 Grade points, B: 3.0, C: 2.0, D: 1.0, F: 0.0) • Find the grade that the student got the most of. • Calculate overall GPA by looping through the array • Print out result One sample output is: Enter number of A B C D and F grades for the student: 5 4 3 2 1 The grade that student got the most is: A Student Overall GPA: 2.67 (Hint: GPA calculation: (#As*4.0 + #Bs*3.0 + #Cs*2.0 + #Ds*1.0 + #Fs*0.0)/total #courses For above example (5*4.0+4*3.0+3*2.0+2*1.0+0)/15 = 2.67, you need to use a loop for calculating the GPA)Explanation / Answer
“import java.util.Scanner;
public class StudentGPA {
public static void main (String args[]){
String grade = "";
double credit1;
double credit2;
double credit3;
double credit4;
double gradeValue=0;
double totPtsClass1=0;
double totPtsClass2=0;
double totPtsClass3=0;
double totPtsClass4=0;
double totPts=0;
double totalCredits= 0;
double gpa;
Scanner console = new Scanner (System.in);
System.out.println("Please enter the number of credits of the class 1 (A number)");
credit1 = console.nextDouble();
System.out.println("Please enter your grades for the class 1(Capital letters such as A,B+, C-)");
grade = console.next();
if (grade.equals ("A"))
gradeValue= 4.00;
else if (grade.equals("A-"))
gradeValue= 3.67;
else if (grade.equals("B+"))
gradeValue = 3.33;
else if (grade.equals("B"))
gradeValue = 3.00;
else if (grade.equals ("B-"))
gradeValue = 2.67;
else if (grade.equals("C+"))
gradeValue = 2.33;
else if (grade.equals("C"))
gradeValue = 2.00;
else if (grade.equals ("D+"))
gradeValue = 1.33;
else if (grade.equals ("D"))
gradeValue = 1.00;
else if (grade.equals ("F"))
gradeValue = 0;
else if (grade.equals ("FX"))
gradeValue = 0;
else
System.out.println ("Invalid Grade");
totPtsClass1 = gradeValue * credit1;
System.out.println("Please enter the number of credits of the class 2 (A number)");
credit2 = console.nextDouble();
System.out.println("Please enter your grades for the class 2 (Capital letters such as A,B+, C-)");
grade = console.next();
if (grade.equals ("A"))
gradeValue= 4.00;
else if (grade.equals("A-"))
gradeValue= 3.67;
else if (grade.equals("B+"))
gradeValue = 3.33;
else if (grade.equals("B"))
gradeValue = 3.00;
else if (grade.equals ("B-"))
gradeValue = 2.67;
else if (grade.equals("C+"))
gradeValue = 2.33;
else if (grade.equals("C"))
gradeValue = 2.00;
else if (grade.equals ("D+"))
gradeValue = 1.33;
else if (grade.equals ("D"))
gradeValue = 1.00;
else if (grade.equals ("F"))
gradeValue = 0;
else if (grade.equals ("FX"))
gradeValue = 0;
else
System.out.println ("Invalid Grade");
totPtsClass2 = gradeValue * credit2;
System.out.println("Please enter the number of credits of the class 3 (A number)");
credit3 = console.nextDouble();
System.out.println("Please enter your grades for the class 3 (Capital letters such as A,B+, C-)");
grade = console.next();
if (grade.equals ("A"))
gradeValue= 4.00;
else if (grade.equals("A-"))
gradeValue= 3.67;
else if (grade.equals("B+"))
gradeValue = 3.33;
else if (grade.equals("B"))
gradeValue = 3.00;
else if (grade.equals ("B-"))
gradeValue = 2.67;
else if (grade.equals("C+"))
gradeValue = 2.33;
else if (grade.equals("C"))
gradeValue = 2.00;
else if (grade.equals ("D+"))
gradeValue = 1.33;
else if (grade.equals ("D"))
gradeValue = 1.00;
else if (grade.equals ("F"))
gradeValue = 0;
else if (grade.equals ("FX"))
gradeValue = 0;
else
System.out.println ("Invalid Grade");
totPtsClass3 = gradeValue * credit3;
System.out.println("Please enter the number of credits of the class 4 (A number)");
credit4 = console.nextDouble();
System.out.println("Please enter your grades for the class 4 (Capital letters such as A,B+, C-)");
grade = console.next();
if (grade.equals ("A"))
gradeValue= 4.00;
else if (grade.equals("A-"))
gradeValue= 3.67;
else if (grade.equals("B+"))
gradeValue = 3.33;
else if (grade.equals("B"))
gradeValue = 3.00;
else if (grade.equals ("B-"))
gradeValue = 2.67;
else if (grade.equals("C+"))
gradeValue = 2.33;
else if (grade.equals("C"))
gradeValue = 2.00;
else if (grade.equals ("D+"))
gradeValue = 1.33;
else if (grade.equals ("D"))
gradeValue = 1.00;
else if (grade.equals ("F"))
gradeValue = 0;
else if (grade.equals ("FX"))
gradeValue = 0;
else
System.out.println ("Invalid Grade");
totPtsClass4 = gradeValue * credit4;
totPts= totPtsClass1+totPtsClass2+totPtsClass3+totPtsClass4;
totalCredits = credit1+credit2+credit3+credit4;
gpa= totPts / totalCredits;
System.out.printf("Your GPA is: %.2.67f ", + gpa);
}
}”
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.