0% found this document useful (0 votes)
2 views24 pages

XII IT Practical File Content

The document contains practical exercises for Class XII students on MySQL and Java programming. It includes SQL commands for creating and manipulating student and employee tables, as well as various Java programs demonstrating calculations, conditionals, loops, arrays, user-defined methods, classes, string functions, exception handling, and threading. Each section provides code snippets and examples for students to practice and understand the concepts.

Uploaded by

komalsharma3127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views24 pages

XII IT Practical File Content

The document contains practical exercises for Class XII students on MySQL and Java programming. It includes SQL commands for creating and manipulating student and employee tables, as well as various Java programs demonstrating calculations, conditionals, loops, arrays, user-defined methods, classes, string functions, exception handling, and threading. Each section provides code snippets and examples for students to practice and understand the concepts.

Uploaded by

komalsharma3127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Dr. M.K.

K Arya Model School


IT Practical
Information Technology(802)
Class XII
MYSQL
1. create table student(rollno integer,name varchar(25),gender char(1),marks decimal(5,2),DOB
date);
insert into student values(2,'Deep Singh','M',98,'1998-08-22');
insert into student values(4,'Radhika Gupta','F',78.5,'1999-12-03');
insert into student values(1,'Raj Kumar','M',93,'2000-11-17');
insert into student values(9,'Shreya Anand','F',70.5,'1999-10-08');
insert into student values(7,'Gurpreet Kaur','F',65,'2000-01-04');
insert into student values(10,'Prateek Mittal','M',75.5,'2000-12-25');
insert into student(rollno,name) values(3,'Ankit Sharma');
select * from student;

select * from student where gender='M';

SELECT ROLLNO,NAME,DOB
WHERE DOB BETWEEN ‘1999-01-01’ AND ‘2000-12-31’

select rollno,name,dob from student order by name;


select rollno,name,dob from student order by rollno desc;

select rollno,name,marks from student order by rollno desc,marks;

select rollno,name,marks+5 from student;

select rollno||" "||name from student;

select distinct name from student;


select rollno,name,marks from student where marks>=70 or rollno>5;

select rollno,name,marks from student where name in ('Deep Singh','Raj Kumar');

select avg(marks),max(marks),min(marks) from student;

select sum(marks) from student;

select count(name) from student;


2. create table emp(eno integer,ename varchar(25),job varchar(20),hiredate date,sal
decimal(7,2),deptno integer);
insert into emp values(8369,'SMITH','CLERK','1990-12-18',8000.00,20);
insert into emp values(8499,'ANYA','SALESMAN','1991-02-20',16000,30);
insert into emp values(8566,'MAHADEVAN','MANAGER','1991-04-02',24500,20);
insert into emp values(8888,'SCOTT','ANALYST','1992-12-09',30500,20);
insert into emp values(8934,'MITA','CLERK','1992-01-23',13000,10);
insert into emp values(8839,'AMIR','PRESIDENT','1991-11-18',50000,10);

SELECT COUNT(ENAME),DEPTNO FROM EMP GROUP BY DEPTNO HAVING


DEPTNO=20;

To display the sum of salaries in each dept


To display max salary in each dept

Display department name of all employees


select emp.eno,emp.ename,dept.dname from emp,dept where emp.deptno=dept.deptno;
JAVA
1. simple calculator program
public class HelloWorld{

public static void main(String []args){


int a=10,b=20;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
}

2. To calculate student’s total and percentage


public class HelloWorld{
public static void main(String []args){
double eng=67.5,math=76,sc=89,ssc=67.5,hnd=77.5;
double total=eng+math+sc+ssc+hnd;
double perc = total/5;
System.out.println("Total="+total);
System.out.println("Percentage="+perc);
}
}
3. To calculate volume of a box
public class HelloWorld{
public static void main(String []args){
int L=10;
int B=4;
int H=8;
int Vol=L*B*H;
System.out.println("Volume of cube is: "+Vol);
}
}

4. To calculate area and perimeter of a circle


public class HelloWorld{
public static void main(String []args){
double r=2.6;
double area=3.14*r*r;
double peri=2*3.14*r;
System.out.println("The area of circle is "+area);
System.out.println("The perimeter of circle is "+peri);
}
}
IF ELSE STATEMENT

5. Take a number and check whether it is odd or even.


public class Main
{
public static void main(String[] args) {
int num=53;
if(num%2==0)
System.out.println(num+" is Even");
else
System.out.println(num+" is Odd");
}
}
6. Check whether a person is eligible to vote or not
public class Main
{
public static void main(String[] args) {
int age=17;
if(age>=18)
System.out.println("You are eligible to vote");
else
System.out.println("You are not eligible to vote");
}
}

7. Take the percentage of a student. If the percentage is greater than 60 then print “Pass”
otherwise print “Work Hard”

public class Main


{
public static void main(String[] args) {
double perc=47.5;;
if(perc>=60)
System.out.println("PASS");
else
System.out.println("WORK HARD");
}
}
8. Take two numbers and print the bigger number.
public class Main
{
public static void main(String[] args) {
int a=25,b=56;
if(a>b)
System.out.println(a+" is the greater no.");
else
System.out.println(b+" is the greater no.");
}
}

9. Take 3 numbers and display the greater number.

public class Main


{
public static void main(String[] args) {
int a=27,b=16,c=62;
if(a>b && a>c)
System.out.println(a+" is the greatest no.");
else if(b>a && b>c)
System.out.println(b+" is the greatest no.");
else
System.out.println(c+" is the greatest no.");
}
}

Take marks in 5 subjects. Then calculate the percentage and print the remark based on it:
% Remark
>=80 Excellent
>=60 and <80 Very Good
>=40 and <60 Good
<40 Work Hard

public class Main


{
public static void main(String[] args) {
double eng=45.5,math=78.5,sc=67,ssc=75.5,hnd=62;
double perc=(eng+math+sc+ssc+hnd)/5;
if(perc>=80)
System.out.println(perc+" % Excellent");
else if(perc>=60 && perc<80)
System.out.println(perc+" % Very Good");
else if(perc>=40 && perc<60)
System.out.println(perc+" % Good");
else
System.out.println(perc+" % Work Hard");
}
}
10. Write code to accept the following from the user :
1. Name 2. Integer 3. Float
Display the values entered.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner user_input=new Scanner(System.in);
String name; int a; double num;
System.out.println("Enter your name:");
name=user_input.next();
System.out.println("Your name is "+name);
System.out.println("Enter an Integer:");
a=user_input.nextInt();
System.out.println("Your Integer is "+a);
System.out.println("Enter a double value:");
num=user_input.nextDouble();
System.out.println("Your double value is "+num);
}
}
11. Accept the basic salary from the user. Calculate and display
DA=50% basic, HRA = 30% basic, PF = 12% basic.
Display Total salary = basic+DA+HRA – PF
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner user_input=new Scanner(System.in);
System.out.println("Enter your basic salary");
double bsal;
bsal=user_input.nextDouble();
double DA=0.50*bsal;
double HRA=0.30*bsal;
double PF=0.12*bsal;
double Tot_sal=bsal+DA+HRA-PF;
System.out.println("Your total salary is "+Tot_sal);
}
}
12. Accept salary of an employee from the user. Deduct the income tax from the salary on
the following basis and finally display income tax and net salary.
Salary Income Tax
>`15000 30%
Between `7000 - `15000 20%
<`7000 10%
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner user_input=new Scanner(System.in);
System.out.println("Enter your salary");
double sal, itax;
sal=user_input.nextDouble();
if(sal>=15000)
itax=0.30*sal;
else if(sal>=7000 && sal<15000)
itax=0.20*sal;
else
itax=0.10*sal;
System.out.println("Your Income Tax is "+itax);
System.out.println("Your net salary is "+(sal-itax));
}
}

