Professional Documents
Culture Documents
1
Using JLable, JTextfield and JButton
Selection Control Structure(if-else-if Construct)
1. When the user the calculate percentage button, calculate the percentage marks of
the subjects if the student passes in all the subjects otherwise display percentage
marks as follows:
Passing marks=35 maximum marks=100
2. When the user clicks calculate grade and result button, calculate grade and result
as follows:
PERCENTAGE
Greater than or equal
75
Greater than or equal
65
Greater than or equal
55
Greater than or equal
45
Greater than or equal
35
Less than 35
GRADE
to
to
to
to
to
E
F
Result:
If a student fails in one subject, his result is compartment.
If a student fails in more than one subject, his result is fail otherwise it is
pass.
3. When the user clicks on the clear button, clear all textfields and disable the
calculate grade and result button and change the editable status of textfields
Total Marks, Percentage Marks, Grade and Result to false.
4. When the user clicks on the exit button, terminate the program.
Program code:public class EXP1 extends javax.swing.JFrame {
int count;
double pm;
public EXP1() {
initComponents(); }
private void btncalculateActionPerformed(java.awt.event.ActionEvent evt) {
double eng,phy,chem,bio,maths,tm=0.00;
eng=Double.parseDouble(txteng.getText());
phy=Double.parseDouble(txtphy.getText());
maths=Double.parseDouble(txtmaths.getText());
Astrid Ana Gomes
bio=Double.parseDouble(txtbio.getText());
chem=Double.parseDouble(txtchem.getText());
count=0;
if(eng<35)
count++;
if(phy<35)
count++;
if(bio<35)
count++;
if(chem<35)
count++;
if(maths<35)
count++;
if(count==0)
{tm=eng+phy+chem+bio+maths;
pm=tm/500.00*100.00;
txttm.setText(" "+tm);
txtpm.setText(" "+pm);}
else
{txttm.setText("-");
txtpm.setText("-");}
btngrade.setEnabled(true);}
if(pm>=75)
grade='A';
else if(pm>=65)
grade='B';
else if(pm>=55)
grade='C';
else if(pm>=45)
grade='D';
else if(pm>=35)
grade='E';
else grade='F';
txtgrade.setText(" "+grade);
if (count==0)
txtresult.setText("pass");
else if(count==1)
txtresult.setText("compartment");
else if(count>1)
txtresult.setText("fail");}
txtclass.setText(null);
txtsec.setText(null);
txteng.setText(null);
txtbio.setText(null);
txtmaths.setText(null);
txtchem.setText(null);
txtphy.setText(null);
txttm.setText(null);
txtpm.setText(null);
txttm.setEditable(false);
txtpm.setEditable(false);
txtgrade.setEditable(false);
txtresult.setEditable(false);}
Input/Output:-