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

write with JAVA You will create a Java application which Dr. Java can use to cal

ID: 3876629 • Letter: W

Question

write with JAVA

You will create a Java application which Dr. Java can use to calculate a student’s final grade. To do this:
1. Create a driver similar to the PushCounter . This driver instantiates a panel object from a new class that was created for this specific GUI example. Explicitly, in PushCounter, an object named panel was instantiated from a new class called PushCounterPanel. PushCounterPanel is a new class that is defined on pages 249-250. You are to create a driver for this homework assignment which is similar in format to PushCounter. Name your driver, ClassAverage


2. Create a class similar to PushCounterPanel that defines all the GUI components you need for the assignment described below. You should not create multiple panels. Use only one panel. I want simple solutions. Overcomplicating your homework assignment will cause a deduction in points. Remember you are NOT to use a Layout Manager for this assignment. Name your panel ClassAveragePanel.

Input areas

Dr. Java teaches a class which uses the following weighted percentages for student grades:
60% from homework
15% from weekly quizzes
25% from the final exam

You will create a Java application which Dr. Java can use to calculate a student’s final grade.

Create the appropriate GUI components to input the following 3 items (all on a scale of 0-100):
o Homework average
o Quiz average
o Final exam score
Output area
Create an appropriate GUI component to display a student’s course average
Headings and Clearly Labeled Components
Create appropriate GUI components to format the panel with headings and clearly identified input and output areas of the panel
Each GUI you create should be easy to use and clearly defines input and output areas for the user (so that know how to use the panel)
Calculate, Clear, and Exit Buttons
Add three buttons to the panel:
o Calculate course average
o Clear data
o Exit
Button listener
You are to create one Button listener to properly handle the three buttons
For the calculate button:
o Use the values entered by the user and the weighting factors for the 3 categories to calculate
a student’s course average.
o Example:
Homework average of 92%
Quiz average of 84.5%
Final exam of 74%
The course average will be: 86.4% (rounded to one decimal place)
For the clear button:
o Clear all of the data in the input fields and output area.
o Place the curser in the first text field (set the focus to the text field) so that the form is ready
for the user to enter data again.
o There is a method named requestFocusInWindow() which will place the focus on a specific
component (a button, a text field, etc.). For example, if there is a JTextField object named
firstName, the following will set the focus to the firstName text field:
firstName.requestFocusInWindow();
For the exit button:
This button will end and close the application when clicked.
Do a quick search on System.exit(0);

Explanation / Answer

import javax.swing.JOptionPane; //Needed for GUI

import java.text.DecimalFormat; //needed to format the Output

public class DTTestAverageAndGrade

{//Begin class

public static void main(String[] args)

{//Begin main method

String inputString; //For reader's input

double Score1, //Define score1

Score2, //Define score2

Score3, //Define score3

Score4, //Define score4

Score5, //Define score5

Average ;//Define Average

DecimalFormat formatter = new DecimalFormat("#,##0.0"); //format the scores

// Get the five scores

inputString=

JOptionPane.showInputDialog("Enter the First Test Score: "); //ask user to enter the first test score

Score1 = Double.parseDouble(inputString);

inputString=

JOptionPane.showInputDialog("Enter the Second Test Score: ");//ask user to enter the second test score

Score2 = Double.parseDouble(inputString);

inputString=

JOptionPane.showInputDialog("Enter the third test score: ");//ask user to enter the third test score

Score3 = Double.parseDouble(inputString);

inputString=

JOptionPane.showInputDialog("Enter the fourth test score: ");//ask user to enter the fourth test score

Score4 = Double.parseDouble(inputString);

inputString=

JOptionPane.showInputDialog("Enter the fifth test score: ");//ask user to enter the fifth test score

Score5 = Double.parseDouble(inputString);

// Call to method calcAverage and output the 5 test average

Average = calcAverage(Score1, Score2, Score3, Score4, Score5);

// Display Average test Score and Determine the letter grade for each test and call to determineGrade

JOptionPane.showMessageDialog(null, " Your Score 1 is : " +formatter.format(Score1) +" Grade: " + determineGrade(Score1)

+ " Your Score 2 is : " +formatter.format(Score2) +" Grade: " + determineGrade(Score2)

+ " Your Score 3 is : " +formatter.format(Score3) +" Grade: " + determineGrade(Score3)

+ " Your Score 4 is : " +formatter.format(Score4) +" Grade: " + determineGrade(Score4)

+ " Your Score 5 is : " +formatter.format(Score5) +" Grade: " + determineGrade(Score5)

+ " Your Average is : " +formatter.format(Average) +" Grade: " + determineGrade(Average),

" Your Test Results",JOptionPane.INFORMATION_MESSAGE);

}//end Main method

// Calculate the average of the five test scores

public static double calcAverage(double Score1, double Score2, double Score3, double Score4, double Score5)

{

double Average = ((Score1 + Score2 + Score3 + Score4 + Score5) / 5);

return Average;

}

// Determine the letter grade for the average and 5 test scores

public static double determineGrade(double Average)

{

char grade; // Define grade

// Determine letter grade

if (Average>=90)

{

grade = 'A';

JOptionPane.showMessageDialog(null, grade + " ");

}

else if (Average>=80)

{

grade = 'B';

JOptionPane.showMessageDialog(null, grade + " ");

}

else if (Average>=70)

{

grade = 'C';

JOptionPane.showMessageDialog(null, grade + " ");

}

else if (Average>=60)

{

grade = 'D';

JOptionPane.showMessageDialog(null, grade + " ");

}

else if (Average<60)

{

grade = 'F';

JOptionPane.showMessageDialog(null, grade + " ");

}

else

{

JOptionPane.showMessageDialog(null, "error ");

}

return 0;

}//end determinegrade method

}//end class