0% found this document useful (0 votes)
54 views23 pages

Case Study and FInals

This document contains source code for a Java program that calculates student grades. The program has labels, text fields, and buttons to input student name, number, exam scores (prelim, midterm, finals), and calculate the total score, percentage, and final grade. It uses Swing components like JFrame, JLabel, JTextField, and JButton. The code initializes these components, sets their properties, and defines event handler methods for the buttons to perform the grade calculations.

Uploaded by

Jarlo Carampot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views23 pages

Case Study and FInals

This document contains source code for a Java program that calculates student grades. The program has labels, text fields, and buttons to input student name, number, exam scores (prelim, midterm, finals), and calculate the total score, percentage, and final grade. It uses Swing components like JFrame, JLabel, JTextField, and JButton. The code initializes these components, sets their properties, and defines event handler methods for the buttons to perform the grade calculations.

Uploaded by

Jarlo Carampot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

De La Salle University – Dasmariñas

College of Engineering Architecture and Technology

T – CPET 221 Object Oriented Programming Lecture and Laboratory


Case Study and Final Exam

Submitted by:
Carampot, Jhune Jarlo S.

Submitted to:
Engr. Michael Olivo
Instructor
SOURCE CODES:
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Jarlo Carampot
*/
public class Grading_System extends javax.swing.JFrame {

/**
* Creates new form Grading_System
*/
public Grading_System() {
initComponents();
}

/**
* This method is called from within the constructor to initialize
the form.
* WARNING: Do NOT modify this code. The content of this method is
always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jOptionPane1 = new javax.swing.JOptionPane();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(0, 153, 51));
jLabel1.setFont(new java.awt.Font("Century", 1, 18)); //
NOI18N
jLabel1.setForeground(new java.awt.Color(51, 102, 0));
jLabel1.setText("Grade Calculator");

jLabel2.setFont(new java.awt.Font("Modern No. 20", 0, 24)); //


NOI18N
jLabel2.setForeground(new java.awt.Color(0, 102, 0));
jLabel2.setText("De La Salle University - Dasmariñas");

jLabel3.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N


jLabel3.setForeground(new java.awt.Color(0, 51, 51));
jLabel3.setText("Name:");

jLabel4.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N


jLabel4.setForeground(new java.awt.Color(0, 51, 51));
jLabel4.setText("Student Number:");

jLabel5.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N


jLabel5.setForeground(new java.awt.Color(0, 153, 153));
jLabel5.setText("Prelim:");

jLabel6.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N


jLabel6.setForeground(new java.awt.Color(0, 102, 102));
jLabel6.setText("Midterm:");

jLabel7.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N


jLabel7.setForeground(new java.awt.Color(0, 102, 102));
jLabel7.setText("Finals:");
jTextField3.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jTextField3ActionPerformed(evt);
}
});

jTextField4.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jTextField4ActionPerformed(evt);
}
});

jTextField5.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jTextField5ActionPerformed(evt);
}
});

jLabel8.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N


jLabel8.setForeground(new java.awt.Color(0, 102, 102));
jLabel8.setText("Total:");

jLabel9.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N


jLabel9.setForeground(new java.awt.Color(0, 102, 102));
jLabel9.setText("Percentage:");
jLabel10.setFont(new java.awt.Font("Tahoma", 2, 14)); //
NOI18N
jLabel10.setForeground(new java.awt.Color(0, 102, 102));
jLabel10.setText("Grade:");

jTextField6.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jTextField6ActionPerformed(evt);
}
});

jTextField7.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
jTextField7ActionPerformed(evt);
}
});

jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); //


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

jButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); //


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

jButton3.setFont(new java.awt.Font("Tahoma", 1, 14)); //


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

jButton4.setFont(new java.awt.Font("Tahoma", 1, 14)); //


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

jButton5.setFont(new java.awt.Font("Tahoma", 1, 14)); //


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

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(jLabel3)
.addGap(18, 18, Short.MAX_VALUE)
.addComponent(jLabel4)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE, 110,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(jLabel2)
.addGap(92, 92, 92))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(jLabel6))
.addGroup(layout.createSequentialGroup()
.addGap(85, 85, 85)
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE, 164,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(62, 62, 62)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.TRAILING)
.addComponent(jLabel7)
.addComponent(jLabel5))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.LEADING)
.addGroup(layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.TRAILING)
.addComponent(jTextField4,
javax.swing.GroupLayout.PREFERRED_SIZE, 57,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.PREFERRED_SIZE, 59,
javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jTextField5,
javax.swing.GroupLayout.PREFERRED_SIZE, 57,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.LEADING)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.LEADING)

.addGroup(layout.createSequentialGroup()
.addGap(306, 306, 306)
.addComponent(jLabel9))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGap(343, 343, 343)
.addComponent(jLabel10)))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGap(349, 349, 349)
.addComponent(jLabel8)))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.LEADING)
.addComponent(jTextField6,
javax.swing.GroupLayout.PREFERRED_SIZE, 68,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.TRAILING)
.addComponent(jTextField8,
javax.swing.GroupLayout.PREFERRED_SIZE, 59,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField7,
javax.swing.GroupLayout.PREFERRED_SIZE, 61,
javax.swing.GroupLayout.PREFERRED_SIZE))))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.TRAILING, false)

.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGap(43, 43, 43)
.addComponent(jButton5,
javax.swing.GroupLayout.PREFERRED_SIZE, 101,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton3,
javax.swing.GroupLayout.PREFERRED_SIZE, 203,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4,
javax.swing.GroupLayout.PREFERRED_SIZE, 101,
javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 203,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(63, 63, 63)
.addComponent(jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE, 203,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(184, 184, 184)
.addComponent(jLabel1)))
.addContainerGap(19, Short.MAX_VALUE))
);
layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel1)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2)
.addGap(37, 37, 37)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.LEADING)
.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.BASELINE)
.addComponent(jLabel5)
.addComponent(jLabel8)
.addComponent(jTextField3,
javax.swing.GroupLayout.PREFERRED_SIZE, 43,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField6,
javax.swing.GroupLayout.PREFERRED_SIZE, 39,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(19, 19, 19)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.BASELINE)
.addComponent(jLabel6)
.addComponent(jLabel9)
.addComponent(jTextField4,
javax.swing.GroupLayout.PREFERRED_SIZE, 40,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField7,
javax.swing.GroupLayout.PREFERRED_SIZE, 40,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.BASELINE)
.addComponent(jLabel7)
.addComponent(jTextField5,
javax.swing.GroupLayout.PREFERRED_SIZE, 40,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10)
.addComponent(jTextField8,
javax.swing.GroupLayout.PREFERRED_SIZE, 41,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.BASELINE)
.addComponent(jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE, 41,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 41,
javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3,
javax.swing.GroupLayout.PREFERRED_SIZE, 55,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGap(358, 358, 358)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.BASELINE)
.addComponent(jButton5,
javax.swing.GroupLayout.PREFERRED_SIZE, 45,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4,
javax.swing.GroupLayout.PREFERRED_SIZE, 42,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())))
);

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

private void jButton1ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
int prelim = Integer.parseInt(jTextField3.getText());
int midterm = Integer.parseInt(jTextField4.getText());
int finals = Integer.parseInt(jTextField5.getText());

int tot = prelim + midterm + finals;

jTextField6.setText("" + tot);
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
System.exit(0);
}

private void jTextField4ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
}

private void jTextField7ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
}

private void jButton5ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
jTextField8.setText("");
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
int tot = Integer.parseInt(jTextField6.getText());

int per = tot / 3 ;

jTextField7.setText("" + per);
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
double per = Double.parseDouble(jTextField7.getText());

char Grade;

if (per>=98)
Grade = '1';
else
if (per>=95)
Grade = '2';
else
if (per>=92)
Grade = '3';
else
if (per>=89)
Grade = '4';
else
if (per>=86)
Grade = '5';
else
if (per>=83)
Grade = '6';
else
if (per>=80)
Grade = '7';
else
if (per>=77)
Grade = '8';
else
if (per>=74)
Grade = '9';
else
if (per>=71)
Grade = 'Q';
else
if (per>=68)
Grade = 'W';
else
if (per>=64)
Grade = 'E';
else
if (per>=60)
Grade = 'R';
else
Grade = '0';

jTextField8.setText("" + Grade);
}

private void jTextField5ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
}

private void jTextField3ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
}

private void jTextField6ActionPerformed(java.awt.event.ActionEvent


evt) {
// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel
setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay
with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.ht
ml
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(Grading_System.class.getName()).log
(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Grading_System.class.getName()).log
(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Grading_System.class.getName()).log
(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Grading_System.class.getName()).log
(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Grading_System().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.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JOptionPane jOptionPane1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
// End of variables declaration
}
SAMPLE OUTPUT:
Condition:
Grade of: 2.25 – Marked as “8”

4.00 – Marked as “1” 2.00 – Marked as “9”

3.75 – Marked as “2” 1.75 – Marked as “Q”

3.50 – Marked as “3” 1.50 – Marked as “W”

3.25 – Marked as “4” 1.25 – Marked as “E”

3.00 – Marked as “5” 1.00 – Marked as “R”

2.75 – Marked as “6” 0.00 – Marked as “0”

2.50 – Marked as “7”

You might also like