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

The requirement of today’s lab is to create a weighted grade calculator. The pro

ID: 3770174 • Letter: T

Question

The requirement of today’s lab is to create a weighted grade calculator. The program should have the following features:

Use pointers to dynamically allocate memory for grade groups, and grade weights

Interactive user prompts to determine the number of the grade groups, the weights, the number of grades for each group, and each individual grade

Calculate the weighted average for each grade group and display the final grade

Use the delete command to free up memory that was allocated

Example Approach:

Prompt the user for the number of grade groups

Use the number of grade groups to allocate the appropriate memory for the group names and the group weights (new command)

create pointer for group names (string)

create pointer for group weights (double)

Use for loop to get names and weights and store in appropriate memory location (use # groups as control)

Use nested for loops to get grades for each group and calculate weighted average(outer for loop) Prompt the user for the number of grades (use for loop with # grade groups as control)

(nested for loop) Prompt user for individual grades and average them using a for loop (use number of grades as control)

Sum the weighted averages (part of the outer for loop)

Display final grade

Use delete command to free up memory

Explanation / Answer

program :   import javax.swing.*;
import javax.swing.AbstractButton;
import java.awt.event.*;
import javax.swing.border.*;
public class Pizza extends JFrame
{
public static void main (String[]args)
{
new Pizza();
}
private JButton buttonOK, buttonNext;
private JRadioButton regular, honors, ap;
private JRadioButton a, b, c, d, f;
public Pizza()
{
this.setSize(320, 200);
this.setTitle("Grade Calculator");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ButtonListener bl=new ButtonListener();
ButtonListener bl2=new ButtonListener();
JPanel mainPanel=new JPanel();
JPanel sizePanel=new JPanel();
Border b1=BorderFactory.createTitledBorder("Class Type");
sizePanel.setBorder(b1);
ButtonGroup sizeGroup=new ButtonGroup();
ButtonGroup GradeGroup=new ButtonGroup();
regular=new JRadioButton("Regular");
regular.setSelected(true);
sizePanel.add(regular);
sizeGroup.add(regular);
honors=new JRadioButton("Honors");
sizePanel.add(honors);
sizeGroup.add(honors);
ap=new JRadioButton("AP");
sizePanel.add(ap);
sizeGroup.add(ap);
mainPanel.add(sizePanel);
JPanel topPanel=new JPanel();
Border b2=BorderFactory.createTitledBorder("Letter Grade");
topPanel.setBorder(b2);
a=new JRadioButton("A");
a.setSelected(true);
topPanel.add(a);
GradeGroup.add(a);
b=new JRadioButton("B");
topPanel.add(b);
GradeGroup.add(b);
c=new JRadioButton("C");
topPanel.add(c);
GradeGroup.add(c);
d=new JRadioButton("D");
topPanel.add(d);
GradeGroup.add(d);
f=new JRadioButton("F");
topPanel.add(f);
GradeGroup.add(f);
mainPanel.add(topPanel);
buttonNext=new JButton ("Next Class");
buttonNext.addActionListener(bl2);
mainPanel.add(buttonNext);
buttonOK=new JButton ("Done");
buttonOK.addActionListener(bl);
mainPanel.add(buttonOK);
this.getContentPane().add(mainPanel);
this.setVisible(true);
}
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e)
{
double gradepoints=0.0;
if (e.getSource()==buttonNext)
{
if (a.isSelected ()&& regular.isSelected())
gradepoints+=4.0;
if (a.isSelected ()&& honors.isSelected())
gradepoints+=4.5;
if (a.isSelected ()&& ap.isSelected())
gradepoints+=6.0;
if (b.isSelected ()&& regular.isSelected())
gradepoints+=3.0;
if (b.isSelected ()&& honors.isSelected())
gradepoints+=3.375;
if (b.isSelected ()&& ap.isSelected())
gradepoints+=4.5;
if (c.isSelected ()&& regular.isSelected())
gradepoints+=2.0;
if (c.isSelected ()&& honors.isSelected())
gradepoints=2.25;
if (c.isSelected ()&& ap.isSelected())
gradepoints+=3.0;
if (d.isSelected ()&& regular.isSelected())
gradepoints+=1.0;
if (d.isSelected ()&& honors.isSelected())
gradepoints+=1.125;
if (d.isSelected ()&& ap.isSelected())
gradepoints+=1.5;
if (f.isSelected ()&& regular.isSelected())
gradepoints+=0.0;
if (f.isSelected ()&& honors.isSelected())
gradepoints+=0.0;
if (f.isSelected ()&& ap.isSelected())
gradepoints+=0.0;
}
if (e.getSource()==buttonOK){
}
}
}
}