Object Oriented Software Concepts and Development PRACTICAL ASSIGNMENT N0236685B
Object Oriented Software Concepts and Development PRACTICAL ASSIGNMENT N0236685B
Write a complete Java program that accept a set of marks in test out of 100 for 40
students. The program should find the average and highest marks in the test and
display them. Use a method to capture the marks into an array via keyboard. Include
another method that receive an array of the captured marks and returns their sum.
[20]
import java.util.Scanner;
// Display results
System.out.println("Average marks: " + average);
System.out.println("Highest marks: " + highestMarks);
}
return marks;
}
}
Output of example using a class of 40 students including of example of what happens
when mark not within the range is entered
Question 2
Create a login Java application that authenticate users by checking their details in a
database with an interface given below. The application should allow the user to enter
their username and password. On clicking login button, if user credentials are in the
database the application should display a message “Log in Successful” else it displays
message “Wrong password or username”. On clicking reset button the application
should clear the username and password textboxes. Create MySQL database with 3
user details which the application works with for user authentication.
[30]
USE user_auth;
);
('john_doe', 'password123'),
('jane_smith', 'mypassword'),
('admin', 'admin123');
Code to create and implement login page,
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
// Connecting to database
try {
return DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Database connection failed!");
return null;
}
}
frame.add(usernameLabel);
frame.add(usernameField);
frame.add(passwordLabel);
frame.add(passwordField);
frame.add(loginButton);
frame.add(resetButton);
frame.setVisible(true);
loginButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = usernameField.getText();
String password = new String(passwordField.getPassword());
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
JOptionPane.showMessageDialog(frame, "Login
Successful");
} else {
JOptionPane.showMessageDialog(frame, "Wrong username
or password");
}
stmt.close();
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
});
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
usernameField.setText("");
passwordField.setText("");
}
});
}
}
OUTPUT
Login page