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

Completing an application that uses the If...Then.. .BlseIf statement In this tu

ID: 3728410 • Letter: C

Question

Completing an application that uses the If...Then.. .BlseIf statement In this tutorial, you will begin with the program from Tutorial 4-2 and add controls and program code that display the student's letter grade (A, B, GD,F Step 1: Open the Test Score Average 2 project you modified in Tutorial 42. Step 2: Drag the form's border downward about one-half inch, and drag the IbIMessage control and the three Button controls downward on the form to make space for a new row of controls Drag the lower border of the group box downward about one-half inch to make room for a label that will display the student's letter grade Step 3: Inside the group box add the new Label controls shown in Figure 4-8. When you add the label on the left, set its Text property to Grade. When you add the label on the right, set its Name property to lblGrade, its AutoSize property to Fale, and set its BorderSgyle property to FixadiD. Step 4: Figure 4-8 Adding the Grade label inside the group box wsge 1blGrade

Explanation / Answer


import java.awt.*;  
import java.awt.event.*;  
public class TestScoreAverage extends Frame implements ActionListener{  
private enum Actions {
CALAVG,
CLEAR,
EXIT
}
TextField tf1,tf2,tf3,tf4,tf5; Label l1,l2,l3,l4,l5,l6,l7,l8,l9; Button b1,b2,b3;  
TestScoreAverage(){  
l1=new Label("Enter Three test scores 0-100");  
l1.setBounds(50,100, 250,20);
l2=new Label("Score 1");  
l2.setBounds(50,150, 80,20);
l3=new Label("Score 2");  
l3.setBounds(50,200, 80,20);
l4=new Label("Score 3");  
l4.setBounds(50,250, 80,20);
l5=new Label("Average");  
l5.setBounds(50,300, 80,20);
l6=new Label("Grade");  
l6.setBounds(50,350, 80,20);
tf1=new TextField();  
tf1.setBounds(150,150, 100,20);
l7=new Label();  
l7.setBounds(200,150, 100,20);
l7.setVisible(false);
tf2=new TextField();  
tf2.setBounds(150,200, 100,20);
l8=new Label();  
l8.setBounds(200,200, 100,20);
l8.setVisible(false);
tf3=new TextField();  
tf3.setBounds(150,250, 100,20);
l9=new Label();  
l9.setBounds(200,250, 100,20);
l9.setVisible(false);
tf4=new TextField();  
tf4.setBounds(150,300, 100,20);
tf4.setEnabled(false);
tf5=new TextField();  
tf5.setBounds(150,350, 100,20);
tf5.setEnabled(false);

b1=new Button("Calculate Avg");  
b1.setBounds(50,450,100,50);
b1.setActionCommand(Actions.CALAVG.name());
b1.addActionListener(this);   
add(b1);
b2=new Button("Clear");  
b2.setBounds(200,450,100,50);
b2.setActionCommand(Actions.CLEAR.name());
b2.addActionListener(this);   
add(b2);
b3=new Button("Exit");  
b3.setBounds(200,500,100,50);
b3.setActionCommand(Actions.EXIT.name());
b3.addActionListener(this);   
add(b3);
add(tf1);add(tf2);add(tf3);add(tf4);add(tf5);
add(l1);add(l2);add(l3);add(l4);add(l5);add(l6);   
setSize(600,800);  
setLayout(null);  
setVisible(true);  
}
  
@Override
public void actionPerformed(ActionEvent evt) {
if (evt.getActionCommand() == Actions.CALAVG.name()) {
try {
int sc1=Integer.parseInt(tf1.getText());
int sc2=Integer.parseInt(tf2.getText());
int sc3=Integer.parseInt(tf3.getText());
double avg=(sc1+sc2+sc3)/3;
String grade=null;
if (avg>=90) {
grade="A";
} else if(avg>=80 && avg<90) {
grade="B";
}
else if(avg>=70 && avg<80) {
grade="C";
}
else if(avg>=60 && avg<70) {
grade="D";
}
else
{
grade="F";
}
tf4.setText(String.valueOf(avg));
tf5.setText(grade);
} catch (Exception e2) {
e2.printStackTrace();
}
}else if (evt.getActionCommand() == Actions.CLEAR.name()) {
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
else if(evt.getActionCommand() == Actions.EXIT.name()) {
System.exit(0);
}   
}  
public static void main(String[] args) {  
new TestScoreAverage();  
}  
}  

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