0% found this document useful (0 votes)
7 views

IT HHW

The document provides a practical file for Information Technology homework, detailing the creation of a database named 'School' with a 'Students' table, including SQL commands for inserting records, updating, deleting, and querying data. It also includes Java GUI applications for various tasks such as calculating the sum of digits, checking if a number is positive and even, and calculating profit or loss based on user input. Additionally, it describes a book publishing application that calculates prices and discounts based on customer type.

Uploaded by

gaurigandhi2008
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)
7 views

IT HHW

The document provides a practical file for Information Technology homework, detailing the creation of a database named 'School' with a 'Students' table, including SQL commands for inserting records, updating, deleting, and querying data. It also includes Java GUI applications for various tasks such as calculating the sum of digits, checking if a number is positive and even, and calculating profit or loss based on user input. Additionally, it describes a book publishing application that calculates prices and discounts based on customer type.

Uploaded by

gaurigandhi2008
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
You are on page 1/ 12

INFORMATION TECHNOLOGY

PRACTICAL FILE
WINTER HOLIDAY HOMEWORK

1. Create a database named School. Inside it, create a


table Students with the following columns:
StudentID (Primary Key)
Name (Text)
Class (Integer)
Marks (Integer)
Solution:
To create a database named School and a table Students with the
required columns, use the following SQL commands:
-- Create the database
CREATE DATABASE School;

-- Use the database


USE School;

-- Create the Students table


CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Y Name VARCHAR(100),
Class INT,
Marks INT
);
Explanation:
• CREATE DATABASE School; → Creates a new
database named School.
• USE School; → Selects the School database to work in.
• CREATE TABLE Students (...); → Creates a Students
table with the following columns:
• StudentID (INT PRIMARY KEY) → Unique student
identification number.
• Name (VARCHAR(100)) → Stores student names (up to
100 characters).
• Class (INT) → Stores class numbers.
• Marks (INT) → Stores student marks.

StudentID Name Class Marks

2. Write SQL query to insert at least 5 records into the


student table.

Solution:

INSERT INTO Students (StudentID, Name, Class, Marks) VALUES


(101, ‘Anushka Tyagi’, 11, 85),
(102, ‘Anvesha Sharma’, 11, 92),
(103, ‘Sadiya’, 11, 72),
(104, ‘Somya Sharma’, 11, 37),
(105, ‘Sapna Gandhi’, 11, 95);

StudentID Name Class Marks


101 Anushka Tyagi 11 85
102 Anvesha Sharma 11 92
103 Sadiya 11 72
104 Somya Sharma 11 37
105 Sapna Gandhi 11 95

3. Write SQL queries to perform the following tasks on


the Students table:
a. Display the details of all students who scored above 80
marks.
b. Update the marks of a student with StudentID = 103 to
90.
c. Delete the record of a student whose marks are below
40.

Solution:

a) SQL Query to display details of all students who scored above 80


marks:

SELECT * FROM Students WHERE Marks > 80;


StudentID Name Class Marks
101 Anushka Tyagi 11 85
102 Anvesha Sharma 11 92
105 Sapna Gandhi 11 95

b) SQL Query to update the marks of a student with StudentID =


103 to 90:

UPDATE Students SET Marks = 90 WHERE StudentID = 103;

StudentID Name Class Marks


103 Sadiya 11 90

c) SQL Query to delete the record of a student whose marks are


below 40:
DELETE FROM Students WHERE Marks < 40;

StudentID Name Class Marks


101 Anushka Tyagi 11 85
102 Anvesha Sharma 11 92
103 Sadiya 11 90
105 Sapna Gandhi 11 95

4. Write a query to find the average marks scored by


students in the Students table.

Solution:

SELECT AVG(Marks) AS AverageMarks FROM Students;

This query calculates the average of the Marks column for all the
students in the table.

Average Marks
90.5

5. Write a query to group students based on their class


and display the number of students in each class.

Solution:

SELECT Class, COUNT(*) AS NumberOfStudents


FROM Students
GROUP BY Class;

Class Number of Students


11 04

6. Design a GUl application in which the user enters a


three digit number in the text field and on clicking the
button the sum of the digits of the number should be
displayed in a label.

Solution:

Description: The user enters a three-digit number, and on clicking the


button, the sum of the digits of the number is displayed in a label.

Java Code (GUI using Swing):

import javax.swing.*;

import java.awt.event.*;

