[Go to site: main page, start]

0% found this document useful (0 votes)
13 views57 pages

Java GUI Book and Employee Management

The document contains Java code for three different GUI applications: a book management system, an employee management system, and a quiz management system. Each application uses Swing components to create a user interface, allowing users to input data and view details about books, employees, or students. The code includes classes for managing data, handling user actions, and displaying information in text areas.
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)
13 views57 pages

Java GUI Book and Employee Management

The document contains Java code for three different GUI applications: a book management system, an employee management system, and a quiz management system. Each application uses Swing components to create a user interface, allowing users to input data and view details about books, employees, or students. The code includes classes for managing data, handling user actions, and displaying information in text areas.
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

//20

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
class Book
{
public String isbnnumber;
public String booktitle;
public String authorname;
public int numberofcopies;
Book(String isbnnumber,String booktitle,String authorname,int numberofcopies)
{
[Link]=isbnnumber;
[Link]=booktitle;
[Link]=authorname;
[Link]=numberofcopies;
}

public String getisbn()


{
return isbnnumber;
}
public String gettitle()
{
return booktitle;
}
public String getauthname()
{
return authorname;
}
public int getnumberofcopies()
{
return numberofcopies;
}
}
class Trail extends JFrame
{
JLabel l1,l2,l3,l4;
JTextField f1,f2,f3,f4;
JButton b1,b2;
JTextArea ta;
ArrayList<Book> bookList;
Trail()
{
setSize(700,700);
setVisible(true);
setLayout(null);
//setLayout(new FlowLayout());
b1=new JButton("SUBMIT");
[Link](100,250,100,20);
b2=new JButton("DETAILS");
[Link](100,300,100,20);
l1=new JLabel("ISBN Number");
[Link](50,50,100,20);
f1=new JTextField();
[Link](150,50,100,20);
l2=new JLabel("Book Title");
[Link](50,100,100,20);
f2=new JTextField();
[Link](150,100,100,20);
l3=new JLabel("Author Name");
[Link](50,150,100,20);
f3=new JTextField();
[Link](150,150,100,20);
l4=new JLabel("Number of copies");
[Link](50,200,100,20);
f4=new JTextField();
[Link](150,200,100,20);
ta=new JTextArea();
[Link](200,350,500,500);
add(l1);
add(f1);
add(l2);
add(f2);
add(l3);
add(f3);
add(l4);
add(f4);
add(b1);
add(b2);
add(ta);
bookList=new ArrayList<>();

[Link](new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try
{
int count=[Link]([Link]());
Book nb=new
Book([Link](),[Link](),[Link](),count);
[Link](nb);
[Link]("");
[Link]("");
[Link]("");
[Link]("");
}
catch(NumberFormatException ep)
{
[Link]([Link], "Number
of copies must be a numeric value");

}
}
});
[Link](new ActionListener(){
public void actionPerformed(ActionEvent e)
{
[Link]("");
for(Book book:bookList)
{
[Link]("ISBN number : "+[Link]()+ "\n");
[Link]("title "+[Link]()+ "\n");
[Link]("Author : "+[Link]() +"\n");
[Link](" copies : "+[Link]()+ "\
n");
}
}
});

}
public static void main(String args[])
{
new Trail();
}
}

//19
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

class Employee {
//private String name;
private String designation;
private String department;
private double basicSalary;

// Constructor
//public Employee(String name, String designation, String department, double basicSalary)
{
public Employee(String designation, String department, double basicSalary) {

// [Link] = name;
[Link] = designation;
[Link] = department;
[Link] = basicSalary;
}

// Getter methods
// public String getName() {
// return name;
//}

public String getDesignation() {


return designation;
}

public String getDepartment() {


return department;
}

public double getBasicSalary() {


return basicSalary;
}

// Method to calculate gross salary based on designation


public double calculateGrossSalary() {
double hraPercentage, daPercentage;

if ([Link]("Manager")) {
hraPercentage = 0.20;
daPercentage = 0.25;
} else if ([Link]("Accountant")) {
hraPercentage = 0.10;
daPercentage = 0.15;
} else {
hraPercentage = 0.10;
daPercentage = 0.10;
}

double hra = basicSalary * hraPercentage;


double da = basicSalary * daPercentage;

return basicSalary + hra + da;


}
}
class SFrame extends JFrame {
JLabel l1, l2, l3, l4;
JTextField f1, f2, f3;
JButton b1, b2;
JTextArea ta;
ArrayList<Employee> employeeList;

SFrame() {
setSize(700, 700);
setVisible(true);
setLayout(null);

b1 = new JButton("SUBMIT");
[Link](100, 250, 100, 20);
b2 = new JButton("DETAILS");
[Link](100, 300, 100, 20);

l1 = new JLabel("Designation");
[Link](50, 50, 100, 20);
f1 = new JTextField();
[Link](150, 50, 100, 20);

l2 = new JLabel("Department");
[Link](50, 100, 100, 20);
f2 = new JTextField();
[Link](150, 100, 100, 20);

l3 = new JLabel("Basic Salary");


[Link](50, 150, 100, 20);
f3 = new JTextField();
[Link](150, 150, 100, 20);
ta = new JTextArea();
[Link](200, 350, 500, 500);

add(l1);
add(f1);
add(l2);
add(f2);
add(l3);
add(f3);
add(b1);
add(b2);
add(ta);

employeeList = new ArrayList<>();

[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
double basicSalary = [Link]([Link]());
Employee newEmployee = new Employee([Link](), [Link](),
basicSalary);
[Link](newEmployee);

[Link]("");
[Link]("");
[Link]("");
} catch (NumberFormatException ex) {
[Link]([Link], "Basic Salary must be a numeric
value");
}
}
});
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link]("");
for (Employee employee : employeeList) {
//[Link]("Name: " + [Link]() + "\n");
[Link]("Designation: " + [Link]() + "\n");
[Link]("Department: " + [Link]() + "\n");
[Link]("Basic Salary: " + [Link]() + "\n");
[Link]("Gross Salary: " + [Link]() + "\n\n");
}
}
});

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String args[]) {


new SFrame();
}
}

//17th question

import [Link].*;
import [Link].*;
import [Link].*;

class NullFieldException extends Exception


{
NullFieldException(String message)
{
super(message);
}
}

class Student
{
String name;
int registerNumber;
int totalScore;
int noofQuizzes;
double average;

public Student(String name, int registerNumber, int totalScore, int noofQuizzes) {


[Link] = name;
[Link] = registerNumber;
[Link] = totalScore;
[Link] = noofQuizzes;
[Link] = (double) totalScore / noofQuizzes;
}
}

class QuizManagement {
private ArrayList<Student> al = new ArrayList<>();
private int currentIndex = -1;

public void addStudent(Student obj) {


[Link](obj);
}

public Student searchStudent(int registerNumber) {


for (Student obj : al) {
if ([Link] == registerNumber) {
return obj;
}
}
return null;
}

public void moveFirst() {


if (![Link]()) {
currentIndex = 0;
}
}

public void movePrevious() {


if (![Link]() && currentIndex > 0) {
currentIndex--;
}
}

public void moveNext() {


if (![Link]() && currentIndex < [Link]() - 1) {
currentIndex++;
}
}

public void moveLast() {


if (![Link]()) {
currentIndex = [Link]() - 1;
}
}

public Student getCurrentStudent() {


if (currentIndex >= 0 && currentIndex < [Link]()) {
return [Link](currentIndex);
}
return null;
}

public ArrayList<Student> getal() {


return al;
}
}

public class QuizManagementSystemGUI {


private JTextField nameField, registerNumberField, totalScoreField, noofQuizzesField;
private JTextArea displayArea;
private QuizManagement quizManagement;

public QuizManagementSystemGUI() {
JFrame frame = new JFrame("Quiz Management System");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 400);

JPanel panel = new JPanel();


[Link](panel);
placeComponents(panel);

[Link](true);

quizManagement = new QuizManagement();


// Initialize the arraylist with 5 records for testing
[Link](new Student("John", 1, 80, 2));
[Link](new Student("Alice", 2, 90, 3));
[Link](new Student("Bob", 3, 75, 2));
[Link](new Student("Eve", 4, 95, 3));
[Link](new Student("Charlie", 5, 85, 2));
}

private void placeComponents(JPanel panel) {


[Link](null);

JLabel nameLabel = new JLabel("Name:");


[Link](10, 20, 80, 25);
[Link](nameLabel);

nameField = new JTextField(20);


[Link](100, 20, 165, 25);
[Link](nameField);

JLabel registerNumberLabel = new JLabel("Register Number:");


[Link](10, 50, 150, 25);
[Link](registerNumberLabel);

registerNumberField = new JTextField(10);


[Link](150, 50, 115, 25);
[Link](registerNumberField);

JLabel totalScoreLabel = new JLabel("Total Score:");


[Link](10, 80, 80, 25);
[Link](totalScoreLabel);

totalScoreField = new JTextField(5);


[Link](100, 80, 80, 25);
[Link](totalScoreField);

JLabel noofQuizzesLabel = new JLabel("Number of Quizzes:");


[Link](10, 110, 150, 25);
[Link](noofQuizzesLabel);

noofQuizzesField = new JTextField(5);


[Link](150, 110, 80, 25);
[Link](noofQuizzesField);

JButton addButton = new JButton("Add");


[Link](10, 140, 80, 25);
[Link]
+(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
addStudent();
clearFields();
displayal();
} catch (NullFieldException ex) {
[Link](null, [Link](), "Error",
JOptionPane.ERROR_MESSAGE);
}
}
});
[Link](addButton);

JButton searchButton = new JButton("Search");


[Link](100, 140, 80, 25);
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
searchStudent();
}
});
[Link](searchButton);

JButton displayButton = new JButton("Display");


[Link](190, 140, 80, 25);
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
displayal();
}
});
[Link](displayButton);

JButton moveFirstButton = new JButton("MoveFirst");


[Link](280, 140, 100, 25);
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
moveFirst();
}
});
[Link](moveFirstButton);

JButton movePreviousButton = new JButton("MovePrevious");


[Link](390, 140, 120, 25);
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
movePrevious();
}
});
[Link](movePreviousButton);
JButton moveNextButton = new JButton("MoveNext");
[Link](10, 170, 100, 25);
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
moveNext();
}
});
[Link](moveNextButton);

JButton moveLastButton = new JButton("MoveLast");


[Link](120, 170, 100, 25);
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
moveLast();
}
});
[Link](moveLastButton);

displayArea = new JTextArea();


[Link](10, 200, 450, 150);
[Link](displayArea);
}

private void addStudent() throws NullFieldException {


String name = [Link]();
String registerNumberStr = [Link]();
String totalScoreStr = [Link]();
String noofQuizzesStr = [Link]();
if ([Link]() || [Link]() || [Link]() ||
[Link]()) {
throw new NullFieldException("All fields must be filled");
}

int registerNumber = [Link](registerNumberStr);


int totalScore = [Link](totalScoreStr);
int noofQuizzes = [Link](noofQuizzesStr);

Student obj = new Student(name, registerNumber, totalScore, noofQuizzes);


[Link](obj);
}

private void searchStudent() {


String registerNumberStr = [Link]();

if ([Link]()) {
[Link](null, "Please enter a register number for search",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}

int registerNumber = [Link](registerNumberStr);


Student obj = [Link](registerNumber);

if (obj != null) {
[Link]("Average: " + [Link]);
} else {
[Link]("Student not found");
}
}

private void displayal() {


ArrayList<Student> al = [Link]();

if ([Link]()) {
[Link]("No al in the list");
} else {
StringBuilder output = new StringBuilder();
for (Student obj : al) {
[Link]("Name: ").append([Link]).append(", Register Number:
").append([Link])
.append(", Total Score: ").append([Link]).append(", No of Quizzes:
").append([Link])
.append(", Average: ").append([Link]).append("\n");
}
[Link]([Link]());
}
}

private void moveFirst() {


[Link]();
displayCurrentStudent();
}

private void movePrevious() {


[Link]();
displayCurrentStudent();
}

private void moveNext() {


[Link]();
displayCurrentStudent();
}

private void moveLast() {


[Link]();
displayCurrentStudent();
}

private void displayCurrentStudent() {


Student currentStudent = [Link]();

if (currentStudent != null) {
[Link]("Name: " + [Link] + ", Register Number: " +
[Link]
+ ", Total Score: " + [Link] + ", No of Quizzes: " +
[Link]
+ ", Average: " + [Link]);
} else {
[Link]("No al in the list");
}
}

private void clearFields() {


[Link]("");
[Link]("");
[Link]("");
[Link]("");
}

public static void main(String[] args) {

new QuizManagementSystemGUI();
}

}
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

class Compliments
{
int coke200ml;
int sprite500ml;
}
class Pizza extends Compliments
{
int[] type;
}
class Customer
{
int id;
String name;
String address;
double amount;
Pizza pizza;
public Customer(int id, String name, String address, Pizza pizza)
{
[Link] = id;
[Link] = name;
[Link] = address;
[Link] = pizza;
}
// Override the equals method in the Customer class
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null || getClass() != [Link]())
return false;
Customer customer = (Customer) obj;
return id == [Link];
}
}
public class PizzaOrderGUI extends JFrame
{
ArrayList<Customer> customerList = new ArrayList<>();
JTextArea textArea1, textArea2;
JTextField idField, nameField, addressField;
JList<String> pizzaList;
JTextField[] quantityFields;

public PizzaOrderGUI()
{
setTitle("Pizza Order System");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
// Add your pizza names and prices to the pizzaData array
String[] pizzaData = {"Paneer 50", "Margherita 40", "Pepperoni 60"};
JLabel pizzaLabel = new JLabel("Select Pizza:");
[Link](10, 10, 100, 20);
add(pizzaLabel);
pizzaList = new JList<>(pizzaData);
[Link](120, 10, 150, 100);
add(pizzaList);
JLabel quantityLabel = new JLabel("Quantity:");
[Link](10, 120, 100, 20);
add(quantityLabel);
quantityFields = new JTextField[[Link]];
for (int i = 0; i < [Link]; i++)
{
quantityFields[i] = new JTextField(10);
quantityFields[i].setBounds(120, 120 + i * 30, 50, 20);
add(quantityFields[i]);
}
JLabel idLabel = new JLabel("Customer ID:");
[Link](10, 250, 100, 20);
add(idLabel);
idField = new JTextField(20);
[Link](120, 250, 150, 20);
add(idField);
JLabel nameLabel = new JLabel("Customer Name:");
[Link](10, 280, 120, 20);
add(nameLabel);
nameField = new JTextField(20);
[Link](120, 280, 150, 20);
add(nameField);
JLabel addressLabel = new JLabel("Customer Address:");
[Link](10, 310, 150, 20);
add(addressLabel);
addressField = new JTextField(20);
[Link](120, 310, 150, 20);
add(addressField);
textArea1 = new JTextArea(10, 30);
[Link](10, 340, 300, 150);
//add(new JScrollPane(textArea1));
textArea2 = new JTextArea(4, 30);
[Link](320, 10, 300, 150);
//add(new JScrollPane(textArea2));
textArea1 = new JTextArea(10, 30);
[Link](10, 340, 300, 150);
add(textArea1); // Add this line to set the bounds for textArea1
textArea2 = new JTextArea(4, 30);
[Link](320, 170, 300, 150);
add(textArea2); // Add this line to set the bounds for textArea2
JButton orderButton = new JButton("Place an order");
[Link](320, 330, 150, 30);
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
placeOrder();
}
catch (Exception ex)
{
[Link]([Link]());
}
}
});
add(orderButton);
JButton historyButton = new JButton("History");
[Link](480, 330, 150, 30);
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
showHistory();
}
catch (Exception ex)
{
[Link]([Link]());
}
}
});
add(historyButton);
//pack(); // Adjusts the frame size based on added components
//setLocationRelativeTo(null); // Centers the frame on the screen
setVisible(true);
setSize(900,900);
}
private void placeOrder() throws Exception
{
int customerId;
String customerName, customerAddress;

try
{
customerId = [Link]([Link]());
customerName = [Link]();
customerAddress = [Link]();
}
catch (NumberFormatException e)
{
throw new Exception("Enter valid customer details");
}
Pizza pizza = new Pizza();
[Link] = new int[[Link]];
double totalAmount = 0;
for (int i = 0; i < [Link]; i++)
{
try
{
int quantity = [Link](quantityFields[i].getText());
if (quantity > 0)
{
[Link][i] = quantity;
// Add your pizza prices here
totalAmount += quantity * getPizzaPrice(i);
}
}
catch (NumberFormatException e)
{
throw new Exception("Enter quantity for selected items");
}
}
if (totalAmount == 0)
{
throw new Exception("Select an item first");
}
pizza.coke200ml = calculateCompliment(totalAmount, 500, 1000);
pizza.sprite500ml = calculateCompliment(totalAmount, 1000, 1500);
Customer customer = new Customer(customerId, customerName, customerAddress,
pizza);
[Link] = totalAmount;
int existingCustomerIndex = [Link](customer);
if (existingCustomerIndex != -1)
{
// Update existing customer
Customer existingCustomer = [Link](existingCustomerIndex);
[Link] += [Link];
for (int i = 0; i < [Link]; i++)
{
[Link][i] += [Link][i];
}
[Link].coke200ml += pizza.coke200ml;
[Link].sprite500ml += pizza.sprite500ml;
}
else
{
// Add new customer
[Link](customer);
}

displayOrderDetails(customer);
}
private void showHistory()
{
StringBuilder historyText = new StringBuilder("Order History:\n");

for (Customer customer : customerList)


{
[Link]("Customer ID: ").append([Link]).append(", ");
[Link]("Name: ").append([Link]).append(", ");
[Link]("Amount: Rs").append([Link]).append("\n");
}

[Link]([Link]());
}
private void displayOrderDetails(Customer customer)
{
[Link]("Customer ID: " + [Link] + "\n");
[Link]("Name: " + [Link] + "\n");
[Link]("Address: " + [Link] + "\n");
[Link]("Purchased Items:\n");
for (int i = 0; i < [Link]; i++)
{
if ([Link][i] > 0)
{
[Link](" " + getPizzaName(i) + ": " + [Link][i] + "\n");
}
}
[Link]("Complimentary Coke (200ml): " + [Link].coke200ml + "\n");
[Link]("Complimentary Sprite (500ml): " + [Link].sprite500ml + "\n");
[Link]("Total Amount: Rs" + [Link] + "\n");
// Set history in textArea2
StringBuilder historyText = new StringBuilder("Order History:\n");
for (Customer c : customerList)
{
[Link]("Customer ID: ").append([Link]).append(", Amount:
Rs").append([Link]).append("\n");
}
[Link]([Link]());
}
private double getPizzaPrice(int index)
{
// Add your pizza prices here
double[] pizzaPrices = {50, 40, 60};
return pizzaPrices[index];
}
private String getPizzaName(int index)
{
// Add your pizza names here
String[] pizzaNames = {"Paneer", "Margherita", "Pepperoni"};
return pizzaNames[index];
}
private int calculateCompliment(double totalAmount, double lowerLimit, double
upperLimit)
{
if (totalAmount > lowerLimit && totalAmount <= upperLimit)
{
return 1;
}
else if (totalAmount > upperLimit)
{
return 2;
}
else
{
return 0;
}
}
public static void main(String[] args)
{
new PizzaOrderGUI();
}
}

