Sample java programs free download source code
Bookmark and Share
 
Free Website Design Templates
Free Website Design Templates
Web Site Template10
view actual page | download
Web Site Template 1
view actual page | download
Web Site Template 4
view actual page | download

My Java Home |

Java Grade Computation Applet Free Source code

Source code: download for right indenting or just copy and paste the source code below.

More Free Java Programs:

  • Java Program - Grade Computation Applet
  • Java Program - Grade Computation Stand Alone Application
  • Java Program - Length Converter Applet
  • Java Program - Length Converter Stand Alone Application

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class ama_grade_applet extends Applet implements ActionListener
{

Label titleLabel = new Label(" AMA Grading System ");

Label prelimsLabel = new Label("Prelims: ",Label.LEFT);
TextField prelimsField = new TextField(10);

Label midtermLabel = new Label("Midterm: ",Label.LEFT);
TextField midtermField = new TextField(10);

Label finalsLabel = new Label("Finals: ",Label.LEFT);
TextField finalsField = new TextField(10);

Button computeButton = new Button(" Compute ");
Button clearButton = new Button(" Clear ");

Label gradeLabel = new Label("Grade: ",Label.RIGHT);
TextField gradeField = new TextField(10);

Label statusLabel = new Label("Status: ",Label.RIGHT);
TextField statusField = new TextField("enter the data",10);

public void init()
{ //begin init-------------------------------

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

public void actionPerformed(ActionEvent yhan)
{

//declare object strings
String strprelims = new String(prelimsField.getText());
String strmidterm = new String(midtermField.getText());
String strfinals = new String(finalsField.getText());


if (yhan.getSource()==computeButton)

{
if (strprelims.equals(""))
{
prelimsField.setText("0");
}

if (strmidterm.equals(""))
{
midtermField.setText("0");
}

if (strfinals.equals(""))
{
finalsField.setText("0");
}

// Converting input to values
int prelims = Integer.parseInt(prelimsField.getText());
int midterm = Integer.parseInt(midtermField.getText());
int finals = Integer.parseInt(finalsField.getText());

// 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 (grade > 100)
{
statusField.setText("You may have invalid input");
}
} // end if computeButton

if (yhan.getSource()==clearButton)
{
gradeField.setText("");
prelimsField.setText("");
midtermField.setText("");
finalsField.setText("");
statusField.setText("reenter the data");
} // end if clearButton

} // end actionperformed

Free Website Templates
Web Design Articles
Math Calculators
Java Programs
Site map
Contact Us
Useful Links
Web Designer in Philippines
Web Design Resources


Sample java programs free download source code Copyright © 2004 - 2010. yhanpolo.com All rights are reserved
  Valid XHTML 1.0 Transitional   Valid CSS!