Java GUI Book and Employee Management
Java GUI Book and Employee Management
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;
}
[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;
//}
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;
}
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);
add(l1);
add(f1);
add(l2);
add(f2);
add(l3);
add(f3);
add(b1);
add(b2);
add(ta);
[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);
}
//17th question
import [Link].*;
import [Link].*;
import [Link].*;
class Student
{
String name;
int registerNumber;
int totalScore;
int noofQuizzes;
double average;
class QuizManagement {
private ArrayList<Student> al = new ArrayList<>();
private int currentIndex = -1;
public QuizManagementSystemGUI() {
JFrame frame = new JFrame("Quiz Management System");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](500, 400);
[Link](true);
if ([Link]()) {
[Link](null, "Please enter a register number for search",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (obj != null) {
[Link]("Average: " + [Link]);
} else {
[Link]("Student not found");
}
}
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]());
}
}
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");
}
}
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");
[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:");
add(nameField);
add(idField);
add(matchCountField);
add(runsWicketsField);
add(playerDetailsTextArea);
add(addButton);
add(searchButton);
add(top3PlayerButton);
add(playerDetailsTextArea);
// Interface Bank
interface Bank {
void deposit(double amount) throws InvalidAmountException;
double checkBalance();
}
// Constructor
Customer(String customerName, int accountNumber, double balance) {
[Link] = customerName;
[Link] = accountNumber;
[Link] = balance;
}
@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;
}
// GUI components
private JFrame frame;
private JTextField nameField, accountField, amountField;
private JTextArea displayArea;
// Constructor
public BankDemoGUI2() {
initialize();
}
[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();
}
});
}
}
}
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");
}
} 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].*;
TitleThread(JLabel moveLabel) {
[Link] = moveLabel;
t = new Thread(this,"thread haha");
}
} catch(InterruptedException e) {
return;
}
}
}
}
StudentDetails() {
//create moving title label
title = new JLabel("Welcome to online program!");
[Link](new Font("Times New Roman",[Link],22));
//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(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);
}
try {
//validate inputs
if([Link]().length() != 10) {
throw new InvalidInput("Phone number must be 10 digits");
}
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(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;
}
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();
}
}