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

Using jGrasp and the Software Development Kit, write a program in response to th

ID: 3537676 • Letter: U

Question

Using jGrasp and the Software Development Kit, write a program in response to the following prompt:

Design a GUI program to find the weighted average of four test scores. The four test scores and their respective weights are given in the following format:

testscore1 weight1
...

For example, the sample data is as follows:

75 0.20
95 0.35
85 0.15
65 0.30

The user is supposed to enter the data and press a Calculate button. The program must display the weighted average.

Remember to follow proper form and design in your response.

To submit your compiled Java code for this assignment, compress the .java file into a single .zip file. Submit this .zip file to the link below.

For additional details, refer to the Programming Problems Rubric in the Assignment Guidelines and Rubrics folder

Explanation / Answer

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class MalikCh6Exercise1 extends JFrame

{private JLabel oneLabel,twoLabel,threeLabel,scoreLabel,weightLabel,onewLabel,twowLabel;

private JLabel threewLabel,fourwLabel,avgLabel,fourLabel,bLabel,bLabel2,bLabel3;

private JTextField oneTextField, twoTextField,threeTextField,fourTextField;

private JTextField onewTextField, twowTextField,threewTextField,fourwTextField, avgwTextField;

private JButton calcButton,exitButton;

private CalculateButtonHandler cbHandler;

private ExitButtonHandler ebHandler;

public MalikCh6Exercise1()

{bLabel=new JLabel("");

bLabel2= new JLabel("");

bLabel3= new JLabel("");

scoreLabel=new JLabel("Score",SwingConstants.CENTER);

weightLabel=new JLabel("Weight",SwingConstants.CENTER);

oneLabel=new JLabel("Test one: ",SwingConstants.RIGHT);

twoLabel=new JLabel("Test two: ",SwingConstants.RIGHT);

threeLabel=new JLabel("Test three: ",SwingConstants.RIGHT);

fourLabel=new JLabel("Test four: ",SwingConstants.RIGHT);

avgLabel=new JLabel("Average: ",SwingConstants.RIGHT);

oneTextField=new JTextField(5);

twoTextField=new JTextField(5);

threeTextField=new JTextField(5);

fourTextField=new JTextField(5);

onewTextField=new JTextField(5);

twowTextField=new JTextField(5);

threewTextField=new JTextField(5);

fourwTextField=new JTextField(5);

avgwTextField=new JTextField(5);

calcButton=new JButton("Calculate");

cbHandler=new CalculateButtonHandler();

calcButton.addActionListener(cbHandler);

exitButton = new JButton("Exit");

ebHandler = new ExitButtonHandler();

exitButton.addActionListener(ebHandler);

Container pane = getContentPane();

pane.setLayout(new GridLayout(7,3));

pane.add(bLabel);

pane.add(oneLabel);

pane.add(scoreLabel);

pane.add(weightLabel);   

pane.add(oneLabel);

pane.add(oneTextField);

pane.add(onewTextField);   

pane.add(twoLabel);

pane.add(twoTextField);

pane.add(twowTextField);   

pane.add(threeLabel);

pane.add(threeTextField);

pane.add(threewTextField);

pane.add(fourLabel);

pane.add(fourTextField);

pane.add(fourwTextField);   

pane.add(avgLabel);

pane.add(avgwTextField);

pane.add(calcButton);

pane.add(bLabel2);

pane.add(bLabel3);

pane.add(exitButton);

setSize(400,300);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

private class CalculateButtonHandler implements ActionListener

{public void actionPerformed(ActionEvent e)

{double one,onew,two,twow,three,threew,four,fourw,avg;

one=Double.parseDouble(oneTextField.getText());

onew=Double.parseDouble(onewTextField.getText());

two=Double.parseDouble(twoTextField.getText());

twow=Double.parseDouble(twowTextField.getText());

three=Double.parseDouble(threeTextField.getText());

threew=Double.parseDouble(threewTextField.getText());

four=Double.parseDouble(fourTextField.getText());

fourw=Double.parseDouble(fourwTextField.getText());

avg=(one*onew+two*twow+three*threew+four*fourw)/(onew+twow+threew+fourw);

avgwTextField.setText(" "+ avg);

}

}

private class ExitButtonHandler implements ActionListener

{public void actionPerformed(ActionEvent e)

{System.exit(0);

}

}


public static void main(String[] args)

{MalikCh6Exercise1 a=new MalikCh6Exercise1();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote