Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
287 changes: 287 additions & 0 deletions Reg number:223012040 and 223013296
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
import javax.swing.JOptionPane;

class Loan {
private double monthlyPayment;
private int numberOfYears;
private double totalAmount;

// Constructor
public Loan(double monthlyPayment, int numberOfYears) {
this.monthlyPayment = monthlyPayment;
this.numberOfYears = numberOfYears;
this.totalAmount = calculateTotalAmount();
}

// Method to calculate the total amount
private double calculateTotalAmount() {
return monthlyPayment * numberOfYears * 12;
}

// Getter methods
public double getMonthlyPayment() {
return monthlyPayment;
}
public int getNumberOfYears() {
return numberOfYears;
}

public double getTotalAmount() {
return totalAmount;
}
}

public class SimpleComputeLoan {
public static void main(String[] args) {
// Enter yearly interest rate from input dialog
String annualInterestRateString = JOptionPane.showInputDialog("Enter yearly interest rate");
double annualInterestRate = Double.parseDouble(annualInterestRateString);
double monthlyInterestRate = annualInterestRate / 1200;

// Enter the number of years to pay off the loan
String numberOfYearsString = JOptionPane.showInputDialog("Enter the number of years");
int numberOfYears = Integer.parseInt(numberOfYearsString);

// Enter loan amount needed
String loanAmountString = JOptionPane.showInputDialog("Enter the loan amount");
double loanAmount = Double.parseDouble(loanAmountString);

// Calculate monthly payment using formula
double monthlyPayment = (loanAmount * monthlyInterestRate) /
(1 - Math.pow(1 + monthlyInterestRate, -numberOfYears * 12));

// Create Loan object
Loan loan = new Loan(monthlyPayment, numberOfYears);

// Display the results
JOptionPane.showMessageDialog(null, "Monthly payment: " + loan.getMonthlyPayment() +
"\nTotal amount to be paid over " + loan.getNumberOfYears() + " years: " + loan.getTotalAmount());
    }
}

2.import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class StudentApp {

// Database connection details
private static final String URL = "jdbc:mysql://localhost:3306/Student"; // Database URL
private static final String USER = "your_username"; // Database username
private static final String PASSWORD = "your_password"; // Database password

// Method to establish a connection to the database
public static Connection connect() throws SQLException {
return DriverManager.getConnection(URL, USER, PASSWORD);
}
// Method to insert student data into the database
public void insertStudent(int regNumber, String lastName, String firstName, int yearsOfStudy,
String telephone, String college, String email, boolean physics,
boolean mathematics, boolean chemistry, boolean biology) {
String sql = "INSERT INTO student_information (reg_number, last_name, first_name, years_of_study, telephone, college, email, physics, mathematics, chemistry, biology) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (Connection conn = connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setInt(1, regNumber);
pstmt.setString(2, lastName);
pstmt.setString(3, firstName);
pstmt.setInt(4, yearsOfStudy);
pstmt.setString(5, telephone);
pstmt.setString(6, college);
pstmt.setString(7, email);
pstmt.setBoolean(8, physics);
pstmt.setBoolean(9, mathematics);
pstmt.setBoolean(10, chemistry);
pstmt.setBoolean(11, biology);
pstmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Data inserted successfully.");
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Error inserting data: " + e.getMessage());
}
}

public static void main(String[] args) {
JFrame frame = new JFrame("Student Information");
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel();
frame.add(panel);
placeComponents(panel);

frame.setVisible(true);
}

private static void placeComponents(JPanel panel) {
panel.setLayout(null);
panel.setBackground(new Color(30, 30, 30)); // Light black background

// Labels and text fields
Font labelFont = new Font("Arial", Font.BOLD, 14);
Font textFont = new Font("Arial", Font.PLAIN, 12);

JLabel regLabel = new JLabel("Reg Number:");
regLabel.setBounds(10, 20, 100, 25);
regLabel.setForeground(Color.WHITE);
regLabel.setFont(labelFont);
panel.add(regLabel);

JTextField regText = new JTextField(20);
regText.setBounds(120, 20, 165, 25);
regText.setFont(textFont);
regText.setBackground(new Color(240, 240, 240)); // Light background for text fields
panel.add(regText);

JLabel lastNameLabel = new JLabel("Last Name:");
lastNameLabel.setBounds(10, 50, 100, 25);
lastNameLabel.setForeground(Color.WHITE);
lastNameLabel.setFont(labelFont);
panel.add(lastNameLabel);

JTextField lastNameText = new JTextField(20);
lastNameText.setBounds(120, 50, 165, 25);
lastNameText.setFont(textFont);
lastNameText.setBackground(new Color(240, 240, 240));
panel.add(lastNameText);

JLabel firstNameLabel = new JLabel("First Name:");
firstNameLabel.setBounds(10, 80, 100, 25);
firstNameLabel.setForeground(Color.WHITE);
firstNameLabel.setFont(labelFont);
panel.add(firstNameLabel);

JTextField firstNameText = new JTextField(20);
firstNameText.setBounds(120, 80, 165, 25);
firstNameText.setFont(textFont);
firstNameText.setBackground(new Color(240, 240, 240));
panel.add(firstNameText);
JLabel yearsLabel = new JLabel("Years of Study:");
yearsLabel.setBounds(10, 110, 100, 25);
yearsLabel.setForeground(Color.WHITE);
yearsLabel.setFont(labelFont);
panel.add(yearsLabel);

JTextField yearsText = new JTextField(20);
yearsText.setBounds(120, 110, 165, 25);
yearsText.setFont(textFont);
yearsText.setBackground(new Color(240, 240, 240));
panel.add(yearsText);

JLabel phoneLabel = new JLabel("Telephone:");
phoneLabel.setBounds(10, 140, 100, 25);
phoneLabel.setForeground(Color.WHITE);
phoneLabel.setFont(labelFont);
panel.add(phoneLabel);

JTextField phoneText = new JTextField(20);
phoneText.setBounds(120, 140, 165, 25);
phoneText.setFont(textFont);
phoneText.setBackground(new Color(240, 240, 240));
panel.add(phoneText);

JLabel collegeLabel = new JLabel("College:");
collegeLabel.setBounds(10, 170, 100, 25);
collegeLabel.setForeground(Color.WHITE);
collegeLabel.setFont(labelFont);
panel.add(collegeLabel);

JTextField collegeText = new JTextField(20);
collegeText.setBounds(120, 170, 165, 25);
collegeText.setFont(textFont);
collegeText.setBackground(new Color(240, 240, 240));
panel.add(collegeText);

JLabel emailLabel = new JLabel("Email:");
emailLabel.setBounds(10, 200, 100, 25);
emailLabel.setForeground(Color.WHITE);
emailLabel.setFont(labelFont);
panel.add(emailLabel);

JTextField emailText = new JTextField(20);
emailText.setBounds(120, 200, 165, 25);
emailText.setFont(textFont);
emailText.setBackground(new Color(240, 240, 240));
panel.add(emailText);

// Modules checkboxes (moved to the top-right corner)
JLabel modulesLabel = new JLabel("Select Modules:");
modulesLabel.setBounds(280, 20, 120, 25);
modulesLabel.setForeground(Color.WHITE);
modulesLabel.setFont(labelFont);
panel.add(modulesLabel);

JCheckBox physicsCheckBox = new JCheckBox("Physics");
physicsCheckBox.setBounds(280, 50, 100, 25);
physicsCheckBox.setBackground(new Color(30, 30, 30));
physicsCheckBox.setForeground(Color.WHITE);
panel.add(physicsCheckBox);

JCheckBox mathematicsCheckBox = new JCheckBox("Mathematics");
mathematicsCheckBox.setBounds(280, 80, 120, 25);
mathematicsCheckBox.setBackground(new Color(30, 30, 30));
mathematicsCheckBox.setForeground(Color.WHITE);
panel.add(mathematicsCheckBox);
JCheckBox chemistryCheckBox = new JCheckBox("Chemistry");
chemistryCheckBox.setBounds(280, 110, 100, 25);
chemistryCheckBox.setBackground(new Color(30, 30, 30));
chemistryCheckBox.setForeground(Color.WHITE);
panel.add(chemistryCheckBox);

JCheckBox biologyCheckBox = new JCheckBox("Biology");
biologyCheckBox.setBounds(280, 140, 80, 25);
biologyCheckBox.setBackground(new Color(30, 30, 30));
biologyCheckBox.setForeground(Color.WHITE);
panel.add(biologyCheckBox);

// Submit and Search buttons with custom style
JButton submitButton = new JButton("Submit");
submitButton.setBounds(10, 270, 100, 25);
submitButton.setBackground(Color.RED);
submitButton.setForeground(Color.WHITE);
submitButton.setFont(new Font("Arial", Font.BOLD, 14));
panel.add(submitButton);

JButton searchButton = new JButton("Search");
searchButton.setBounds(120, 270, 100, 25);
searchButton.setBackground(Color.RED);
searchButton.setForeground(Color.WHITE);
searchButton.setFont(new Font("Arial", Font.BOLD, 14));
panel.add(searchButton);

StudentApp app = new StudentApp();

// Action for Submit button
submitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int regNumber = Integer.parseInt(regText.getText());
String lastName = lastNameText.getText();
String firstName = firstNameText.getText();
int yearsOfStudy = Integer.parseInt(yearsText.getText());
String telephone = phoneText.getText();
String college = collegeText.getText();
String email = emailText.getText();

// Collect module data
boolean physics = physicsCheckBox.isSelected();
boolean mathematics = mathematicsCheckBox.isSelected();
boolean chemistry = chemistryCheckBox.isSelected();
boolean biology = biologyCheckBox.isSelected();

app.insertStudent(regNumber, lastName, firstName, yearsOfStudy, telephone, college, email, physics, mathematics, chemistry, biology);
}
});

// Action for Search button (can be enhanced)
searchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Search functionality can be added here
JOptionPane.showMessageDialog(null, "Search functionality coming soon!");
}
     });
    }
}