Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Online Java Compiler
- // Use this editor to write, compile and run your Java code online
- package course_project;
- import java.text.DecimalFormat;
- import java.awt.event.*;
- import javax.swing.*;
- class CGPA{
- int SUM,PC;
- double res;
- CGPA(int m1,int m2,int m3,int m4,int m5)
- {
- SUM=m1+m2+m3+m4+m5;
- PC=(SUM/5);
- res=PC/9.5;
- }
- double getCGPA()
- {
- return(res);
- }
- }
- public class Course_project {
- private static DecimalFormat df2 = new DecimalFormat("#.##");
- public static void main(String[] args) {
- JFrame f=new JFrame("CGPA CALCULATOR FOR ONE SEM");
- JTextField nf=new JTextField();
- JTextField uf=new JTextField();
- JTextField mf1=new JTextField();
- JTextField mf2=new JTextField();
- JTextField mf3=new JTextField();
- JTextField mf4=new JTextField();
- JTextField mf5=new JTextField();
- JLabel nl=new JLabel("Enter Name :");
- JLabel ul=new JLabel("Enter USN :");
- JLabel m=new JLabel("Enter the Marks for given Subjects");
- JLabel m1l=new JLabel("Maths :");
- JLabel m2l=new JLabel("Java :");
- JLabel m3l=new JLabel("WP :");
- JLabel m4l=new JLabel("DS :");
- JLabel m5l=new JLabel("DE :");
- JLabel nm=new JLabel();
- JLabel un=new JLabel();
- JLabel cgpa=new JLabel();
- JLabel resu=new JLabel();
- JLabel err=new JLabel();
- nm.setBounds(200, 210, 150, 30);
- un.setBounds(200, 230, 150, 30);
- cgpa.setBounds(200, 250, 150, 30);
- resu.setBounds(200, 270, 150, 30);
- err.setBounds(170, 210, 200, 30);
- JButton res=new JButton("Get Result");
- nl.setBounds(50, 20, 100, 20);
- nf.setBounds(130, 20, 100, 20);
- ul.setBounds(50, 50, 100, 20);
- uf.setBounds(130, 50, 100, 20);
- m.setBounds(150, 80, 250, 40);
- m1l.setBounds(30, 120, 50, 20);
- mf1.setBounds(80, 120, 40, 20);
- m2l.setBounds(140, 120, 50, 20);
- mf2.setBounds(180, 120, 40, 20);
- m3l.setBounds(240, 120, 50, 20);
- mf3.setBounds(270, 120, 40, 20);
- m4l.setBounds(330, 120, 50, 20);
- mf4.setBounds(360, 120, 40, 20);
- m5l.setBounds(420, 120, 50, 20);
- mf5.setBounds(450, 120, 40, 20);
- res.setBounds(200, 170, 100, 30);
- res.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- String a,b,c,d,e,nam,usn;
- a=mf1.getText();
- b=mf2.getText();
- c=mf3.getText();
- d=mf4.getText();
- e=mf5.getText();
- nam=nf.getText();
- usn=uf.getText();
- if(!(nf.getText().isEmpty()) && !(uf.getText().isEmpty()))
- {
- if(isNumber(a) && isNumber(b) && isNumber(c) && isNumber(d) && isNumber(e))
- {
- int m1,m2,m3,m4,m5;
- m1=Integer.parseInt(a);
- m2=Integer.parseInt(b);
- m3=Integer.parseInt(e);
- m4=Integer.parseInt(d);
- m5=Integer.parseInt(e);
- nm.setText("Name : : "+nam.toUpperCase());
- un.setText("USN : : "+usn.toUpperCase());
- double ans;
- CGPA s=new CGPA(m1,m2,m3,m4,m5);
- ans=s.getCGPA();
- if(ans>=10.0)
- cgpa.setText("CGPA : : 10");
- else
- cgpa.setText("CGPA : : "+df2.format(ans));
- if(ans>=9)
- resu.setText("RESULT : : DISTINCTION");
- else if(ans == 8)
- resu.setText("RESULT : : FIRST CLASS");
- else if(ans>=6)
- resu.setText("RESULT : : SECOND CLASS");
- else if(ans == 5)
- resu.setText("RESULT :: PASS CLASS");
- else
- resu.setText("RESULT :: FAIL");
- }
- else{
- err.setText("Marks must be only in integers");
- }
- }
- else
- {
- err.setText("Name and USN must be filled");
- }
- }
- });
- f.add(nl);
- f.add(nf);
- f.add(ul);
- f.add(uf);
- f.add(m);
- f.add(m1l);
- f.add(mf1);
- f.add(m2l);
- f.add(mf2);
- f.add(m3l);
- f.add(mf3);
- f.add(m4l);
- f.add(mf4);
- f.add(m5l);
- f.add(mf5);
- f.add(res);
- f.add(nm);
- f.add(un);
- f.add(cgpa);
- f.add(resu);
- f.add(err);
- f.setSize(550,600);
- f.setLayout(null);
- f.setVisible(true);
- }
- static boolean isNumber(String s)
- {
- for (int i = 0; i < s.length(); i++)
- if (Character.isDigit(s.charAt(i)) == false)
- return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement