Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a program that will calculate that will collect all the information to ca

ID: 3818925 • Letter: C

Question

create a program that will calculate 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. You will need to create a flow chart that diagrams your algorithm. make sure it is for beginner.

Write a program that will do the following:

Ask the user to enter their name.

Ask the user to enter the name of the class, number of credit hours for the class and the letter grade received.

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.

The program will need calculate the total number of credit hours.

The program will need to calculate the total of the weighted grades.

Write the information entered to a file.

Repeat this until they have no more classes to enter

All data entered must be validated.

After all classes are entered the G.P.A should be calculated and written to a file.

You should include the following:

Validate the number of credit hours entered.

Validate the letter grades entered.

Use the following chart to determine the numeric equivalent of a letter grade:

Letter
Grade

Grade
Point

A

4

A-

3.7

B+

3.2

B

3

B-

2.7

C+

2.2

C

2

C-

1.7

D+

1.2

D

1

D-

0.7

F

0

You can assume the following:

Use the JOptionPane for the data input and output.

Parse data as necessary

The output file classes.txt should look similar to the following

Classes for Ann Mauss:

Title                   Credits       Grade

CIS 215 Programming I   4             A

RES 104 Research Writing     3             B

PSY 110 Intro to Psych 3             C

WVS 101 World View I    3             A

GPA: 3.31

i need to have those

The classes.txt file

The flow chart of the algorithm.(word file, hand written....it is up too you)

Letter
Grade

Grade
Point

A

4

A-

3.7

B+

3.2

B

3

B-

2.7

C+

2.2

C

2

C-

1.7

D+

1.2

D

1

D-

0.7

F

0

Explanation / Answer

package myProject;
import java.io.*;

import javax.swing.JOptionPane;
//Class definition
public class StudentGPA
{
   //Instance Variables
   String name;
   String className[] = new String [4];
   double creditHours[] = new double[4];
   String grade[] = new String[4];
   double weightedGrade;
   double GPA;
   //Method to accept data
   public void accept()
   {
       //Accept name
       name = JOptionPane.showInputDialog ( "Enter your name" );
       //Accepts 4 class name, credit hours, grade
       for(int x = 0; x < 4; x++)
       {
           className[x] = JOptionPane.showInputDialog ( "Enter your Class Name" );
           //Validates credit hour
           do
           {
               double ch = Double.parseDouble(JOptionPane.showInputDialog ( "Enter Credit Hours" ));
               //valid credit hour if greater than zero
               if(ch > 0)
               {
                   creditHours[x] = ch;
                   //Come out of the do - while loop
                   break;
               }//End of if
               //Otherwise show error message and ask again
               else
                   JOptionPane.showMessageDialog (null, "Invalid Credit Hours. Please reenter." );
           }while(true);
           //Validates grade
           do
           {
               String g = JOptionPane.showInputDialog ( "Enter your Grade" );
               //Checks the given grades
               if(g.equalsIgnoreCase("A") || g.equalsIgnoreCase("A-") || g.equalsIgnoreCase("B+") || g.equalsIgnoreCase("B") || g.equalsIgnoreCase("B-")|| g.equalsIgnoreCase("C+")||g.equalsIgnoreCase("C")||g.equalsIgnoreCase("C-")||g.equalsIgnoreCase("D+")||g.equalsIgnoreCase("D")||g.equalsIgnoreCase("D-")||g.equalsIgnoreCase("F"))
               {
                   grade[x] = g;
                   //Come out of the do - while loop
                   break;
               }//End of if
               //Otherwise show error message and ask again
               else
                   JOptionPane.showMessageDialog (null, "Invalid Grade. Please reenter." );
           }while(true);
       }//End of for loop
   }//End of method
  
   //Method to calculate GPA
   public void calculateWeightedGrade()throws IOException
   {
       double gradePoint = 0.0;
       //Converts character grade to its corresponding value
       for(int x = 0; x < 4; x++)
       {
           if(grade[x].equalsIgnoreCase("A"))
               gradePoint = 4;
           else if(grade[x].equalsIgnoreCase("A-"))
               gradePoint = 3.7;
           else if(grade[x].equalsIgnoreCase("B+"))
               gradePoint = 3.2;
           else if(grade[x].equalsIgnoreCase("B"))
               gradePoint = 3;
           else if(grade[x].equalsIgnoreCase("B-"))
               gradePoint = 2.7;
           else if(grade[x].equalsIgnoreCase("C+"))
               gradePoint = 2.2;
           else if(grade[x].equalsIgnoreCase("C"))
               gradePoint = 2;
           else if(grade[x].equalsIgnoreCase("C-"))
               gradePoint = 1.7;
           else if(grade[x].equalsIgnoreCase("D+"))
               gradePoint = 1.2;
           else if(grade[x].equalsIgnoreCase("D"))
               gradePoint = 1;
           else if(grade[x].equalsIgnoreCase("D-"))
               gradePoint = 0.7;
           else
               gradePoint = 0;
           //Calculates weighted Grade
           weightedGrade = creditHours[x] * gradePoint;
       }//End of for loop
       //Calculates GPA
       GPA = weightedGrade / 4;
       //Writes data to fuile
       writeFile();
   }//End of method
  
   //Method to write data
   public void writeFile()throws IOException
   {
       //Creates a bufferedWriter object to write onto the file
       //true for append mode
       BufferedWriter outputWriter = new BufferedWriter(new FileWriter("GPA.txt", true));
       //Name of the student
       outputWriter.write("Classes for " + name + ":");
       //For next line
       outputWriter.newLine();
       //Writes the heading
       outputWriter.write("Title Credit Grade");
       //For next line
       outputWriter.newLine();
       //Writes subject, credit hour, and grade
       for (int i = 0; i < 4; i++)
       {
           //Writes the guess numbers entered by the user
           outputWriter.write(className[i] + " ");
           outputWriter.write(creditHours[i] + " ");
           outputWriter.write(grade[i] + " ");
           //For next line
           outputWriter.newLine();
       }//End of for loop
       //Writes GPA
       outputWriter.write("GPA: " + Double.toString(GPA));
       //Cleans the stream
       outputWriter.flush();
       //Closes the file
       outputWriter.close();
   }//End of Method
  
   //Main method
   public static void main(String ss[])throws IOException
   {
       StudentGPA sg = new StudentGPA();
       int no = Integer.parseInt(JOptionPane.showInputDialog ( "Enter how may students: " )); ;
       for(int x = 0; x < no; x++)
       {
           sg.accept();
           sg.calculateWeightedGrade();
       }//End of for loop
   }//End of main method
}//End of class

After writing to the file name: GPA.txt contents

Classes for Pyari:
Title    Credit Grade
C   2.0   A  
C++   3.0   C  
Java   1.0   D-  
Python   5.0   D  
GPA: 1.25

Classes for Mohan:
Title Credit Grade.
Java   2.0   A  
C#   4.0   A-  
VB   8.0   C+  
C   4.0   D  
GPA: 1.0