Share on Google+Share on Google+

Design and Implement GPA Calculator
5 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners

Once the user clicks on the calculate button the program should display on a dialog box first the info about the student like his name. ID, session and student type. Second the program should display the GPA.

Once the user clicks on the clear button all the fields in the form should be cleared. Once the user clicks on the cancel button the program should stop.

Assume that all the courses have the same credits number which is: 3

The points for the letter grades are as follows:

A 4 B+ 3.5 B 3 c+ 2.5 C 2 D+ 1.5 D 1 F 0

the user should be able to enter the letter grades in lower or upper cases like A or a.


View Answers

June 14, 2013 at 10:38 AM

Try the following code snippet, may this will be helpful for you.

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class GPACalculator {

    JFrame frame;   
    JInternalFrame jInternalFrame;
    JLabel headingLabel, stuNameLabel, stuIdLabel, sessionLabel, 
    stuType, courseLabel1, courseLabel2, courseLabel3, courseLabel4, 
    courseLabel5, courseLabel6;
    JCheckBox eveningCheckbox, morningCheckbox;
    JRadioButton regularRdbtn, nonDegreeRdbtn;
    JTextField course1, course2, course3, course4, course5, course6,
    stuNameTf, stuIdTf;
    JButton calculate, clear, cancel;
    JDesktopPane desktop = new JDesktopPane();

    public void createUI()
        frame = new JFrame("GPA Calculator");
        //frame.setLayout(new BorderLayout());
        headingLabel = new JLabel("Welcome To GPA Calculator");
        headingLabel.setBounds(10, 10, 200, 20);

        stuNameLabel = new JLabel("Student Name");
        stuNameLabel.setBounds(30, 30, 100, 20);

        stuNameTf = new JTextField();
        stuNameTf.setBounds(130, 30, 100, 20);

        stuIdLabel = new JLabel("ID");
        stuIdLabel.setBounds(270, 30, 20, 20);

        stuIdTf = new JTextField();
        stuIdTf.setBounds(290, 30, 100, 20);

        sessionLabel = new JLabel("Session");
        sessionLabel.setBounds(30, 60, 80, 20);

        eveningCheckbox = new JCheckBox("Evening");
        eveningCheckbox.setBounds(110, 60, 80, 20);

        morningCheckbox = new JCheckBox("Morning");
        morningCheckbox.setBounds(190, 60, 80, 20);

        stuType = new JLabel("Student Type");
        stuType.setBounds(30, 90, 80, 20);

        regularRdbtn = new JRadioButton("regular");
        regularRdbtn.setBounds(110, 90, 80, 20);

        nonDegreeRdbtn = new JRadioButton("non Degree");
        nonDegreeRdbtn.setBounds(190, 90, 100, 20);

        courseLabel1 = new JLabel("Course1");
        courseLabel1.setBounds(30, 120, 60, 20);

        course1 = new JTextField();
        course1.setBounds(90, 120, 100, 20);

        courseLabel2 = new JLabel("Course2");
        courseLabel2.setBounds(200, 120, 60, 20);

        course2 = new JTextField();
        course2.setBounds(260, 120, 100, 20);

        courseLabel3 = new JLabel("Course3");
        courseLabel3.setBounds(30, 150, 60, 20);

        course3 = new JTextField();
        course3.setBounds(90, 150, 100, 20);

        courseLabel4 = new JLabel("Course4");
        courseLabel4.setBounds(200, 150, 60, 20);

        course4 = new JTextField();
        course4.setBounds(260, 150, 100, 20);

        courseLabel5 = new JLabel("Course5");
        courseLabel5.setBounds(30, 180, 60, 20);

        course5 = new JTextField();
        course5.setBounds(90, 180, 100, 20);

        courseLabel6 = new JLabel("Course6");
        courseLabel6.setBounds(200, 180, 60, 20);

        course6 = new JTextField();
        course6.setBounds(260, 180, 100, 20);


June 14, 2013 at 10:38 AM

calculate = new JButton("Calculate");
        calculate.setBounds(80, 230, 100, 20);
        calculate.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae)

        clear = new JButton("Clear");
        clear.setBounds(190, 230, 80, 20);
        clear.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae)

        cancel = new JButton("Cancel");
        cancel.setBounds(280, 230, 80, 20);
        cancel.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae)



June 14, 2013 at 10:39 AM

public JCheckBox checkboxName()
        JCheckBox ckbox = null;
            ckbox = eveningCheckbox;
        else if(morningCheckbox.isSelected())
            ckbox = morningCheckbox;

        return ckbox;

    public JRadioButton radioButtonName()
        JRadioButton radioBtn = null;
            radioBtn = regularRdbtn;
        else if(nonDegreeRdbtn.isSelected())
            radioBtn = nonDegreeRdbtn;

        return radioBtn;

June 14, 2013 at 10:40 AM


public String getGPA()
        double A = 0, BP = 0, B = 0, CP = 0, C = 0, DP = 0, D = 0, F = 0;
        double avg = 0, total=0;
        String gpa = "";
        String grade ="";
        String c1 = course1.getText();
        String c2 = course2.getText();
        String c3 = course3.getText();
        String c4 = course4.getText();
        String c5 = course5.getText();
        String c6 = course6.getText();      

                || c2.equalsIgnoreCase("a")
                || c3.equalsIgnoreCase("a") 
                || c4.equalsIgnoreCase("a")
                || c5.equalsIgnoreCase("a")
                || c6.equalsIgnoreCase("a"))
            A = 4;
        else if(c1.equalsIgnoreCase("b+")
                || c2.equalsIgnoreCase("b+")
                || c3.equalsIgnoreCase("b+")
                || c4.equalsIgnoreCase("b+")
                || c5.equalsIgnoreCase("b+")
                || c6.equalsIgnoreCase("b+"))
            BP = 3.5;
        else if(c1.equalsIgnoreCase("b")
                || c2.equalsIgnoreCase("b")
                || c3.equalsIgnoreCase("b")
                || c4.equalsIgnoreCase("b")
                || c5.equalsIgnoreCase("b")
                || c6.equalsIgnoreCase("b"))
            B = 3;
        else if(c1.equalsIgnoreCase("c+")
                || c2.equalsIgnoreCase("c+")
                || c3.equalsIgnoreCase("c+")
                || c4.equalsIgnoreCase("c+")
                || c5.equalsIgnoreCase("c+")
                || c6.equalsIgnoreCase("c+"))
            CP = 2.5;
        else if(c1.equalsIgnoreCase("c")
                || c2.equalsIgnoreCase("c")
                || c3.equalsIgnoreCase("c")
                || c4.equalsIgnoreCase("c")
                || c5.equalsIgnoreCase("c")
                || c6.equalsIgnoreCase("c"))
            C = 2;
        else if(c1.equalsIgnoreCase("d+")
                || c2.equalsIgnoreCase("d+")
                || c3.equalsIgnoreCase("d+")
                || c4.equalsIgnoreCase("d+")
                || c5.equalsIgnoreCase("d+")
                || c6.equalsIgnoreCase("d+"))
            DP = 1.5;
        else if(c1.equalsIgnoreCase("d")
                || c2.equalsIgnoreCase("d")
                || c3.equalsIgnoreCase("d")
                || c4.equalsIgnoreCase("d")
                || c5.equalsIgnoreCase("d")
                || c6.equalsIgnoreCase("d"))
            D = 1;
        else if(c1.equalsIgnoreCase("f")
                || c2.equalsIgnoreCase("f")
                || c3.equalsIgnoreCase("f")
                || c4.equalsIgnoreCase("f")
                || c5.equalsIgnoreCase("f")
                || c6.equalsIgnoreCase("f"))
            F = 0;

        avg = A+BP+B+CP+C+DP+D+F;
        if(avg >= 4)
            gpa = "A";
        if(avg < 4 && avg >=3.5)
            gpa = "B+";
        if(avg < 3.5 && avg >= 3)
            gpa = "B";
        if(avg < 3 && avg >= 2.5)
            gpa = "C+";
        if(avg < 2.5 && avg >= 2)
            gpa = "C";
        if(avg < 2 && avg >= 1.5)
            gpa = "D+";
        if(avg < 1.5 && avg >=1)
            gpa = "D";
        if(avg < 1)
            gpa = "F";
        return gpa;         


June 14, 2013 at 10:41 AM


public void displayStudentRecord()
        jInternalFrame = new JInternalFrame("Student Record", true, true, true, true);
        jInternalFrame.setBounds(50, 50, 400, 250);

        String stuName = stuNameTf.getText();
        String stuId = stuIdTf.getText();
        String checkboxValue = checkboxName().getText();
        String radioBtnValue = radioButtonName().getText();
        String stuGpaValue = getGPA();

        JLabel stuNameLabel = new JLabel("Name");
        JLabel name = new JLabel();
        stuNameLabel.setBounds(20, 20, 80, 20);
        name.setBounds(130, 20, 150, 20);

        JLabel stuIdLabel = new JLabel("ID");
        JLabel id = new JLabel();
        stuIdLabel.setBounds(20, 40, 30, 20);
        id.setBounds(130, 40, 100, 20);

        JLabel ckLabel = new JLabel("Session");
        JLabel ckValue = new JLabel();
        ckLabel.setBounds(20, 60, 80, 20);
        ckValue.setBounds(130, 60, 100, 20);

        JLabel rdLabel = new JLabel("Student Type");
        JLabel rdValue = new JLabel();
        rdLabel.setBounds(20, 80, 110, 20);
        rdValue.setBounds(130, 80, 100, 20);

        JLabel gpLabel = new JLabel("GPA");
        JLabel gpValue = new JLabel();
        gpLabel.setBounds(20, 100, 30, 20);
        gpValue.setBounds(130, 100, 20, 20);



    public void resetFields()

    public void closeFrame()
    public static void main(String args[])
        GPACalculator cal = new GPACalculator();

