In Java based programming Eclipse using the Joptionpane method with the data par
ID: 3821796 • Letter: I
Question
In Java based programming Eclipse using the Joptionpane method with the data parased with the if/else/for/switch methods, create the following program:
Make a program that will collect all the information to calculate a student’s semester G.P.A and display the courses, grades received and the G.P.A..
1. Ask the user to enter their name.
2. Ask the user to enter the name of the class, number of credit hours for the class and the letter grade received.
3. You will need to calculate the weighted grade for the course by multiplying the credit hours for the course by the numeric equivalent of the grade.
4. The program will need calculate the total number of credit hours.
5. The program will need to calculate the total of the weighted grades.
6. Write the information entered to a file (results.txt).
7. Repeat this until they have no more classes to enter
8. All data entered must be validated.
9. After all classes are entered the G.P.A should be calculated and written to a file.
10. Validate the number of credit hours entered.
11. Validate the letter grades entered.
The output file classes.txt should look similar to the following (which will be tab a lot to create appropite spacing)
Classes for *studentname*:
Title Credits Grade
Class one 4 A
Class two 3 B
class three 3 C
class four 3 A
GPA: 3.81
Explanation / Answer
The Java Code for the particularly asked question is as below. Please read the working of the code stated below the code finely.
import java.util.Scanner;
public class studGPA {
public static void main (String args[]){
String obt_grade = "";
double obt1;
double obt2;
double obt3;
double obt4;
double grad_val=0;
double total_score1=0;
double total_score2=0;
double total_score3=0;
double total_score4=0;
double total_score=0;
double comp_cred= 0;
double GPA;
Scanner console = new Scanner (System.in);
System.out.println("Enter credit no of Class1 ");
obt1 = console.nextDouble();
System.out.println("Enter the obtained obt_grades of Class1");
obt_grade = console.next();
if (obt_grade.equals ("A"))
grad_val= 4.00;
else if (obt_grade.equals("A-"))
grad_val= 3.67;
else if (obt_grade.equals("B+"))
grad_val = 3.33;
else if (obt_grade.equals("B"))
grad_val = 3.00;
else if (obt_grade.equals ("B-"))
grad_val = 2.67;
else if (obt_grade.equals("C+"))
grad_val = 2.33;
else if (obt_grade.equals("C"))
grad_val = 2.00;
else if (obt_grade.equals ("D+"))
grad_val = 1.33;
else if (obt_grade.equals ("D"))
grad_val = 1.00;
else if (obt_grade.equals ("F"))
grad_val = 0;
else if (obt_grade.equals ("FX"))
grad_val = 0;
else
System.out.println ("Invalid obt_grade");
total_score1 = grad_val * obt1;
System.out.println("Enter credit no for the Class2");
obt2 = console.nextDouble();
System.out.println("Enter the obtained obt_grade of the Class2");
obt_grade = console.next();
if (obt_grade.equals ("A"))
grad_val= 4.00;
else if (obt_grade.equals("A-"))
grad_val= 3.67;
else if (obt_grade.equals("B+"))
grad_val = 3.33;
else if (obt_grade.equals("B"))
grad_val = 3.00;
else if (obt_grade.equals ("B-"))
grad_val = 2.67;
else if (obt_grade.equals("C+"))
grad_val = 2.33;
else if (obt_grade.equals("C"))
grad_val = 2.00;
else if (obt_grade.equals ("D+"))
grad_val = 1.33;
else if (obt_grade.equals ("D"))
grad_val = 1.00;
else if (obt_grade.equals ("F"))
grad_val = 0;
else if (obt_grade.equals ("FX"))
grad_val = 0;
else
System.out.println ("Invalid obt_grade");
total_score2 = grad_val * obt2;
System.out.println("Enter the credit no for the Class3");
obt3 = console.nextDouble();
System.out.println("Enter the obt_grades of Class3");
obt_grade = console.next();
if (obt_grade.equals ("A"))
grad_val= 4.00;
else if (obt_grade.equals("A-"))
grad_val= 3.67;
else if (obt_grade.equals("B+"))
grad_val = 3.33;
else if (obt_grade.equals("B"))
grad_val = 3.00;
else if (obt_grade.equals ("B-"))
grad_val = 2.67;
else if (obt_grade.equals("C+"))
grad_val = 2.33;
else if (obt_grade.equals("C"))
grad_val = 2.00;
else if (obt_grade.equals ("D+"))
grad_val = 1.33;
else if (obt_grade.equals ("D"))
grad_val = 1.00;
else if (obt_grade.equals ("F"))
grad_val = 0;
else if (obt_grade.equals ("FX"))
grad_val = 0;
else
System.out.println ("Invalid obt_grade");
total_score3 = grad_val * obt3;
System.out.println("Enter the no of credits for Class4");
obt4 = console.nextDouble();
System.out.println("Enter the obt_grades for Class4");
obt_grade = console.next();
if (obt_grade.equals ("A"))
grad_val= 4.00;
else if (obt_grade.equals("A-"))
grad_val= 3.67;
else if (obt_grade.equals("B+"))
grad_val = 3.33;
else if (obt_grade.equals("B"))
grad_val = 3.00;
else if (obt_grade.equals ("B-"))
grad_val = 2.67;
else if (obt_grade.equals("C+"))
grad_val = 2.33;
else if (obt_grade.equals("C"))
grad_val = 2.00;
else if (obt_grade.equals ("D+"))
grad_val = 1.33;
else if (obt_grade.equals ("D"))
grad_val = 1.00;
else if (obt_grade.equals ("F"))
grad_val = 0;
else if (obt_grade.equals ("FX"))
grad_val = 0;
else
System.out.println ("Invalid obt_grade");
total_score4 = grad_val * obt4;
total_score= total_score1+total_score2+total_score3+total_score4;
comp_cred = obt1+obt2+obt3+obt4;
GPA= total_score / comp_cred;
System.out.printf("Your GPA is: %.2f ", + GPA);
}
}
Working Of the Code:
1. As given in the above code you'll can see that it is completely user based and all the user given values are calculated in the program. There are a list of attributes for which the working goes on. It is given as follows
The list of the attributes required for this program to run is given as below
String obt_grade = "";
double obt1;
double obt2;
double obt3;
double obt4;
double grad_val=0;
double total_score1=0;
double total_score2=0;
double total_score3=0;
double total_score4=0;
double total_score=0;
double comp_cred= 0;
double GPA;
All are taken as double because the score can be in any form with decimal values or long values so double was the best available datatype for this work and the logic for it is basic and you can understand it properly.
2. Once the values are added the program starts to run with the given logic and it is possible to change the values for different outputs necessary. Once the obtained grades are entered in the program it will checkout for the GPA of the given program and the output will be properly displayed.
Hope this helps...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.