Professional Documents
Culture Documents
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
setBackground(Color.lightGray);
setForeground(Color.black);
add(titleLabel);
add(prelimsLabel);
add(prelimsField);
prelimsField.setForeground(Color.black);
add(midtermLabel);
add(midtermField);
midtermField.setForeground(Color.black);
add(finalsLabel);
add(finalsField);
finalsField.setForeground(Color.black);
add(computeButton);
computeButton.addActionListener(this);
add(clearButton);
clearButton.addActionListener(this);
add(gradeLabel);
add(gradeField);
gradeField.setForeground(Color.black);
add(statusLabel);
add(statusField);
statusField.setForeground(Color.black);
} // end init
if (yhan.getSource()==computeButton)
{
if (strprelims.equals(""))
{
prelimsField.setText("0");
}
if (strmidterm.equals(""))
{
midtermField.setText("0");
}
if (strfinals.equals(""))
{
finalsField.setText("0");
}
// Calculations
double grade = (prelims*0.3) + (midterm*0.3) + (finals*0.4);
// Output grade
gradeField.setText("" + Math.round(grade));
if (grade<75)
{
statusField.setText("failed");
}
else
{
statusField.setText("Pass");
}
if (yhan.getSource()==clearButton)
{
gradeField.setText("");
prelimsField.setText("");
midtermField.setText("");
finalsField.setText("");
statusField.setText("reenter the data");
} // end if clearButton
} // end actionperformed
} // end class