import javax.swing.*;
import java.awt.event.*;
import java.lang.Math;

public class ScoreCalc extends JFrame {
    JLabel sub1, sub2, sub3, sub4, sub5, sub6, total, percent, grade;
    JTextField tfsub1, tfsub2, tfsub3, tfsub4, tfsub5, tfsub6;
    JButton btn;

    public ScoreCalc() {
        sub1 = new JLabel("English");
        sub2 = new JLabel("Mathematic");
        sub3 = new JLabel("Physics");
        sub4 = new JLabel("Chemistry");
        sub5 = new JLabel("Electronics/CS");
        sub6 = new JLabel("Work Experience");

        total = new JLabel("Total >> ");
        percent = new JLabel("Percentage >> ");
        grade = new JLabel("Grade >> ");

        tfsub1 = new JTextField();
        tfsub2 = new JTextField();
        tfsub3 = new JTextField();
        tfsub4 = new JTextField();
        tfsub5 = new JTextField();
        tfsub6 = new JTextField();

        sub1.setBounds(10, 10, 100, 20);
        sub2.setBounds(10, 30, 100, 20);
        sub3.setBounds(10, 50, 100, 20);
        sub4.setBounds(10, 70, 100, 20);
        sub5.setBounds(10, 90, 100, 20);
        sub6.setBounds(10, 110, 100, 20);

        tfsub1.setBounds(180, 10, 50, 20);
        tfsub2.setBounds(180, 30, 50, 20);
        tfsub3.setBounds(180, 50, 50, 20);
        tfsub4.setBounds(180, 70, 50, 20);
        tfsub5.setBounds(180, 90, 50, 20);
        tfsub6.setBounds(180, 110, 50, 20);

        total.setBounds(10, 130, 200, 20);
        percent.setBounds(10, 150, 300, 20);
        grade.setBounds(10, 170, 200, 20);

        btn = new JButton("Calculate Score");
        btn.setBounds(10, 190, 200, 20);

        add(sub1);
        add(sub2);
        add(sub3);
        add(sub4);
        add(sub5);
        add(sub6);
        add(tfsub1);
        add(tfsub2);
        add(tfsub3);
        add(tfsub4);
        add(tfsub5);
        add(tfsub6);
        add(total);
        add(percent);
        add(grade);
        add(btn);

        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                double m1 = Double.parseDouble(tfsub1.getText());
                double m2 = Double.parseDouble(tfsub2.getText());
                double m3 = Double.parseDouble(tfsub3.getText());
                double m4 = Double.parseDouble(tfsub4.getText());
                double m5 = Double.parseDouble(tfsub5.getText());
                double m6 = Double.parseDouble(tfsub6.getText());

                double t = m1 + m2 + m3 + m4 + m5 + m6;
                double p = Math.round(t * 100.0) / 600.0;
                String g = "";

                if (p > 90)
                    g = "Outstanding";
                else if (p > 70 && p <= 90)
                    g = "Very Good";
                else if (p > 50 && p <= 70)
                    g = "Good";
                else if (p >= 35 && p <= 50)
                    g = "Needs Improvement";
                else if (p < 35)
                    g = "Fail";

                total.setText("Total >> " + t + "/600");
                percent.setText("Percentage >> " + p + "%");
                grade.setText("Grade >> " + g);

            }
        });

        setTitle("Score Calculator");
        setLayout(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 300);
        setVisible(true);
    }

    public static void main(String[] args) {
        new ScoreCalc();
    }

}
