Advertisement
jbn6972

Untitled

Dec 20th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. // Online Java Compiler
  2. // Use this editor to write, compile and run your Java code online
  3.  
  4. package course_project;
  5. import java.text.DecimalFormat;
  6. import java.awt.event.*;
  7. import javax.swing.*;
  8. class CGPA{
  9. int SUM,PC;
  10. double res;
  11. CGPA(int m1,int m2,int m3,int m4,int m5)
  12. {
  13. SUM=m1+m2+m3+m4+m5;
  14. PC=(SUM/5);
  15. res=PC/9.5;
  16. }
  17. double getCGPA()
  18. {
  19. return(res);
  20. }
  21. }
  22.  
  23. public class Course_project {
  24. private static DecimalFormat df2 = new DecimalFormat("#.##");
  25. public static void main(String[] args) {
  26.  
  27. JFrame f=new JFrame("CGPA CALCULATOR FOR ONE SEM");
  28. JTextField nf=new JTextField();
  29. JTextField uf=new JTextField();
  30. JTextField mf1=new JTextField();
  31. JTextField mf2=new JTextField();
  32. JTextField mf3=new JTextField();
  33. JTextField mf4=new JTextField();
  34. JTextField mf5=new JTextField();
  35.  
  36. JLabel nl=new JLabel("Enter Name :");
  37. JLabel ul=new JLabel("Enter USN :");
  38. JLabel m=new JLabel("Enter the Marks for given Subjects");
  39. JLabel m1l=new JLabel("Maths :");
  40. JLabel m2l=new JLabel("Java :");
  41. JLabel m3l=new JLabel("WP :");
  42. JLabel m4l=new JLabel("DS :");
  43. JLabel m5l=new JLabel("DE :");
  44.  
  45. JLabel nm=new JLabel();
  46. JLabel un=new JLabel();
  47. JLabel cgpa=new JLabel();
  48. JLabel resu=new JLabel();
  49. JLabel err=new JLabel();
  50.  
  51. nm.setBounds(200, 210, 150, 30);
  52. un.setBounds(200, 230, 150, 30);
  53. cgpa.setBounds(200, 250, 150, 30);
  54. resu.setBounds(200, 270, 150, 30);
  55. err.setBounds(170, 210, 200, 30);
  56.  
  57.  
  58.  
  59. JButton res=new JButton("Get Result");
  60.  
  61. nl.setBounds(50, 20, 100, 20);
  62. nf.setBounds(130, 20, 100, 20);
  63.  
  64. ul.setBounds(50, 50, 100, 20);
  65. uf.setBounds(130, 50, 100, 20);
  66.  
  67. m.setBounds(150, 80, 250, 40);
  68.  
  69. m1l.setBounds(30, 120, 50, 20);
  70. mf1.setBounds(80, 120, 40, 20);
  71. m2l.setBounds(140, 120, 50, 20);
  72. mf2.setBounds(180, 120, 40, 20);
  73. m3l.setBounds(240, 120, 50, 20);
  74. mf3.setBounds(270, 120, 40, 20);
  75. m4l.setBounds(330, 120, 50, 20);
  76. mf4.setBounds(360, 120, 40, 20);
  77. m5l.setBounds(420, 120, 50, 20);
  78. mf5.setBounds(450, 120, 40, 20);
  79.  
  80. res.setBounds(200, 170, 100, 30);
  81.  
  82.  
  83. res.addActionListener(new ActionListener(){
  84. public void actionPerformed(ActionEvent ae){
  85. String a,b,c,d,e,nam,usn;
  86. a=mf1.getText();
  87. b=mf2.getText();
  88. c=mf3.getText();
  89. d=mf4.getText();
  90. e=mf5.getText();
  91. nam=nf.getText();
  92. usn=uf.getText();
  93. if(!(nf.getText().isEmpty()) && !(uf.getText().isEmpty()))
  94. {
  95. if(isNumber(a) && isNumber(b) && isNumber(c) && isNumber(d) && isNumber(e))
  96. {
  97. int m1,m2,m3,m4,m5;
  98. m1=Integer.parseInt(a);
  99. m2=Integer.parseInt(b);
  100. m3=Integer.parseInt(e);
  101. m4=Integer.parseInt(d);
  102. m5=Integer.parseInt(e);
  103.  
  104. nm.setText("Name : : "+nam.toUpperCase());
  105. un.setText("USN : : "+usn.toUpperCase());
  106.  
  107. double ans;
  108. CGPA s=new CGPA(m1,m2,m3,m4,m5);
  109. ans=s.getCGPA();
  110.  
  111. if(ans>=10.0)
  112. cgpa.setText("CGPA : : 10");
  113. else
  114. cgpa.setText("CGPA : : "+df2.format(ans));
  115.  
  116.  
  117. if(ans>=9)
  118. resu.setText("RESULT : : DISTINCTION");
  119. else if(ans == 8)
  120. resu.setText("RESULT : : FIRST CLASS");
  121. else if(ans>=6)
  122. resu.setText("RESULT : : SECOND CLASS");
  123. else if(ans == 5)
  124. resu.setText("RESULT :: PASS CLASS");
  125. else
  126. resu.setText("RESULT :: FAIL");
  127. }
  128. else{
  129. err.setText("Marks must be only in integers");
  130. }
  131. }
  132. else
  133. {
  134. err.setText("Name and USN must be filled");
  135. }
  136. }
  137. });
  138.  
  139. f.add(nl);
  140. f.add(nf);
  141. f.add(ul);
  142. f.add(uf);
  143. f.add(m);
  144. f.add(m1l);
  145. f.add(mf1);
  146. f.add(m2l);
  147. f.add(mf2);
  148. f.add(m3l);
  149. f.add(mf3);
  150. f.add(m4l);
  151. f.add(mf4);
  152. f.add(m5l);
  153. f.add(mf5);
  154. f.add(res);
  155. f.add(nm);
  156. f.add(un);
  157. f.add(cgpa);
  158. f.add(resu);
  159. f.add(err);
  160. f.setSize(550,600);
  161. f.setLayout(null);
  162. f.setVisible(true);
  163. }
  164. static boolean isNumber(String s)
  165. {
  166. for (int i = 0; i < s.length(); i++)
  167. if (Character.isDigit(s.charAt(i)) == false)
  168. return false;
  169.  
  170. return true;
  171. }
  172.  
  173. }
  174.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement