InterviewSolution
| 1. |
Aditya is a programmer at Edudel enterprises. He created the following GUI in NetBeans.Help him to write code in Java for the following:(i) To calculate Total marks obtained and display in jTextField4 on the click of command button "Get Total".(ii) To calculate Grade obtained and display in jTextField5 on the click of command button "Get Grade". Criteria for Grade calculation is given below:MarksGradeAbove 80AAbove 50 and < = 55BAbove 50 and < = 65C< = 50D(iii) To stop execution and exit from the application on the click of command button "Exit". |
|
Answer» (i) private void jButton1ActionPerf ormed(java.awt.event.ActionEvent evt) { int a = Integer.parseInt(jTextField1.getText()); int b = Integer.parseInt(jTextField2.getText()); int c = Integer.parseInt(jTextField3.getText()); int total = a + b + c; jTextField4.setText(Integer.toString(total)); } (ii) private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { int t = Integer.parseInt(jTextField4.getText()); int a = t/3; if(a >=80) { jTertField5.setText("A"); } else if(a>55 && a<=55) { j TextField5. setText("B"); } else if(a>50 && a<=65) { jTextField5.setText("C"); } else if(a< =50) { jTextField5.setText("D"); } } (iii) privatevoidjButton3ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } |
|