Related Tutorials/Questions & Answers:
Design and Implement GPA Calculator
Design and Implement GPA Calculator  Once the user clicks...); headingLabel = new JLabel("Welcome To GPA Calculator... should display the GPA. Once the user clicks on the clear button all the fields
How can i implement the calculator programe in jsp code
How can i implement the calculator programe in jsp code  Please send code for the calculator using jsp technologies please guidelines to me.   Here is a simple jsp calculator code that accepts two numbers from the user
Calculator  need a simple java program to degin a CALCULATOR without using ADVANCED JAVA....   Calculator in Java Swing
calculator midlet
calculator midlet  give me code calculator midlet in bluetooth application with j2me
Calculator class
Calculator class  I am a beginner in Eclipse. I have to do a program called calculator that adds numbers. This is my code so far: //Margaret //ICS... class Calculator extends JFrame implements ActionListener { JTextField text
simple calculator program in javascript
simple calculator program in javascript  strong textsimple calculator in javascript
thread program for calculator implementation
thread program for calculator implementation  Hi i'm prem i need calculator progrm in java that are implemented by Thread interface.....pls strong text
base calculator.. - Java Beginners
base calculator..  Help, i need some help about a base calculator.. i don't know how to start
Program for Calculator - Swing AWT
Program for Calculator  write a program for calculator?  Hi Friend, Please visit the following link: Hope that it will be helpful
calculator - Java Interview Questions
calculator  create calculator by java code  Hi Friend, Please visit the following link: Thanks
PHP Tax Calculator - PHP
PHP Tax Calculator  In my project i required a tax calculator that can calculate the property tax
simple calculator - Java Beginners
simple calculator  how can i create a simple calculator using java codes?  Hi Friend, Please visit the following link: Thanks
Calculator - JSP-Servlet
Calculator  Dear Deepak Sir, Calculator program is avilable in Jsp... calculator program in jsp function checkValue(){ var msg...; } Simple calculator program in jsp /> >
Java Calculator Program
Java Calculator Program  Hi, so I need to make a program that "works like a calculator". I need to make two versions: 1) I'm given the Expression Class and need to implement the children classes, which are Number, Product, Sum
calculator - Java Server Faces Questions
calculator  Some ideas for the project of calculator
matrix calculator - Java Beginners
matrix calculator  hi..... can you help me in writing source code of matrix calculator in java... i know you are the best you can do it!!! show yourself
Scientific Calculator - Java Beginners
Scientific Calculator  Develop a scientific calculator using even-driven programming paradigm of Java.? Thanks in ADVANCE  Hi Friend, Please visit the following link:
How to write calculator in J2ME program?
How to write calculator in J2ME program?  How to write calculator in J2ME program
calculator in java with stack
calculator in java with stack  i want calcultor with interface in java and in interface there is button called postfix ,,, when the user enter opertions and numbers first check if is vaild or not then convert to postfix
base calculator.. - Java Beginners
base calculator..  need some help!!! I cant install jcreator properly?? there's always an error (Error : Invalid path, "C:\Program Files\Java\jre1.6.0_01\bin\javac.exe" -classpath "C:\Program Files\Java\jdk1.6.0_01\bin" -d "C
Implement push
Implement push  Hi.. How do you implement push on a flex applications? give me answer with example so i clearly understand Thanks  Ans: push implement on a flex applications using BlazeDS Server
Implement push
Implement push  hi....... just tell me about How do you implement push with flex data services? give me answer with example Thanks  Ans: Using BlazeDS Server and Live Cycle Data Services
Web design program - WebSevices
Web design program  Design an HTML page to create the standard calculator. When user will click on the button, display the caption of selected button in new document
swimming pool calculator
", customers); jtabbedPane.addTab("Temp Calculator", tempCalc
Simple Java Calculator - Java Beginners
Calculator for 4 basic Math operations, Addition, Subtraction, Multiplication and Division. The calculator should simulate the look of handheld calculator containing.... Write proper code for making this calculator operational. Students
Java Calculator program - Java Beginners
Java Calculator program  import java.awt.*; import javax.swing.*; import java.awt.event.*; class Calculator implements ActionListener { int c,n...; Calculator() { f=new Frame("Calculator"); p=new Panel(); b1=new JButton("0
HTML Calculator
HTML Calculator In this example we will learn how to make HTML Calculator. We have used HTML language in this example. First off all we have created one...;. This calculator can be used to perform simple mathematical operations like
Swimming Pool Calculator - Java Beginners
Calculator is one that is very simple to use. As you can see, it is a user... PoolVolume() { mainFrame = new JFrame("Swimming Pool Volume Calculator
Writing Calculator Stateless Session Bean
Writing Calculator Stateless Session Bean... for our Calculator Session Bean:   /* * ...; <session > <description>EJB Calculator Session
Java Swing Scientific Calculator
Java Swing Scientific Calculator A Scientific Calculator is a very powerful and general purpose calculator. In addition to basic arithmetic functions... calculator using java swing. Here is the code: import java.awt.*; import
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null