diff --git a/223014732 Cynthia, 223024076 Bella b/223014732 Cynthia, 223024076 Bella
new file mode 100644
index 0000000..292a7a9
--- /dev/null
+++ b/223014732 Cynthia, 223024076 Bella
@@ -0,0 +1,854 @@
+//This is the answer of question one
+
+import javax.swing.JOptionPane;
+
+public class Loan {
+
+ private double monthlyPayment;
+ private int numberOfYears;
+ private double totalAmount;
+
+ // use of Constructor
+ public Loan(double monthlyPayment, int numberOfYears, double totalAmount) {
+ this.monthlyPayment = monthlyPayment;
+ this.numberOfYears = numberOfYears;
+ this.totalAmount = totalAmount;
+ }
+
+ // Setter method that sets monthly payment and number of years, and calculates total amount to be paid.
+ public void setLoan(double monthlyPayment, int numberOfYears) {
+ this.monthlyPayment = monthlyPayment;
+ this.numberOfYears = numberOfYears;
+ // Calculate total amount
+ this.totalAmount = monthlyPayment * numberOfYears * 12; // Calculate total amount
+ }
+
+ // Getter methods
+ public double getMonthlyPayment() {
+ return monthlyPayment;
+ }
+
+ public int getNumberOfYears() {
+ return numberOfYears;
+ }
+
+ public double getTotalAmount() {
+ return totalAmount;
+ }
+
+ // Method to display loan details in a dialog box
+ public void displayLoaninfo() {
+ String message = String.format("Monthly Payment: %.2f%nNumber of Years: %d%nTotal Amount Paid: %.2f",
+ monthlyPayment, numberOfYears, totalAmount);
+ JOptionPane.showMessageDialog(null, message, "Loan Information", JOptionPane.INFORMATION_MESSAGE);
+ }
+
+ public static void main(String[] args) {
+ try {
+ // Enter yearly interest rate
+ String annualInterestRateString = JOptionPane.showInputDialog("Enter interest rate per year (in %):");
+ double annualInterestRate = Double.parseDouble(annualInterestRateString);
+
+ // Enter number of years to be paid
+ String numberOfYearString = JOptionPane.showInputDialog("Enter the number of years:");
+ int numberOfYears = Integer.parseInt(numberOfYearString);
+
+ // Enter amount of loan needed
+ String loanAmountString = JOptionPane.showInputDialog("Enter the loan amount:");
+ double loanAmount = Double.parseDouble(loanAmountString);
+
+ // Calculate monthly interest rate
+ double monthlyInterestRate = annualInterestRate / 1200;
+
+ // Check if monthlyInterestRate is zero to avoid division by zero
+ if (monthlyInterestRate == 0) {
+ JOptionPane.showMessageDialog(null, "Interest rate cannot be zero.", "Input Error", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ // Calculate monthly payment
+ double monthlyPayment = (loanAmount * monthlyInterestRate) /
+ (1 - Math.pow(1 + monthlyInterestRate, -numberOfYears * 12));
+
+ // Create a Loan object and display the loan information
+ Loan loan = new Loan(0, 0, 0); // Initial values
+ loan.setLoan(monthlyPayment, numberOfYears);
+ loan.displayLoaninfo();
+ } catch (NumberFormatException e) {
+ JOptionPane.showMessageDialog(null, "Invalid input! Please enter numeric values.", "Input Error", JOptionPane.ERROR_MESSAGE);
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null, "An error occurred: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+}
+// This is answered based on how you have told us in class that we can take that program you have given us and add a constructor , setter and getter methods
+and we have to create the methods for the variables we entered
+-------------------
+// but due to how it is written in the slides this is how we can answer it , this is our understanding
+
+class Laon {
+ private double monthlyPayment;
+ private int numberOfYears;
+ private double totalAmount;
+
+ // Constructor
+ public Laon(double monthlyPayment, int numberOfYears) {
+ this.monthlyPayment = monthlyPayment;
+ this.numberOfYears = numberOfYears;
+ this.totalAmount = calculateTotalAmount(); // Calculate total amount upon creation
+ }
+
+ // Method to calculate the total amount to be paid
+ private double calculateTotalAmount() {
+ return this.monthlyPayment * this.numberOfYears * 12; // Total payments over the years
+ }
+
+ // Getters
+ public double getMonthlyPayment() {
+ return monthlyPayment;
+ }
+
+ public int getNumberOfYears() {
+ return numberOfYears;
+ }
+
+ public double getTotalAmount() {
+ return totalAmount;
+ }
+
+ // Method to display loan details
+ public void displayLoanDetails() {
+ System.out.println("Monthly Payment: " + this.monthlyPayment+"rwf");
+ System.out.println("Number of Years: " + this.numberOfYears);
+ System.out.println("Total Amount to be Paid: " + this.totalAmount+"rwf");
+ }
+}
+
+public class NewComputerLoan {
+ public static void main(String[] args) {
+ // Example values
+ double monthlyPayment = 1000.00; // Example monthly payment
+ int numberOfYears = 10; // Example payment duration in years
+
+ // Create an instance of Laon
+ Laon loan = new Laon(monthlyPayment, numberOfYears);
+
+ // Display loan details
+ loan.displayLoanDetails();
+ }
+}
+ ================================================================================================================================
+ --------------------------------------------------------------------------------------------------------------------------------
+
+ /*This is the answer of the second quetion . But it is difficult to give all work becouse it is created in different classes
+ and we have two different GUI ,the one to add information and other one to retrieve added information from database .
+ on each GUI there is the button that directs a user to the other GUI, when you are on the GUI that add information you can click the button to view what is in the database
+ and also you can come back to the insertion GUI by clicking to the button that directs you imediately to that GUI.*/
+
+ //firstly connect database and create table
+ class Laon {
+ private double monthlyPayment;
+ private int numberOfYears;
+ private double totalAmount;
+
+ // Constructor
+ public Laon(double monthlyPayment, int numberOfYears) {
+ this.monthlyPayment = monthlyPayment;
+ this.numberOfYears = numberOfYears;
+ this.totalAmount = calculateTotalAmount(); // Calculate total amount upon creation
+ }
+
+ // Method to calculate the total amount to be paid
+ private double calculateTotalAmount() {
+ return this.monthlyPayment * this.numberOfYears * 12; // Total payments over the years
+ }
+
+ // Getters
+ public double getMonthlyPayment() {
+ return monthlyPayment;
+ }
+
+ public int getNumberOfYears() {
+ return numberOfYears;
+ }
+
+ public double getTotalAmount() {
+ return totalAmount;
+ }
+
+ // Method to display loan details
+ public void displayLoanDetails() {
+ System.out.println("Monthly Payment: " + this.monthlyPayment+"rwf");
+ System.out.println("Number of Years: " + this.numberOfYears);
+ System.out.println("Total Amount to be Paid: " + this.totalAmount+"rwf");
+ }
+}
+
+public class NewComputerLoan {
+ public static void main(String[] args) {
+ // Example values
+ double monthlyPayment = 1000.00; // Example monthly payment
+ int numberOfYears = 10; // Example payment duration in years
+
+ // Create an instance of Laon
+ Laon loan = new Laon(monthlyPayment, numberOfYears);
+
+ // Display loan details
+ loan.displayLoanDetails();
+ }
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+package cynthy.workofjava;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.sql.*;
+
+public class answer2 extends javax.swing.JFrame {
+
+ private static final String JDBC_URL = "jdbc:mysql://localhost:3306/studentmanagementsystem";
+ private static final String USERNAME = "root";
+ private static final String PASSWORD = "";
+
+
+ /**
+ * Creates new form answer2
+ */
+ public answer2() {
+ initComponents();
+ setupSubmitButton();
+ }
+ private void setupSubmitButton() {
+ SUBMIT.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ submitForm();
+ }
+ });
+ }
+
+ /**
+ * 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")
+ //
+ private void initComponents() {
+
+ jLabel1 = new javax.swing.JLabel();
+ jLabel3 = new javax.swing.JLabel();
+ jLabel5 = new javax.swing.JLabel();
+ ID = new javax.swing.JTextField();
+ NAME = new javax.swing.JTextField();
+ SCHOOL = new javax.swing.JTextField();
+ jLabel6 = new javax.swing.JLabel();
+ jLabel7 = new javax.swing.JLabel();
+ DEPARTMENT = new javax.swing.JTextField();
+ SUBMIT = new javax.swing.JButton();
+ jLabel8 = new javax.swing.JLabel();
+ MATH = new javax.swing.JCheckBox();
+ ENGLISH = new javax.swing.JCheckBox();
+ ECOMONICS = new javax.swing.JCheckBox();
+ C = new javax.swing.JCheckBox();
+ jLabel9 = new javax.swing.JLabel();
+ COLLEGE = new javax.swing.JTextField();
+ SUBMIT1 = new javax.swing.JButton();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+
+ jLabel1.setBackground(new java.awt.Color(102, 102, 255));
+ jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N
+ jLabel1.setForeground(new java.awt.Color(51, 51, 255));
+ jLabel1.setText("Student Form");
+
+ jLabel3.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
+ jLabel3.setText("Student Id");
+
+ jLabel5.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
+ jLabel5.setText("Student Name");
+
+ ID.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ IDActionPerformed(evt);
+ }
+ });
+
+ NAME.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ NAMEActionPerformed(evt);
+ }
+ });
+
+ SCHOOL.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ SCHOOLActionPerformed(evt);
+ }
+ });
+
+ jLabel6.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
+ jLabel6.setText("School");
+
+ jLabel7.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
+ jLabel7.setText("Department ");
+
+ DEPARTMENT.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ DEPARTMENTActionPerformed(evt);
+ }
+ });
+
+ SUBMIT.setBackground(new java.awt.Color(204, 204, 255));
+ SUBMIT.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
+ SUBMIT.setText("SUBMIT");
+ SUBMIT.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ SUBMITActionPerformed(evt);
+ }
+ });
+
+ jLabel8.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
+ jLabel8.setText("Modules ");
+
+ MATH.setText("Math");
+
+ ENGLISH.setText("English");
+ ENGLISH.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ ENGLISHActionPerformed(evt);
+ }
+ });
+
+ ECOMONICS.setText("Economics ");
+ ECOMONICS.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ ECOMONICSActionPerformed(evt);
+ }
+ });
+
+ C.setText("C programming ");
+ C.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ CActionPerformed(evt);
+ }
+ });
+
+ jLabel9.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
+ jLabel9.setText("College");
+
+ COLLEGE.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ COLLEGEActionPerformed(evt);
+ }
+ });
+
+ SUBMIT1.setBackground(new java.awt.Color(0, 102, 255));
+ SUBMIT1.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
+ SUBMIT1.setText("VIEW");
+ SUBMIT1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ SUBMIT1ActionPerformed(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()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(49, 49, 49)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(SCHOOL, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(28, 28, 28)
+ .addComponent(ID, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(NAME, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(DEPARTMENT, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(MATH, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(ENGLISH, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(ECOMONICS, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(C, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(SUBMIT, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(SUBMIT1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(76, 76, 76))))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(COLLEGE, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))))
+ .addGroup(layout.createSequentialGroup()
+ .addGap(182, 182, 182)
+ .addComponent(jLabel1)))
+ .addContainerGap(63, Short.MAX_VALUE))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(32, 32, 32)
+ .addComponent(jLabel1)
+ .addGap(29, 29, 29)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel3)
+ .addComponent(ID, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel5)
+ .addComponent(NAME, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(21, 21, 21)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(SCHOOL, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(21, 21, 21)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(COLLEGE, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(DEPARTMENT, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel7))
+ .addGap(18, 18, 18)
+ .addComponent(MATH)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(ENGLISH)
+ .addComponent(jLabel8))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(ECOMONICS)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(C)
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(SUBMIT, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(SUBMIT1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addContainerGap(61, Short.MAX_VALUE))
+ );
+
+ pack();
+ }//
+ //SUBMITTING THE FORM
+ private void submitForm() {
+
+ String studentname = NAME.getText().trim();
+ String studentid = ID.getText().trim();
+ String school = SCHOOL.getText().trim();
+ String college = COLLEGE.getText().trim();
+ String department = DEPARTMENT.getText().trim();
+
+ // Collect selected modules
+ StringBuilder modules = new StringBuilder();
+ if (MATH.isSelected()) {
+ modules.append("Math,");
+ }
+ if (ENGLISH.isSelected()) {
+ modules.append("English,");
+ }
+ if (ECOMONICS.isSelected()) {
+ modules.append("Economics,");
+ }
+ if (C.isSelected()) {
+ modules.append("C programmings,");
+ }
+ String selectedModules = modules.length() > 0
+ ? modules.substring(0, modules.length() - 1) : "";
+ // Validate inputs
+ if (studentname.isEmpty() || studentid.isEmpty() || school.isEmpty() || college.isEmpty()
+ || department.isEmpty() ) {
+ JOptionPane.showMessageDialog(this,
+ "Please fill in all fields",
+ "Validation Error",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ try (Connection conn = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD)) {
+ String sql = "INSERT INTO StudentInfo (StudentId, StudentName, School, college, "
+ + " Department,Modules) "
+ + "VALUES (?, ?, ?, ?, ?, ?)";
+
+ try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setString(1, studentid);
+ pstmt.setString(2, studentname);
+ pstmt.setString(3, school);
+ pstmt.setString(4, college);
+ pstmt.setString(5, department);
+ pstmt.setString(6, selectedModules);
+
+ int rowsAffected = pstmt.executeUpdate();
+
+ if (rowsAffected > 0) {
+ JOptionPane.showMessageDialog(this,
+ "Registration successful!",
+ "Success",
+ JOptionPane.INFORMATION_MESSAGE);
+ clearForm();
+ } else {
+ JOptionPane.showMessageDialog(this,
+ "Registration failed",
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ } catch (SQLException ex) {
+ JOptionPane.showMessageDialog(this,
+ "Database error: " + ex.getMessage(),
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ ex.printStackTrace();
+ }
+ }
+ private void clearForm() {
+ ID.setText("");
+ NAME.setText("");
+ SCHOOL.setText("");
+ COLLEGE.setText("");
+ DEPARTMENT.setText("");
+ MATH.setSelected(false);
+ ENGLISH.setSelected(false);
+ ECOMONICS.setSelected(false);
+ C.setSelected(false);
+ }
+ private void IDActionPerformed(java.awt.event.ActionEvent evt) {
+ // TODO add your handling code here:
+ }
+
+ private void NAMEActionPerformed(java.awt.event.ActionEvent evt) {
+ // TODO add your handling code here:
+ }
+
+ private void SCHOOLActionPerformed(java.awt.event.ActionEvent evt) {
+ // TODO add your handling code here:
+ }
+
+ private void DEPARTMENTActionPerformed(java.awt.event.ActionEvent evt) {
+ // TODO add your handling code here:
+ }
+
+ private void SUBMITActionPerformed(java.awt.event.ActionEvent evt) {
+
+ }
+
+ private void ENGLISHActionPerformed(java.awt.event.ActionEvent evt) {
+ // TODO add your handling code here:
+ }
+
+ private void COLLEGEActionPerformed(java.awt.event.ActionEvent evt) {
+ // TODO add your handling code here:
+ }
+
+ private void ECOMONICSActionPerformed(java.awt.event.ActionEvent evt) {
+ // TODO add your handling code here:
+ }
+
+ private void CActionPerformed(java.awt.event.ActionEvent evt) {
+ // TODO add your handling code here:
+ }
+
+ private void SUBMIT1ActionPerformed(java.awt.event.ActionEvent evt) {
+
+ Studentinfo formdisp = new Studentinfo();
+ answer2.this.setVisible(false);
+ formdisp.setVisible(true);
+
+ // TODO add your handling code here:
+ }
+
+ public static void main(String args[]) {
+ /* Set the Nimbus look and feel */
+ //
+ /* 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.html
+ */
+ 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(answer2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(answer2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(answer2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(answer2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //
+
+ /* Create and display the form */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new answer2().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify
+ private javax.swing.JCheckBox C;
+ private javax.swing.JTextField COLLEGE;
+ private javax.swing.JTextField DEPARTMENT;
+ private javax.swing.JCheckBox ECOMONICS;
+ private javax.swing.JCheckBox ENGLISH;
+ private javax.swing.JTextField ID;
+ private javax.swing.JCheckBox MATH;
+ private javax.swing.JTextField NAME;
+ private javax.swing.JTextField SCHOOL;
+ private javax.swing.JButton SUBMIT;
+ private javax.swing.JButton SUBMIT1;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel3;
+ 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;
+ // End of variables declaration
+}
+
+// and this is the the code for the second GUI that shows/ display the information
+
+
+package cynthy.workofjava;
+
+import java.sql.*;
+import javax.swing.*;
+import javax.swing.table.DefaultTableModel;
+
+public class Studentinfo extends javax.swing.JFrame {
+
+ private static final String DB_URL = "jdbc:mysql://localhost:3306/studentmanagementsystem";
+ private static final String USER = "root";
+ private static final String PASS = "";
+
+ /**
+ * Creates new form Studentinfo
+ */
+ public Studentinfo() {
+ initComponents();
+ StudentData();
+ }
+ private void StudentData() {
+ DefaultTableModel model = (DefaultTableModel) TABLE.getModel();
+ model.setRowCount(0); // Clear existing data
+
+ try {
+ // Create database connection
+ Connection connection = DriverManager.getConnection(DB_URL, USER, PASS);
+
+ // Create SQL query
+ String sql = "SELECT StudentId, StudentName, School, college, Department, Modules FROM studentinfo";
+
+ // Create statement and execute query
+ Statement s = connection.createStatement();
+ ResultSet rset = s.executeQuery(sql);
+// Iterate over result set and add rows to table model
+ while (rset.next()) {
+ Object[] row = {
+ rset.getInt("StudentId"),
+ rset.getString("StudentName"),
+ rset.getString("School"),
+ rset.getString("college"),
+ rset.getString("Department"),
+ rset.getString("Modules")
+
+ };
+ model.addRow(row);
+ }
+ // Close resources
+ rset.close();
+ s.close();
+ connection.close();
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ JOptionPane.showMessageDialog(this,
+ "Error loading student data: " + e.getMessage(),
+ "Database Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ /**
+ * 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")
+ //
+ private void initComponents() {
+
+ jScrollPane1 = new javax.swing.JScrollPane();
+ TABLE = new javax.swing.JTable();
+ SUBMIT1 = new javax.swing.JButton();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+
+ TABLE.setModel(new javax.swing.table.DefaultTableModel(
+ new Object [][] {
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null},
+ {null, null, null, null, null, null}
+ },
+ new String [] {
+ "STUDENT ID", "STUDENT NAME", "SCHOOL", "COLLEGE", "DEPARTMENT", "MODULES"
+ }
+ ));
+ jScrollPane1.setViewportView(TABLE);
+
+ SUBMIT1.setBackground(new java.awt.Color(0, 102, 255));
+ SUBMIT1.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
+ SUBMIT1.setText("ADD DATA");
+ SUBMIT1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ SUBMIT1ActionPerformed(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()
+ .addContainerGap(29, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(SUBMIT1)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 674, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addContainerGap(15, Short.MAX_VALUE))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(SUBMIT1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE))
+ );
+
+ pack();
+ }//
+
+ private void SUBMIT1ActionPerformed(java.awt.event.ActionEvent evt) {
+
+answer2 formdisp = new answer2();
+ Studentinfo.this.setVisible(false);
+ formdisp.setVisible(true);
+
+ // TODO add your handling code here:
+ }
+
+ private void addbtnActionPerformed(java.awt.event.ActionEvent evt) {
+ answer2 sdnform =new answer2();
+ Studentinfo.this.setVisible(false);
+ sdnform.setVisible(true);
+ }
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ /* Set the Nimbus look and feel */
+ //
+ /* 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.html
+ */
+ 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(Studentinfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(Studentinfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(Studentinfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(Studentinfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //
+
+ /* Create and display the form */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new Studentinfo().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify
+ private javax.swing.JButton SUBMIT1;
+ private javax.swing.JTable TABLE;
+ private javax.swing.JScrollPane jScrollPane1;
+ // End of variables declaration
+}
+
+// Our database is called StudentManagement
+
+
+
+