import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
// Custom Exception for incomplete details
class IncompleteDetailsException extends Exception {
public IncompleteDetailsException(String message) {
super(message);
}
}
// Person class
class Person {
String name;
int matchCount;
int id;
public Person(String name, int matchCount, int id) {
[Link] = name;
[Link] = matchCount;
[Link] = id;
}
}
// Batsman class derived from Person
class Batsman extends Person {
int totalRuns;
public Batsman(String name, int matchCount, int id, int totalRuns) {
super(name, matchCount, id);
[Link] = totalRuns;
}
// Calculate striking rate
public double getStrikingRate() {
return (double) totalRuns / matchCount;
}
}
// Bowler class derived from Person
class Bowler extends Person {
int wicketCount;
public Bowler(String name, int matchCount, int id, int wicketCount) {
super(name, matchCount, id);
[Link] = wicketCount;
}
// Getter for wicket count
public int getWicketCount() {
return wicketCount;
}
}
// GUI class
public class CricketProfileGUI extends JFrame {
private JRadioButton batsmanRadioButton, bowlerRadioButton;
private JTextField nameField, idField, matchCountField, runsWicketsField;
private JTextArea playerDetailsTextArea;
private JButton addButton, searchButton, top3PlayerButton;
private ArrayList<Batsman> batsmenList = new ArrayList<>();
private ArrayList<Bowler> bowlersList = new ArrayList<>();
public CricketProfileGUI() {
setTitle("Cricket Profile");
setLayout(null);
// Initialize Swing components and setBounds
JLabel nameLabel = new JLabel("Name:");
JLabel idLabel = new JLabel("ID:");
JLabel matchCountLabel = new JLabel("Match Count:");
JLabel runsWicketsLabel = new JLabel("Runs/Wickets:");

batsmanRadioButton = new JRadioButton("Batsman");


bowlerRadioButton = new JRadioButton("Bowler");
nameField = new JTextField();
idField = new JTextField();
matchCountField = new JTextField();
runsWicketsField = new JTextField();
playerDetailsTextArea = new JTextArea();
[Link](false);
addButton = new JButton("Add");
searchButton = new JButton("Search");
top3PlayerButton = new JButton("Top 3 Players");
// Set bounds for components
[Link](20, 20, 100, 30);
[Link](120, 20, 100, 30);

// Set bounds for labels on the left


[Link](20, 60, 150, 30);
[Link](20, 100, 150, 30);
[Link](20, 140, 150, 30);
[Link](20, 180, 150, 30);

// Set bounds for text fields on the right


[Link](180, 60, 150, 30);
[Link](180, 100, 150, 30);
[Link](180, 140, 150, 30);
[Link](180, 180, 150, 30);

// Set bounds for buttons


[Link](20, 220, 100, 30);
[Link](130, 220, 100, 30);
[Link](240, 220, 150, 30);

// Set bounds for text area


[Link](20, 260, 370, 150);

// Add components to the JFrame


add(batsmanRadioButton);
add(bowlerRadioButton);
add(nameLabel);
add(idLabel);
add(matchCountLabel);
add(runsWicketsLabel);

add(nameField);
add(idField);
add(matchCountField);
add(runsWicketsField);

add(playerDetailsTextArea);
add(addButton);
add(searchButton);
add(top3PlayerButton);
add(playerDetailsTextArea);

// Add ActionListener for the "Add" button


[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
// Get input from text fields
String name = [Link]();
int id = [Link]([Link]());
int matchCount = [Link]([Link]());
int runsWickets = [Link]([Link]());
// Check if all fields are filled
if ([Link]() || [Link]().isEmpty() ||
[Link]().isEmpty()
|| [Link]().isEmpty()) {
throw new IncompleteDetailsException("All fields are required.");
}
// Check if it's a Batsman or Bowler
if ([Link]()) {
Batsman batsman = new Batsman(name, matchCount, id, runsWickets);
[Link](batsman);
} else if ([Link]()) {
Bowler bowler = new Bowler(name, matchCount, id, runsWickets);
[Link](bowler);
}
// Clear text fields after adding
clearFields();
showMessage("Player added successfully.");
} catch (NumberFormatException ex) {
showMessage("Invalid input for match count or runs/wickets.");
} catch (IncompleteDetailsException ex) {
showMessage([Link]());
}
}
});
// Add ActionListener for the "Search" button
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int searchId = [Link]([Link]());
// Search in both batsmen and bowlers lists
for (Batsman batsman : batsmenList) {
if ([Link] == searchId) {
showPlayerDetails(batsman);
return;
}
}
for (Bowler bowler : bowlersList) {
if ([Link] == searchId) {
showPlayerDetails(bowler);
return;
}
}
showMessage("Player with ID " + searchId + " not found.");
}
});
// Add ActionListener for the "Top3Player" button
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Sort batsmen based on striking rate
[Link](batsmenList,
[Link](Batsman::getStrikingRate).reversed());
// Display top 3 batsmen
showTopPlayers("Top 3 Batsmen:", batsmenList);
// Sort bowlers based on wicket count
[Link](bowlersList,
[Link](Bowler::getWicketCount).reversed());
// Display top 3 bowlers
showTopPlayers("Top 3 Bowlers:", bowlersList);
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(900,900);
setVisible(true);
}
private void clearFields() {
// Clear text fields
[Link]("");
[Link]("");
[Link]("");
[Link]("");
}
private void showMessage(String message) {
// Display messages in the text area
[Link](message);
}
private void showPlayerDetails(Person person) {
// Display player details in the text area
[Link]("Name: " + [Link] + "\nID: " + [Link] +
"\nMatch Count: " + [Link]);
}
private void showTopPlayers(String title, ArrayList<? extends Person> playersList) {
// Display top players in the text area
StringBuilder topPlayers = new StringBuilder(title + "\n");
int count = [Link](3, [Link]());
for (int i = 0; i < count; i++) {
Person player = [Link](i);
[Link](i + 1).append(". ").append([Link]).append("\n");
}
// Append the top players' information to the existing text
[Link]([Link]());
}

public static void main(String[] args) {


[Link](new Runnable() {
@Override
public void run() {
new CricketProfileGUI();
}
});
}
}
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

// Custom exception for invalid deposit amount


class InvalidAmountException extends Exception {
InvalidAmountException(String message) {
super(message);
}
}

// Custom exception for insufficient funds


class InsufficientFundException extends Exception {
InsufficientFundException(String message) {
super(message);
}
}

// Interface Bank
interface Bank {
void deposit(double amount) throws InvalidAmountException;

void withdrawal(double amount) throws InsufficientFundException;

double checkBalance();
}

// Customer class implementing Bank interface


class Customer implements Bank {
private String customerName;
private int accountNumber;
private double balance;

// Constructor
Customer(String customerName, int accountNumber, double balance) {
[Link] = customerName;
[Link] = accountNumber;
[Link] = balance;
}

// Implementing methods from Bank interface


@Override
public void deposit(double amount) throws InvalidAmountException {
if (amount <= 0) {
throw new InvalidAmountException("Invalid deposit amount");
}
balance += amount;
}

@Override
public void withdrawal(double amount) throws InsufficientFundException {
if (amount <= 0 || amount > balance) {
throw new InsufficientFundException("Insufficient funds or invalid withdrawal
amount");
}
balance -= amount;
}

@Override
public double checkBalance() {
return balance;
}

// Getters
public String getCustomerName() {
return customerName;
}

public int getAccountNumber() {


return accountNumber;
}
}

// BankDemoGUI2 class with GUI


public class BankDemoGUI2 {
private ArrayList<Customer> customerList = new ArrayList<>();

// GUI components
private JFrame frame;
private JTextField nameField, accountField, amountField;
private JTextArea displayArea;

// Constructor
public BankDemoGUI2() {
initialize();
}

// Initialize the GUI

private void initialize() {


frame = new JFrame("Bank Application");
[Link](100, 100, 500, 350); // Adjusted frame size
[Link](JFrame.EXIT_ON_CLOSE);
[Link](null);

// GUI components with labels


JLabel nameLabel = new JLabel("Customer Name:");
[Link](20, 20, 100, 20);
[Link](nameLabel);

nameField = new JTextField();


[Link](130, 20, 120, 20);
[Link](nameField);

JLabel accountLabel = new JLabel("Account Number:");


[Link](20, 50, 100, 20);
[Link](accountLabel);

accountField = new JTextField();


[Link](130, 50, 120, 20);
[Link](accountField);

JLabel amountLabel = new JLabel("Amount:");


[Link](20, 80, 100, 20);
[Link](amountLabel);

amountField = new JTextField();


[Link](130, 80, 120, 20);
[Link](amountField);

displayArea = new JTextArea();


JScrollPane scrollPane = new JScrollPane(displayArea);
[Link](10, 110, 450, 120); // Adjusted width
[Link](scrollPane);
JButton addButton = new JButton("Add Customer");
[Link](10, 240, 120, 20);
[Link](addButton);

JButton depositButton = new JButton("Deposit");


[Link](140, 240, 80, 20);
[Link](depositButton);

JButton withdrawButton = new JButton("Withdrawal");


[Link](230, 240, 100, 20);
[Link](withdrawButton);

JButton checkBalanceButton = new JButton("Check Balance");


[Link](340, 240, 120, 20);
[Link](checkBalanceButton);

JButton displayButton = new JButton("Display");


[Link](10, 270, 120, 20);
[Link](displayButton);

// Action listeners for buttons


[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
addCustomer();
}
});

[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
deposit();
}
});

[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
withdrawal();
}
});

[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
checkBalance();
}
});

[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
display();
}
});
}

// Method to add a customer to the list


private void addCustomer() {
try {
String name = [Link]();
int accountNumber = [Link]([Link]());
double balance = 0; // initial balance
Customer customer = new Customer(name, accountNumber, balance);
[Link](customer);
[Link]("Customer added: " + [Link]() + "\n");
} catch (NumberFormatException e) {
[Link]("Invalid account number\n");
}
}

// Method to perform deposit operation


private void deposit() {
try {
double amount = [Link]([Link]());
Customer customer = getSelectedCustomer();
[Link](amount);
[Link]("Deposit successful. New balance: " + [Link]()
+ "\n");
} catch (NumberFormatException | InvalidAmountException e) {
[Link]("Invalid deposit amount\n");
}
}

// Method to perform withdrawal operation


private void withdrawal() {
try {
double amount = [Link]([Link]());
Customer customer = getSelectedCustomer();
[Link](amount);
[Link]("Withdrawal successful. New balance: " +
[Link]() + "\n");
} catch (NumberFormatException | InsufficientFundException e) {
[Link]("Invalid withdrawal amount or insufficient funds\n");
}
}
6
// Method to check balance
private void checkBalance() {
try {
int accountNumber = [Link]([Link]());
Customer customer = getCustomerByAccountNumber(accountNumber);
if (customer != null) {
[Link]("Balance for account " + accountNumber + ": " +
[Link]() + "\n");
} else {
[Link]("Customer not found\n");
}
} catch (NumberFormatException e) {
[Link]("Invalid account number\n");
}
}

