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

Description Write a Java GUI program that will serve as a GPA calculator (using

ID: 3776937 • Letter: D

Question

Description Write a Java GUI program that will serve as a GPA calculator (using the 4.0 scale and only A, B, C, D, or F letter grades) that can accept one semester of five (5) courses. The program will allow the user to enter the letter grade for each of their courses. The interface should calculate the GPA for that semester.

Create a Semester class that can contain information about a student’s semester. Information in the class should include student name, course names (CSCI 1302, MATH 1161, etc.), credit hours, and final letter grades. Each of the non-name items should be stored in separate collections. There should be methods to get total credit hours, calculate total quality points, and to calculate GPA as well as appropriate getters/setters for any data properties.

The GUI program should create a semester instance with your current course names, subjects, numbers, and credit hours. These values will be used to populate the running GUI and can be created manually (aka hard-coded) in the program. The final grades will be set after the user enters them and the Calculate button is clicked.

The interface should contain one set of each of these controls for every course in the semester: ? Course Name – Label or equivalent, value is pre-filled from Semester instance ? Credit Hours – TextField, Label or equivalent, value is pre-filled from Semester instance ? Letter Grade – TextField, ComboBox or equivalent, value is set by user

The values in the Semester instance should be used to pre-populate values for this JavaFX GUI program. The program should allow a user to set letter grades for each of the classes and click the Calculate button to calculate semester GPA. The Calculate button should work by populating the final grades for the Semester instance, then using the GPA calculation method in the Semester class to calculate the semester GPA. The GUI program should then display the calculated GPA from the Semester instance visually. The Reset button should reset grades for the courses and the change the displayed GPA calculation to 0.

Detailed Requirements and Notes: ? This program should: o Assume that there are always 5 courses for being taken a semester.   

o Pre-populate the class name and credit hours based on values in the created Semester instance. o Have a “calculate” button that, when clicked, calculates and displays the GPA to 2 decimals. The calculated value should be visible to the user in the interface (not printed to the console). The calculate operation should set values for the final letter grades within the created Semester instance based on user input. The GPA calculation should be calculated in the semester instance. o Have a “reset” button to reset all letter grades to their default state and set any calculated GPAs to 0.00. ? Research how GPA is calculated with quality points, letter grades, and credit hours to fit the 4.0 scale and use that calculation for this program. ? There are no visual requirements for this project. Design your interface however you would like with whatever controls you feel are best suited. However, you should: o Effectively use panes and spacing/padding/alignment options to present a clear and understandable interface; think of usability when designing. o Consider error prevention/detection o Test all cases (especially blank/null values) and handle them appropriately. ? Use an online GPA calculator to check the results of your calculations. ? Sketching the object will help you figure out which types of panes to use. ? UI Components can be stored and retrieved from ArrayLists. This may make creating and accessing these components easier.

NOTE: this is start up:


public class GPAcal {

public void start(Stage primaryStage) {

}

public static void main(String args[]) {

launch(args); }

} // end GPAcal class

class Semester { }

NOTE:

The way to calculate GPA in university is to multiply the # units for a course by the value of the letter grade received in that course.

A=4

B=3

C=2

D=1

F=0

Do that with all courses, add up the values, then divide by the number of units taken. Now it's on you to translate that into code.

GPA Calculator Classes for John Q Doe Hours Grade CSCI 1302 3.0 MATH 1161 4.0 ENGL 1102 pHys 2212K 4,0 3.0 GPA: 2.94

Explanation / Answer

hello,

I have already worked on this project and am sharing my code here. I hope this helps .

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.text.DecimalFormat;

public class calcGpa extends JFrame{

   private JPanel panel,panelAtas;
   private JButton btnEnter,btnKira;
   private JLabel display,displayGpa;
   private JTextField namaSubjek,creditHour;
  
   double totalCredit=0.0;
   double realGrade=0.0;
   double result=0.0;
   double gpa=0.0;
   int i=0;
   String displayText="";
  
   ArrayList<String> name = new ArrayList<String>();
   ArrayList<Double> gradeList = new ArrayList<Double>();
   ArrayList<Integer> credit = new ArrayList<Integer>();

   //constuctor create frame
   public cuba(){
       final String[] grade = {"-","A+","A","B+","B","C+","C","D+","D"};
      
      
       setTitle("MyFrame");
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setSize(400,300);
  
       setLocationRelativeTo(null);
      
       final JComboBox<String> comboGrade = new JComboBox<String>(grade);
      
       display = new JLabel("");
       displayGpa = new JLabel("");
      
       namaSubjek = new JTextField(10);
       creditHour = new JTextField(3);
      
      
       btnEnter = new JButton("Insert");
      
       btnEnter.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
               name.add(namaSubjek.getText());
               credit.add(Integer.parseInt(creditHour.getText()));
               //System.out.println(name.get(i)+" "+gradeList.get(i)+" "+credit.get(i));
               displayText+=name.get(i)+" "+gradeList.get(i)+" "+credit.get(i)+" ";
               display.setText(displayText);

               i++;
           }
       });
      
       btnKira = new JButton("Calculate!");
       btnKira.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
              
               DecimalFormat f = new DecimalFormat("##.##");
               double GPA=calcGpa();
               System.out.println(f.format(GPA));
               displayGpa.setText("GPA:"+f.format(GPA));
           }
       });
      
       comboGrade.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent ie){
           String str = (String)comboGrade.getSelectedItem();
           gradeList.add(setGrade(str));
       }
       });
      
  
      
       panel = new JPanel();  
       panelAtas = new JPanel();
      
       //panelAtas.add(display);
      
       //add component to panel
       panel.add(namaSubjek);
      
       panel.add(comboGrade);
       panel.add(creditHour);
       panel.add(btnEnter);
       panel.add(btnKira);
       panel.add(display);
       panel.add(displayGpa);
      
      
      
       //add panel to frame
       add(panel);
      
       //personalization
       namaSubjek.setPreferredSize(btnKira.getPreferredSize());  
       creditHour.setPreferredSize(btnKira.getPreferredSize());  
       setVisible(true);
      
  
      
   }
  
   public double setGrade(String g){
  
       //for(int i=0;i<grade.size();i++){
          
           if(g.equals("A+")){
               realGrade=4.0;              
           }
           else if(g.equals("A")){
               realGrade=4.0;
           }           
           else if(g.equals("B+")){
               realGrade=3.33;          
           }
           else if(g.equals("B")){
               realGrade=3.00;          
           }
          
           else if(g.equals("C+")){
               realGrade=2.33;          
           }
           else if(g.equals("C")){
               realGrade=2.00;          
           }
          

           else if(g.equals("D+")){
               realGrade=1.33;          
           }
           else if(g.equals("D")){
               realGrade=1.00;          
           }
          
  
      
       return realGrade;
  
   }

   public double calcGpa(){
  
       for(int j=0;j<name.size();j++){
           result = result+gradeList.get(j)*credit.get(j);
           totalCredit=totalCredit+credit.get(j);
           gpa=result/totalCredit;
       }
      
       return gpa;
   }
   public static void main(String[] args){
       new cuba();
       //System.out.println("Nama Subjek Grade Credit Hour");
  
   }

}