JAVA Project
JAVA Project
INTRODUCTION
Java is a widely used programming language for developing various types of applications. In this
case, we will use Java to create a quiz application that allows users to test their knowledge on
different topics.
An online quiz application is an interactive platform that allows users to test their knowledge and
skills by answering questions on various topics. The application is designed to provide an
engaging and challenging experience to users, and to facilitate the management and tracking of
quizzes and results.
The quiz application will be designed to present a series of questions to the user, with multiple-
choice answers. The user will be prompted to select the correct answer, and the application will
then provide feedback on whether the selected answer is correct or not.
To create a quiz application using Java, the first step is to define the requirements and
functionality of the application. This includes identifying the types of quizzes that will be
available, the format and structure of the questions, the user interface and navigation, and the
features for tracking and analyzing results.
Once the requirements are established, the application can be built using Java programming
language and various libraries and frameworks. The application can include features such as user
authentication, question randomization, timed quizzes, score tracking and reporting, and
integration with other platforms.
In addition to technical skills, creating a successful quiz application also requires effective design
and user experience considerations. This includes creating an intuitive and engaging interface,
ensuring the application is accessible to a diverse range of users, and providing clear and concise
feedback and results
2.SYSTEM ANALYSIS
Traditional quizzes can take many forms, such as school quizzes, and game shows. The questions
can be on a wide range of subjects, such as history, science, pop culture, sports, and current
events.
In a traditional quiz, questions are typically presented to the players or teams, who then write
down their answers. The answers are then collected and scored, with the team or player with the
highest score at the end of the quiz declared the winner.
Depending on the format and number of questions, traditional quizzes can be time-consuming to
complete. This may make them less appealing to people who have limited time or attention
spans.
In some cases, participants may cheat or look up answers during a quiz, which can undermine the
integrity of the competition.
For some people, taking quizzes can cause anxiety or stress, particularly if they are being timed
or graded. This may detract from the enjoyment of the experience.
Traditional quizzes may be biased towards certain cultural or demographic groups, or may not be
inclusive of diverse perspectives or experiences
2.1 PROPOSED SYSTEM
A quiz using Java is a computer program that allows users to test their knowledge on various
topics. The program presents a series of questions with multiple-choice answers and prompts the
user to select the correct answer. The program then provides feedback on whether the selected
answer is correct or not.
Developing a quiz using Java involves using various programming concepts, such as loops,
conditional statements, arrays, and object-oriented programming. Additionally, user interface
components such as buttons, labels, and text fields are used to create an interactive experience
for the user.
The quiz program can be customized by adding questions and answers to the program's database.
This allows developers to create quizzes on different topics and for different skill levels. The
program can also keep track of the user's score and provide feedback on their performance at the
end of the quiz.
Quiz can be taken from the comfort of your own home, eliminating the need for travel or
gathering in person. This is especially useful during times of social distancing or when
geography is a limiting factor.
Quiz can be taken at any time, making it easy to fit them into busy schedules. They can also be
designed to accommodate different time zones or availability.
quizzes can be a cost-effective way to test knowledge or provide training, as they eliminate the
need for physical materials and resources.
quizzes can be designed to be accessible to a wide range of users, including those with
disabilities or who require additional support.
REQUIREMENTS
2.3.1 Hardware Requirements
IMPLEMENTATION
package com.company;
public class Main {
public static void main(String[] args) {
new MainScreen();
}
}
package com.company;
import javax.swing.*;
public class MainScreen {
private JButton CUSTOMERButton;
private JButton ADMINButton;
private JPanel auctionPanel;
JFrame auctionF = new JFrame();
public MainScreen(){
auctionF.setContentPane(auctionPanel);
auctionF.pack();
auctionF.setVisible(true);
CUSTOMERButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Customer();
}
});
ADMINButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Admin();
}
});
}
}
package com.company;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.*;
import java.text.DateFormat;
import java.util.TimerTask;
import java.util.Vector;
public class Admin {
private JButton startButton;
private JLabel timerLabel;
private JPanel adminPanel;
private JButton ADDITEMButton;
private JTable table1;
private JTextField nameData;
private JTextField priceData;
private JTextField path;
private JButton SELECTIMAGEButton;
private JLabel imageLabel;
private JButton CLOSEButton;
public static String adminNameData="",adminPriceData="";
public static ImageIcon adminImageData;
JFrame adminF = new JFrame();
Timer timer;
public static int sec = 60;
public Admin() {
adminF.setContentPane(adminPanel);
adminF.pack();
tableData();
adminF.setVisible(true);
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
startTimer();
timer.start();
}
});
ADDITEMButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(nameData.getText().equals("")|| path.getText().equals("")|| priceData.getText().equals("")){
JOptionPane.showMessageDialog(null,"Please Fill All Fields to add Record.");
}else{
String sql = "insert into auction"+"(ITEM_NAME,IMAGE,PRICE)"+"values (?,?,?)";
try {
File f = new File(path.getText());
InputStream inputStream = new FileInputStream(f);
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root");
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1,nameData.getText());
statement.setBlob(2, inputStream);
statement.setString(3, priceData.getText());
statement.executeUpdate();
JOptionPane.showMessageDialog(null,"DETAILS ADDED SUCCESSFULLY");
nameData.setText("");
priceData.setText("");
imageLabel.setIcon(null);
path.setText("");
}catch (Exception ex){
JOptionPane.showMessageDialog(null,ex.getMessage());
}
tableData();
}
}
});
SELECTIMAGEButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.IMAGE","jpg","png");
fileChooser.addChoosableFileFilter(filter);
int rs = fileChooser.showSaveDialog(null);
if(rs==JFileChooser.APPROVE_OPTION){
File selectedImage = fileChooser.getSelectedFile();
path.setText(selectedImage.getAbsolutePath());
imageLabel.setIcon(resize(path.getText()));
}
}
});
table1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
DefaultTableModel dm = (DefaultTableModel)table1.getModel();
int selectedRow = table1.getSelectedRow();
adminNameData=dm.getValueAt(selectedRow,0).toString();
nameData.setText(adminNameData);
byte[] img = (byte[]) dm.getValueAt(selectedRow,1);
ImageIcon imageIcon = new ImageIcon(img);
Image im = imageIcon.getImage();
Image newimg = im.getScaledInstance(200,200,Image.SCALE_SMOOTH);
ImageIcon finalPic = new ImageIcon(newimg);
adminImageData = finalPic;
imageLabel.setIcon(adminImageData);
adminPriceData=dm.getValueAt(selectedRow,2).toString();
priceData.setText(adminPriceData);
}
});
CLOSEButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adminF.dispose();
}
});
}
public ImageIcon resize(String path){
ImageIcon myImg = new ImageIcon(path);
Image image = myImg.getImage();
Image newImage = image.getScaledInstance(200,200,Image.SCALE_SMOOTH);
ImageIcon finalImage = new ImageIcon(newImage);
return finalImage;
}
public void startTimer(){
timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
sec--;
if(sec==-1){
timer.stop();
tableData();
}
else if(sec>=0&&sec<10) timerLabel.setText("00:0"+sec);
else timerLabel.setText("00:"+ sec);
}
});
}
public void tableData() {
try{
String a= "Select* from auction";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(a);
table1.setModel(buildTableModel(rs));
}catch (Exception ex1){
JOptionPane.showMessageDialog(null,ex1.getMessage());
}
}
public static DefaultTableModel buildTableModel(ResultSet rs)
throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
// names of columns
Vector<String> columnNames = new Vector<String>();
int columnCount = metaData.getColumnCount();
for (int column = 1; column <= columnCount; column++) {
columnNames.add(metaData.getColumnName(column));
}
// data of the table
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while (rs.next()) {
Vector<Object> vector = new Vector<Object>();
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
vector.add(rs.getObject(columnIndex));
}
data.add(vector);
}
return new DefaultTableModel(data, columnNames);
}
}
package com.company;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;
public class Customer extends Admin {
private JLabel timerLabel;
private JPanel customPanel;
private JTable bidDetails;
private JTextField bidName;
private JTextField bidPrice;
private JButton ADDBIDButton;
private JLabel itemName;
private JLabel price;
private JLabel image;
private JButton close;
private String priceS="",name = "",bidder="";
private ImageIcon imageS;
private int bid;
Timer timer;
private static int sec;
JFrame customerF = new JFrame();
public Customer(){
customerF.setContentPane(customPanel);
customerF.pack();
customerF.setVisible(true);
sec = Admin.sec;
startTimer();
timer.start();
name = Admin.adminNameData;
priceS = Admin.adminPriceData;
imageS = Admin.adminImageData;
itemName.setText(name);
price.setText(priceS);
image.setIcon(imageS);
ADDBIDButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(bidName.getText().equals("")|| bidPrice.getText().equals("")){
JOptionPane.showMessageDialog(null,"Please Fill All Fields to add Record.");
}else{
try {
String sql = "insert into bid"+"(Bidder_Name,Bid)"+"values (?,?)";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root");
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1,bidName.getText());
statement.setInt(2, Integer.parseInt(bidPrice.getText()));
statement.executeUpdate();
JOptionPane.showMessageDialog(null,"ITEM ADDED SUCCESSFULLY");
bidName.setText("");
bidPrice.setText("");
}catch (Exception ex){
JOptionPane.showMessageDialog(null,ex.getMessage());
}
tableData();
}
}
});
close.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
customerF.dispose();
}
});
}
public void startTimer(){
timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(sec==60) timerLabel.setText("AUCTION NOT STARTED!");
else sec--;
if(sec==-1){
timer.stop();
String sql = "select * from bid where bid =(select max(bid) from bid)";
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
while (rs.next()){
bidder = rs.getString(1);
bid = rs.getInt(2);
}
String sql1 = "UPDATE auction " +
"SET BIDDER_NAME = '"+bidder+"'"+
",SOLD_AT= "+bid+
" WHERE ITEM_NAME= '"+name+"'";
String sql2= "delete from bid";
PreparedStatement preparedStatement = connection.prepareStatement(sql1);
preparedStatement.executeUpdate();
PreparedStatement preparedStatement1 = connection.prepareStatement(sql2);
preparedStatement1.executeUpdate();
JOptionPane.showMessageDialog(null,"ITEM:"+name+" SOLD TO "+bidder+" AT "+bid);
}catch (Exception e2){
JOptionPane.showMessageDialog(null,"some error");
}
tableData();
}
else if(sec>=0&&sec<10) timerLabel.setText("00:0"+sec);
else if(sec>10&&sec<60) timerLabel.setText("00:"+ sec);
}
});
}
public void tableData() {
try{
String a= "Select* from bid";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(a);
bidDetails.setModel(buildTableModel(rs));
}catch (Exception ex1){
JOptionPane.showMessageDialog(null,ex1.getMessage());
}
}
public static DefaultTableModel buildTableModel(ResultSet rs)
throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
// names of columns
Vector<String> columnNames = new Vector<String>();
int columnCount = metaData.getColumnCount();
for (int column = 1; column <= columnCount; column++) {
columnNames.add(metaData.getColumnName(column));
}
// data of the table
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while (rs.next()) {
Vector<Object> vector = new Vector<Object>();
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
vector.add(rs.getObject(columnIndex));
}
data.add(vector);
}
return new DefaultTableModel(data, columnNames);
}
}
OUTPUT SCREENS:
CONCLUSION
an online auction system using Java can be a highly effective and efficient way to conduct
auctions over the internet. Java is a versatile programming language that offers a wide range of
tools and features that can be utilized to create a robust and secure online auction system.
One of the main advantages of using Java for online auction systems is its ability to provide a
robust and scalable solution. Java's object-oriented approach allows for the creation of modular
and reusable components that can be easily extended and modified as the system evolves.
Additionally, Java's platform independence and compatibility with different operating systems
make it an ideal choice for building cross-platform applications
the use of Java, it is possible to create a secure and reliable system that can handle large volumes
of data and support various features such as bidding, item categorization, and user authentication.
an online auction system using Java can provide a convenient and accessible platform for
individuals and businesses to participate in auctions from anywhere in the world.
The system can be designed to allow for the creation and management of auctions, bidding by
users, and the processing of payments. Additionally, features such as secure login, real-time
updates on the bidding process, and email notifications can be incorporated to enhance the user
experience