Top  blogs

Monday, September 8, 2014

Free GPA Calculator-Simple App by FxMax

This is a free and open source software which you can use for calculate your GPA value.Developed base on java and use Netbeans IDE. If you need any information please contact me using anuradhakelum92@gmail.com.





Source code is here



Main class:
package gpacal;

import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;


public class GpaCal {


    public static void main(String[] args) {
        try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());                

                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
                      System.err.println("Error on feel and look");
                    }
        
        NewJFrame GUI=new NewJFrame();
        GUI.setVisible(true);
    }

   
    
}

GUI Class 


package gpacal;

import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

public class NewJFrame extends javax.swing.JFrame {

    public NewJFrame() {
        initComponents();
        
        setIcon();
    }
    
    
    
public void getname(){
    
String subject=jTextField1.getText();
        System.out.println(subject);
       String result=String.valueOf(jComboBox1.getSelectedItem());
        System.out.println(result);
       float credit;
       credit = Float.parseFloat(String.valueOf(jComboBox2.getSelectedItem()));
        System.out.println(credit);
       float total=0;
      
       if (  result.equals("A+")){
             total=credit*4;
        }
       if (  result.equals("A")){
            total=credit*4;
        }   
       if (  result.equals("A-")){
            total=(float) (credit*3.7);
        }   
       if (  result.equals("B+")){
            total=(float) (credit*3.3);
        }   
       if (  result.equals("B")){
           total=credit*3;
        }   
       if (  result.equals("B-")){
            total=(float) (credit*2.7);
        }   
       if (  result.equals("C+")){
             total=(float) (credit*2.3);
        }   
       if (  result.equals("C")){
             total=credit*2;
        }   
       if (  result.equals("C-")){
             total=(float) (credit*1.7);
        }   
       if (  result.equals("D+")){
            total=(float) (credit*1.3);
        }   
       if (  result.equals("D")){
            total=credit*1;
        }   
       if (  result.equals("F")){
             total=credit*0;
        } 
       else{
           System.out.println("Enter wrong number");
       }
       
        System.out.println(total);
       
       Object[] row={subject,result,credit,total};
       DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
       model.addRow(row);
}




public float calculate(){
    float credits;
        credits = 0;
    float total;
        total = 0;
       for(int i=0;i<jTable1.getRowCount();i++){
       
           float temp=Float.valueOf(String.valueOf(jTable1.getModel().getValueAt(i, 2)));
           credits=credits+temp;
           
           
           float temp1=Float.valueOf(String.valueOf(jTable1.getModel().getValueAt(i, 3)));
           total=total+temp1;
           
           
       }
       
       System.out.println("TotCredit "+credits+" TotTotal "+total);
       
       float gpa=0.0f;
       gpa=total/credits;
       jLabel4.setText("You have completed "+credits+" credits and "+jTable1.getRowCount()+" subjects.Your GPA Value is : "+gpa);
       return gpa;
       
}


public void ExcelExporter()
    {}
    public void exportTable(JTable table, File file) throws IOException
    {
         try {
            TableModel model = table.getModel();
         FileWriter excel = new FileWriter(file);
         for(int i = 0; i < model.getColumnCount(); i++)
         {
           excel.write(model.getColumnName(i) + "\t");
         }
        excel.write("\n");
        for(int i=0; i< model.getRowCount(); i++) {
         for(int j=0; j < model.getColumnCount(); j++) {
           excel.write(model.getValueAt(i,j).toString()+"\t");
        }
       excel.write("\n");
       
       
    }
        excel.write("GPA: "+calculate());
     excel.close();
     System.out.println("Your file writed...GPA: "+calculate());
     JOptionPane.showMessageDialog(rootPane, "Excel file is created");
        } catch (IOException | HeadlessException e) {
            
             JOptionPane.showMessageDialog(rootPane, "Error occured during the operation.Please close excel if it is open and try again");
        }
  }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GPA Calculator - Simple App by FxMax");
        setAlwaysOnTop(true);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setIconImages(getIconImages());
        setResizable(false);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A+", "A", "A-", "B+","B","B-","C+","C","C-","D+","D","F" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jButton1.setText("Add");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("GPA");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "3", "2", "1", "6" }));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Subject", "Grade", "# of Credit", "Total"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Float.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setColumnSelectionAllowed(true);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        jButton3.setText("Exit");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel1.setText("Subject");

        jButton4.setText("Save as excel sheet");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Delete Row");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("!");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 535, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(90, 90, 90))
            .addGroup(layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3)
                    .addComponent(jLabel1)
                    .addComponent(jButton4)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>                        

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                          

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
    getname();
    jTextField1.setText(null);
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        System.exit(1);
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        float gpa=calculate();
        JOptionPane.showMessageDialog(rootPane, "Your GPA is : "+gpa);
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
        File file = new File("abc.xls");//Note that i'm actually saving the file first
        try {
            exportTable(jTable1, file);
        } catch (IOException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
     
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        
        int selectedRow = jTable1.getSelectedRow();
if(selectedRow != -1) {
    model.removeRow(selectedRow);
}
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        JOptionPane.showMessageDialog(rootPane, "Coded by TMAK Wijethunga as 1st Year university project.\n \tUOP/FOS");
    }                                        

    public static void main(String args[]) throws IOException {
       
        try {
                    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());                

                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
                        System.err.println("error occured...");
                                          }
        
        
        
        
        
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                
               
                
                
                new NewJFrame().setVisible(true);
                
                
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   

    private void If(boolean equals) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    private void setIcon() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("icon.png")));
    }
}

1 comment:

  1. I would like to convey my thanks to you from Trinidad and Tobago as your blog was able to assist me with a similar project I had. the project seemed a bit frustrating at first to complete; however since stumbling upon your site after numerous internet searches, i was able to get the help i needed. My Lecturer was also impressed with the end result. Thanks again for your help!!!

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...