public class SumOfDigits {

public static void main(String[] args) {

JFrame frame = new JFrame("Sum of Digits");

JTextField inputField = new JTextField(10);

JButton button = new JButton("Sum");

JLabel resultLabel = new JLabel("Sum: ");

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int number = Integer.parseInt(inputField.getText());

int sum = 0;

while (number != 0) {

sum += number % 10;

number /= 10;
}

resultLabel.setText("Sum: " + sum);

});

frame.setLayout(new java.awt.FlowLayout());

frame.add(inputField);

frame.add(button);

frame.add(resultLabel);

frame.setSize(300, 150);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

7. Design a GUI application to accept a number from the


user in a text field and print using option pane
whether it is a positive even number or not

Solution:

Description: Accepts a number and displays if it’s positive and even using
an option pane.

Java Code (GUI using Swing):

import javax.swing.*;
public class PositiveEvenCheck {

public static void main(String[] args) {

String input = JOptionPane.showInputDialog("Enter a number:");

int number = Integer.parseInt(input);

if (number > 0 && number % 2 == 0) {

JOptionPane.showMessageDialog(null, "The number is positive


and even.");

} else {

JOptionPane.showMessageDialog(null, "The number is not


positive and even.");

8. Design a GUI application to accept the cost price and


selling price form the user in two text fields then
calculate the profit or loss incurred.

Solution:

Description: Accepts cost price and selling price, and calculates profit or
loss.

Java Code (GUI using Swing):

import javax.swing.*;

public class ProfitLossCalculator {

public static void main(String[] args) {


String costPriceStr = JOptionPane.showInputDialog("Enter Cost
Price:");

String sellingPriceStr = JOptionPane.showInputDialog("Enter Selling


Price:");

double costPrice = Double.parseDouble(costPriceStr);

double sellingPrice = Double.parseDouble(sellingPriceStr);

double result = sellingPrice - costPrice;

if (result > 0) {

JOptionPane.showMessageDialog(null, "Profit: " + result);

} else if (result < 0) {

JOptionPane.showMessageDialog(null, "Loss: " +


Math.abs(result));

} else {

JOptionPane.showMessageDialog(null, "No Profit No Loss");

9. Design a GUI application to accept a character in a


text field and print in a label if that character is a
vowel: a, e, i, o, or u. The application should be case
sensitive.

Solution:
Description: Accepts a character and checks if it is a vowel (case-
sensitive).

Java Code (GUI using Swing):

import javax.swing.*;

public class VowelCheck {

public static void main(String[] args) {

String input = JOptionPane.showInputDialog("Enter a character:");

char character = input.charAt(0);

if (character == 'a' || character == 'e' || character == 'i' || character ==


'o' || character == 'u') {

JOptionPane.showMessageDialog(null, "The character is a


vowel.");

} else {

JOptionPane.showMessageDialog(null, "The character is not a


vowel.");

10. A book publishing house decided to go in for


computerization. The database will be maintained at
the back end but you have to design the front end for
the company. You have to accept book code, Title,
Author and Quantity sold from the user. The rrice will
be generated depending upon the book code. Net
price should be calculated on the basis of the discount
given.
 Book seller - 25%
 School-20%
 Customer-5%

Solution:

Description: Accepts book details, calculates price based on book code,


and applies discount depending on the type of customer.

SQL Queries & Front-End (GUI) Setup:

• Book Code determines the price (e.g., 101 for $50, 102 for $60).

• Discount is applied based on the type of customer (25% for Book Seller,
20% for School, 5% for Customer).

• Net price is calculated by subtracting the discount from the original


price.

Java Code (GUI using Swing):

import javax.swing.*;

public class BookPublisher {

public static void main(String[] args) {

String bookCode = JOptionPane.showInputDialog("Enter Book Code


(101 or 102):");

String title = JOptionPane.showInputDialog("Enter Book Title:");

String author = JOptionPane.showInputDialog("Enter Author


Name:");
String quantityStr = JOptionPane.showInputDialog("Enter Quantity
Sold:");

int quantity = Integer.parseInt(quantityStr);

double price = 0;

if (bookCode.equals("101")) {

price = 50;

} else if (bookCode.equals("102")) {

price = 60;

String customerType = JOptionPane.showInputDialog("Enter


Customer Type (Book Seller/School/Customer):");

double discount = 0;

if (customerType.equals("Book Seller")) {

discount = 0.25;

} else if (customerType.equals("School")) {

discount = 0.20;

} else if (customerType.equals("Customer")) {

discount = 0.05;

double netPrice = price * (1 - discount);


double totalPrice = netPrice * quantity;

JOptionPane.showMessageDialog(null, "Net Price: " + netPrice + "\


nTotal Price for " + quantity + " books: " + totalPrice);

____________________________________________________________

You might also like