13. Ask the user to enter a number between 0 and 6. If the entered number is 0 , the message
“It is Sunday” should be displayed. If the entered number is 1, the message “It is Monday”
should be displayed and so on. Use switch case statement.

import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner user_input=new Scanner(System.in);
System.out.println("Enter a Number");
int num;
num=user_input.nextInt();
switch(num)
{
case 0:System.out.println("It is Sunday");
break;
case 1:System.out.println("It is Monday");
break;
case 2:System.out.println("It is Tuesday");
break;
case 3:System.out.println("It is Wednesday");
break;
case 4:System.out.println("It is Thursday");
break;
case 5:System.out.println("It is Friday");
break;
case 6:System.out.println("It is Saturday");
break;
}
System.out.println("Program Ends");
}
}

LOOPS

14. Write a java program to display numbers from 1 to 10.

public class Main


{
public static void main(String[] args) {
for(int i=1;i<=10;i++)
System.out.println(i);
}
}
15. Accept a number from the user and calculate and display its factorial
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int num;
Scanner user_input=new Scanner(System.in);
System.out.println("Enter a number");
num=user_input.nextInt();
int fact=1;
for(int i=1;i<=num;i++)
fact=fact*i;
System.out.println("The factorial is "+fact);
}
}
16. Calculate the average of all the even numbers till the number entered by the user.

import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int num,sum=0,count=0; double avg;
Scanner user_input=new Scanner(System.in);
System.out.println("Enter a limit");
num=user_input.nextInt();
for(int i=2;i<=num;i=i+2)
{
sum+=i;
count++;
}
avg=sum/count;
System.out.println("The average is "+avg);
}
}

17. Display squares of numbers from 5 to 1.

public class Main


{
public static void main(String[] args) {
for(int num=5;num>=1;num--)
{
System.out.print("Square of " + num);
System.out.println(" = " + num*num);
}
}
}

ARRAYS

18. Create an array of five numbers and display them

public class Main


{
public static void main(String[] args) {
int []marks={10,23,56,45,12};
for(int i=0;i<5;i++)
System.out.print(marks[i]+" ");
}
}
USER DEFINED METHODS

19. Calculate the volume of a cube by sending length, breadth and height to a function for
calculation.
public class Main
{
static double volume(double l,double b,double h)
{
return l*b*h;
}
public static void main(String[] args) {

System.out.println("The volume of cube is "+volume(2.4,5.6,7.8));


}
}

CLASS
20. Design a class book. Display details of a book using Constructor.

class Book
{
String bname;
String author;
double price;

Book(String b,String a,double p){


bname=b;
author=a;
price=p;
}
void display(){
System.out.println("Book name:"+bname);
System.out.println("Author name:"+author);
System.out.println("Price:"+price);
}
}
public class Main
{
public static void main(String[] args) {
Book b1=new Book("Harry Potter","Rowling",450.0);
b1.display();
}
}

21. STRING FUNCTIONS


public class Main
{
public static void main(String[] args) {
String s1="HELLO HOW Are You";
String s2="HI";
String s3="hi";
System.out.println(s2.equalsIgnoreCase(s3));
System.out.println(s1.toLowerCase());
System.out.println(s1.replace('H','t'));
System.out.println(s1.contains("HELLO"));
System.out.println(s1.endsWith("You"));
}
}
22. EXCEPTION HANDLING
public class Main
{
public static void main(String[] args) {
try{
int num1=30, num2=0;
int output=num1/num2;
System.out.println ("Result: "+output);
}
catch(ArithmeticException e){
System.out.println ("You Shouldn't divide a number by zero");
}
}
}

23. THREAD

public class Main extends Thread {


public static void main(String[] args) {
Main thread = new Main();
thread.start();
System.out.println("This code is outside of the thread");
}
public void run() {
System.out.println("This code is running in a thread");
}
}

You might also like