Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- public class Semester {
- public static void main(String[] args) {
- window w = new window();
- w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w.setSize(300,100);
- w.setLocation(500,250);
- w.setVisible(true);
- }
- }
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class window extends JFrame {
- private JButton me, fa;
- public window() {
- super("Semester Wrap-Up");
- setLayout(new FlowLayout());
- me = new JButton("Minimum Exam Grade");
- fa = new JButton("Final Semester Average");
- add(me);
- add(fa);
- Handler h = new Handler();
- me.addActionListener(h);
- fa.addActionListener(h);
- }
- private class Handler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == me) {
- MinimumExam m = new MinimumExam();
- m.setSize(300,130);
- m.setLocation(500,250);
- m.setVisible(true);
- }
- else if(e.getSource() == fa) {
- FinalAvg f = new FinalAvg();
- f.setSize(300,200);
- f.setLocation(500,250);
- f.setVisible(true);
- }
- }
- }
- }
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class MinimumExam extends JFrame {
- private JLabel first, second;
- private JTextField fInput, sInput;
- private JButton calculate;
- public MinimumExam() {
- super("Minimum Exam Grade");
- setLayout(new FlowLayout());
- first = new JLabel("First Nine Weeks Average:");
- second = new JLabel("Second Nine Weeks Average:");
- fInput = new JTextField(3);
- sInput = new JTextField(3);
- calculate = new JButton("Calculate");
- add(first);
- add(fInput);
- add(second);
- add(sInput);
- add(calculate);
- Handler h = new Handler();
- calculate.addActionListener(h);
- }
- private class Handler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == calculate) {
- calc(fInput.getText(),sInput.getText());
- }
- }
- }
- public void calc(String f, String s) {
- try {
- int first = Integer.parseInt(f);
- int second = Integer.parseInt(s);
- double minA = (8950/15.0) - (43/15.0)*first - (42/15.0)*second;
- double minB = (7950/15.0) - (43/15.0)*first - (42/15.0)*second;
- double minC = (7450/15.0) - (43/15.0)*first - (42/15.0)*second;
- double minD = (6950/15.0) - (43/15.0)*first - (42/15.0)*second;
- JFrame results = new JFrame("Results");
- JTextArea r = new JTextArea(15,5);
- r.setEditable(false);
- r.append(String.format("%.2f to get an A\n%.2f to get a B\n%.2f to get a C\n%.2f to pass",minA,minB,minC,minD));
- results.add(r);
- results.setSize(200,100);
- results.setLocation(500,250);
- results.setVisible(true);
- } catch(NumberFormatException ex) {
- JOptionPane.showMessageDialog(null,"You must enter valid number grades.","ERROR",JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class FinalAvg extends JFrame {
- private JLabel first, second, exam;
- private JTextField fIn, sIn, eIn;
- private JButton calculate;
- public FinalAvg() {
- super("Final Semester Average");
- setLayout(new FlowLayout());
- first = new JLabel("First Nine Weeks Average:");
- second = new JLabel("Second Nine Weeks Average:");
- exam = new JLabel("Semester Exam Grade:");
- fIn = new JTextField(3);
- sIn = new JTextField(3);
- eIn = new JTextField(3);
- calculate = new JButton("Calculate");
- add(first);
- add(fIn);
- add(second);
- add(sIn);
- add(exam);
- add(eIn);
- add(calculate);
- Handler h = new Handler();
- calculate.addActionListener(h);
- }
- private class Handler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == calculate) {
- calc(fIn.getText(),sIn.getText(),eIn.getText());
- }
- }
- }
- public void calc(String f, String s, String e) {
- try {
- int first = Integer.parseInt(f);
- int second = Integer.parseInt(s);
- int exam = Integer.parseInt(e);
- long semAvg = Math.round(.43*first + .42*second + .15*exam);
- JOptionPane.showMessageDialog(null,"Semester Average: "+semAvg,"Result",JOptionPane.PLAIN_MESSAGE);
- } catch(NumberFormatException ex) {
- JOptionPane.showMessageDialog(null,"You must enter valid number grades.","ERROR",JOptionPane.ERROR_MESSAGE);
- }
- }
- }
Add Comment
Please, Sign In to add comment