// Method to display all customers


private void display() {
for (Customer customer : customerList) {
[Link]("Customer: " + [Link]() +
", Account Number: " + [Link]() +
", Balance: " + [Link]() + "\n");
}
}

// Helper method to get the selected customer from the list


private Customer getSelectedCustomer() {
int accountNumber = [Link]([Link]());
return getCustomerByAccountNumber(accountNumber);
}

// Helper method to get a customer by account number


private Customer getCustomerByAccountNumber(int accountNumber) {
for (Customer customer : customerList) {
if ([Link]() == accountNumber) {
return customer;
}
}
return null;
}

// Main method to run the application


public static void main(String[] args) {

BankDemoGUI2 window = new BankDemoGUI2();


[Link](true);

}
}

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
class TitleThread extends Thread{
Thread t;
JLabel moveLabel;

TitleThread(JLabel moveLabel) {
[Link] = moveLabel;
t = new Thread(this,"thread haha");
}

public void run() {


while(true) {
try {
[Link](100,50,550,50);
[Link](500);
[Link](300,50,550,50);
[Link](500);
[Link](500,50,550,50);
[Link](500);
[Link](700,50,550,50);
[Link](500);
[Link](900,50,550,50);
[Link](500);
[Link](1100,50,550,50);
[Link](500);

} catch(InterruptedException e) {
return;
}
}
}
}
class Student_Details extends JFrame
{
static JLabel title;
Student_Details()
{
title = new JLabel("Welcome to online program!");
add(title);
setSize(1800,800);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[]) {
new Student_Details();
Thread t = new TitleThread(title);
[Link]();
}

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;

class TitleThread extends Thread{


Thread t;
JLabel moveLabel;

TitleThread(JLabel moveLabel) {
[Link] = moveLabel;
t = new Thread(this,"thread haha");
}

public void run() {


while(true) {
try {
[Link](100,50,550,50);
[Link](700);
[Link](300,50,550,50);
[Link](700);
[Link](500,50,550,50);
[Link](700);
[Link](700,50,550,50);
[Link](700);
[Link](900,50,550,50);
[Link](700);
[Link](1100,50,550,50);
[Link](700);

} catch(InterruptedException e) {
return;
}
}
}
}

class InvalidInput extends Exception {


public InvalidInput(String msg)
{
super(msg);
}
}

class StudentDetails extends JFrame implements ActionListener {

static JLabel title,courseidLabel, courselevelLabel, nameLabel, mailLabel,


numberLabel, sub1Label, sub2Label, sub3Label, sub4Label, sub5Label,statusLabel;
JTextField nameField, mailField, numberField, sub1Field, sub2Field, sub3Field,
sub4Field, sub5Field, statusField;
JTextArea outputArea;
String courseIdString[] = {"101 BCA","201 MCA","301 BTechCse","401
MTechCse"};
JComboBox<String> courseidBox;
JRadioButton UGBtn, PGBtn;
JButton submitBtn;
ButtonGroup gp;

StudentDetails() {
//create moving title label
title = new JLabel("Welcome to online program!");
[Link](new Font("Times New Roman",[Link],22));

//create label object


courseidLabel = new JLabel("Enter course ID: ");
courselevelLabel = new JLabel("Select Course Level: ");
nameLabel = new JLabel("Applicant Name: ");
mailLabel = new JLabel("Email ID: ");
numberLabel = new JLabel("Mobile Number: ");
sub1Label = new JLabel("Enter Subject 1 Marks:");
sub2Label = new JLabel("Enter Subject 2 Marks");
sub3Label = new JLabel("Enter Subject 3 Marks");
sub4Label = new JLabel("Enter Subject 4 Marks");
sub5Label = new JLabel("Enter Subject 5 Marks");
statusLabel = new JLabel("Status");

//Labels on left side of frame


[Link](100,150,150,20);
[Link](100,250,150,20);
[Link](100,350,150,20);
[Link](100,450,150,20);
[Link](100,550,150,20);
[Link](100,650,150,20);
//Labels on right side of frame
[Link](600,150,170,20);
[Link](600,250,170,20);
[Link](600,350,170,20);
[Link](600,450,170,20);
[Link](600,550,170,20);
nameField = new JTextField();
mailField = new JTextField();
numberField = new JTextField();
statusField = new JTextField();
sub1Field = new JTextField();
sub2Field = new JTextField();
sub3Field = new JTextField();
sub4Field = new JTextField();
sub5Field = new JTextField();

//fields on left side of frame


[Link](250,350,150,20);
[Link](250,450,150,20);
[Link](250,550,150,20);
[Link](250,650,150,20);
[Link](false);
//fields on right side of frame
[Link](800,150,150,20);
[Link](800,250,150,20);
[Link](800,350,150,20);
[Link](800,450,150,20);
[Link](800,550,150,20);

//create text area


outputArea = new JTextArea();
[Link](false);
[Link](new Font("Times New Roman",[Link],17));
[Link](1000,150,600,400);

//make combobox
courseidBox = new JComboBox<String>(courseIdString);
[Link](250,150,150,20);
//make button and add to group
UGBtn = new JRadioButton("Undergraduate");
PGBtn = new JRadioButton("Postgraduate");
[Link](250,250,150,20);
[Link](250,290,150,20);
gp = new ButtonGroup();
[Link](UGBtn); [Link](PGBtn);

//make button
submitBtn = new JButton("SUBMIT");
[Link](600,650,100,50);
[Link](this);

//add everything to frame


add(courseidLabel); add(courselevelLabel); add(nameLabel); add(mailLabel);
add(numberLabel); add(courseidBox); add(UGBtn); add(PGBtn);
add(nameField);
add(mailField); add(numberField); add(title); add(outputArea);
add(submitBtn); add(statusLabel); add(statusField);

add(sub1Label);add(sub2Label);add(sub3Label);add(sub4Label);add(sub5Label);

add(sub1Field);add(sub2Field);add(sub3Field);add(sub4Field);add(sub5Field);

setSize(1800,800);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {


String output = "";

try {
//validate inputs
if([Link]().length() != 10) {
throw new InvalidInput("Phone number must be 10 digits");
}

if([Link]().length() > 50) {


throw new InvalidInput("Name should be less than 50
charecters");
}

output += "Course ID: " +


[Link]([Link]()) + "\n";
if([Link]())
output += "Course Level: Undergraduate\n";
else
output += "Course Level: Postgraduate\n";

output += "Name: " + [Link]() + "\n";


output += "Email: " + [Link]() + "\n";
output += "Number: " + [Link]() + "\n";
output += "-----------------\n\n";
output += "Subject Marks\n";

JTextField subjects[] =
{sub1Field,sub2Field,sub3Field,sub4Field,sub5Field};
//go through all subject marks and check for invalid input
//if no invalid input, add to output string
boolean userApplied = true;
for(JTextField subject: subjects) {
if( [Link]([Link]()) <= 0) {
throw new InvalidInput("Marks must be greater than
0");
}

if( [Link]([Link]()) < 50) {


userApplied = false;
}

output += [Link]() + "\n";


}

if(userApplied)
[Link]("APPLIED");
else
[Link]("NOT APPLIED");

[Link](output);

} catch(InvalidInput ex) {

[Link](null,[Link]());
//better solution to display exception
//[Link]([Link]()); // this is given in the
question uncomment above line and use
return;
}

public static void main(String args[]) {


new 0();
Thread t = new TitleThread(title);
[Link]();
}
}

import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
class InvalidInput extends Exception
{
public InvalidInput(String msg)
{
super(msg);
}
}

class Beneficiary
{
int bd,pa,ca,noy;
}
class HomeLoan
{
ArrayList<Beneficiary> bene=new ArrayList<>();
public double eligibilityForSubsidy(int pa,int ca)
{
if(pa<3500000 && ca<30)
{
double pap=pa-260000;
return pap;
}
else
return pa;
}
public double calculateEMI(int pa,int noy)
{
double roi=0.074;
double interest=pa*noy*roi;
double EMI=(pa+interest)/(noy*12);
return EMI;
}
}
class devil extends JFrame
{
JLabel bdL,paL,caL,noyL;
JTextField bdt,pat,cat,noyt;
JButton submit,display;
JTextArea ta;
HomeLoan home =new HomeLoan();

devil()
{
setSize(1000,600);
setLayout(null);
setVisible(true);
bdL=new JLabel("beneficiaryID");
[Link](15,50,100,20);
add(bdL);
paL=new JLabel("principal amount");
[Link](15,100,100,20);
add(paL);
caL=new JLabel("carpet area");
[Link](15,150,100,20);
add(caL);
noyL=new JLabel("[Link] years");
[Link](15,200,100,20);
add(noyL);
bdt=new JTextField();
[Link](150,50,100,20);
add(bdt);
pat=new JTextField();
[Link](150,100,100,20);
add(pat);
cat=new JTextField();
[Link](150,150,100,20);
add(cat);
noyt=new JTextField();
[Link](150,200,100,20);
add(noyt);
submit=new JButton("submit");
[Link](250,300,60,40);
add(submit);
display=new JButton("dispaly");
[Link](250,400,60,40);
add(display);
ta=new JTextArea();
[Link](500,500,800,400);
add(ta);
[Link](new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
Beneficiary b=new Beneficiary();
[Link]=[Link]([Link]());
[Link]=[Link]([Link]());
[Link]=[Link]([Link]());
try{
[Link]=[Link]([Link]());
if ([Link] > 15)
throw new InvalidInput("number of years should be greater than 15");
}catch(InvalidInput e)
{

[Link](null,[Link]());
return;
}
[Link](b);
}
});
[Link](new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
for(Beneficiary temp:[Link])
{
[Link]("beneficiaryID"+[Link]+"\n");
[Link]("principalammount"+[Link]+"\n");
[Link]("carpetarea"+[Link]+"\n");
[Link]("no of years"+[Link]+"\n");
[Link]("EMI"+[Link]([Link],[Link])+"\n");

[Link]("Subsidy"+[Link]([Link],[Link]));
}

}
});
}
public static void main(String args[])
{
new devil();
}
}

You might also like