Making a calculator about letter grades

Course Queries Syllabus Queries 3 years ago

8.05K 2 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago

 

I am taking Maths and I want to make a calculator which tells me the each note I need to take in the final exam to get each letter grade. In the syllabus it tells us that our note is calculated by this:

MT1 - First midterm %26.6 MT2- Second midterm %26.6 F- Final % 26.6 Q - Quizzes % 10 HW- Homeworks % 10

These are the grade intervals: A 80-100 A- 75-80 B+ 70-75 B 65-70 B- 60-65 C+ 55-60 C 50-55 C- 45-50 D+ 40-45 D+ 30-40 F 0-30

You enter MT1, MT2, Q, HW in the JTextFields and when you click the button it will update the jlabel's near the letter grades. When I run the code for the first time, it works but when I want to change it program doesn't update the numbers. Could you help?

Final_Calculator:

import javax.swing.*;
import java.awt.*;

public class Final_Calculator extends JFrame
{

    public static void main(String[] args) 
    {
        JFrame frame = new JFrame("Final Calculator");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new Results());
        frame.pack();
        frame.setVisible(true);
    }
}

Grades:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Grades extends JPanel
{
    private JLabel l1, l2, l3, l4;
    private JTextField t1, t2, t3, t4;
    private double sum,result, MT1, MT2, Q, HW;
    private JButton button;

    public Grades() 
    {
        setPreferredSize(new Dimension(200,100));
        l1 = new JLabel("MT1");
        l2 = new JLabel("MT2");
        l3 = new JLabel("Q");
        l4 = new JLabel("HW");
        t1 = new JTextField("100");
        t2 = new JTextField("100");
        t3 = new JTextField("100");
        t4 = new JTextField("100");
        button = new JButton("Click!");

        TextListener listener = new TextListener();

        button.addActionListener(listener);

        add(l1);
                                                
0 views
0 shares

profilepic.png
manpreet 3 years ago

From the looks of it/only working once, it looks like you are not updating the label after clicking the button.Label text have to updated via label.setText(""); just calling the method wont do anything.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum