Java Netbeans program in which Mr. Vidyarthi has to calculate percentage and grade for medical and non-medical streams.

Q22. Mr. Vidyarthi works in Blossoms Public School as a programmer. He is required to develop a student record. The school offers two different streams: medical and non-medical, with different grading criteria. The school also offers incentive to the NCC cadets in the form of a 3% increment in percentage for all the NCC cadets. The grading criterion for the two streams is given below:

Stream Percentage Grade
 

Medical

>=80 A
60-79 B
< 60 C
 

Non-Medical

>=75 A
50-74 B
< 50 C

There is JPanel a container which is used for Medical and Non-Medical:

  • jRadioButton1 : Medical(OptMed) with buttonGroup1.
  • jRadioButton2 : Non-Medical(OptNMed) with buttonGroup1.
  • jCheckBox1 : NCC Cadet(chkNCC).

In the data entry from enter First Term Marks (txtFirst), Second Term Marks (txtSecond), select Stream and/or NCC Cadet and write the code for the following:

  1. Write the code to disable the text boxes for Percentage(txtPercentage) and Grade (txtGrade). Also, set Medical as default stream.
  2. Write the code for Calculate Percentage button to calculate the percentage after finding the total marks of first term and second term (assuming that both marks are out of 100). Also ensure that NCC cadets (chkNCC) get an increment of 3% in their percentages.
  3. Write the code for Calculate Grade button to calculate the grade depending on the stream selected according to the criteria given above.
  4. Write the code for Exit Button and Clear button to Clear all the text boxes and the check box and Medical as default stream.

 

Solution:

Code forĀ Load Frame(right click on frame then event then window then windowopened):

private void formWindowOpened(java.awt.event.WindowEvent evt) {

// TODO add your handling code here:

txtPercentage.setEnabled(false);

txtGrade.setEnabled(false);

OptMed.setSelected(true);

}

Code for Calculate Percentage Button:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

double first=Double.parseDouble(txtFirst.getText());

double second=Double.parseDouble(txtSecond.getText());

double per=((first+second)/200)*100;

if(chkNCC.isSelected())

per=per+3;

txtPercentage.setText(Double.toString(per));

}

Code for Calculate Grade Button:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

double per=Double.parseDouble(txtPercentage.getText());

String grade;

if(OptMed.isSelected())

{

if(per>=80)

grade=”A”;

else if(per>=60)

grade=”B”;

else

grade=”C”;

}

else

{

if(per>=75)

grade=”A”;

else if(per>=50)

grade=”B”;

else

grade=”C”;

}

txtGrade.setText(grade);

}

Code for Clear Button:

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

txtFirst.setText(“”);

txtSecond.setText(“”);

txtPercentage.setText(“”);

txtGrade.setText(“”);

chkNCC.setSelected(false);

OptMed.setSelected(true);

}

Code for Exit Button:

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

System.exit(0);

}

Output:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

154 Views
%d bloggers like this: