Aissce 2021-22: Information Technology (802) Practical File Class Xii
Aissce 2021-22: Information Technology (802) Practical File Class Xii
2021-22
(2020-2021)
INFORMATION TECHNOLOGY
SUB. CODE – 802
PRACTICAL FILE
MY SQL/JAVA
SUBMITTED BY-
Tushar Dhiman
XII-D
CERTIFICATE
This is to certify that Tushar dhiman of Class XII-D has worked
and completed his Information Technology Practical File under
my Guidance and supervision.
(SESSION : 2020-21)
PLACE: Delhi
DATE:
Answer ->
INPUT
package com.me;
public class Main {
public static void main(String[] args) {
int a = 80, b = 40;
int A = a%b;
int B = a/=b;
int C = (a+b*100)/10;
int D = a*=b;
int E = a+=b;
System.out.println("1)" + A);
System.out.println("2)" + B);
System.out.println("3)" + C);
System.out.println("4)" + D);
System.out.println("5)" + E); }}
OUTPUT
b) To calculate area and perimeter of a circle.
Answer ->
INPUT
package com.me;
Answer ->
INPUT
package com.me;
Answer ->
INPUT
package com.me;
a) To accepts radius of a sphere and displays its volume and surface area.
(Hint: V = 4/3 π r2, S = 4π r3)
Answer ->
INPUT
package com.me;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Enter the Radius of the Sphere: ");
double radius = sc.nextDouble();
System.out.println();
double π = 3.14;
double volume = (4/3)*π*radius*radius*radius;
double sa = 4*π*radius*radius;
System.out.println("Volume of the Sphere: " + volume);
System.out.println("Surface Area of the Sphere: " + sa);}}
OUTPUT
b) To accept marks in five subjects and display the average marks.
Answer ->
INPUT
package com.me;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int i;
System.out.println("Enter number of subjects");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[n];
double avg=0;
System.out.println("Enter marks");
for( i=0;i<n;i++)
{a[i]=sc.nextInt();
}for( i=0;i<n;i++)
{avg=avg+a[i];
}System.out.print("Average of (");
for(i=0;i<n-1;i++)
{System.out.print(a[i]+",");
}System.out.println(a[i]+") ="+avg/n); }}
OUTPUT
c) To accept a number from the user. Then add 3 to that number, and then
multiply the result by 2, subtract twice the original number and display the
result.
Answer ->
INPUT
package com.me;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Enter a Number: "); int num = sc.nextInt();
System.out.println();
int x = num + 3;
int y = x * 2 ;
int z = y - 2 * num;
System.out.println("Final Output: " + z); }}
OUTPUT
d) To accept the temperature in Fahrenheit and convert and display the
temperature in Celsius. (Hint: C = (F – 32) * 5/9)
Answer ->
INPUT
package com.me;
import java.util.Scanner;
public class Main { public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Enter a Temperature in Fahrenheit: "); int num =
sc.nextInt();
System.out.println();
double tem = 0;
double F = tem;
double C = (F-32)*5/9;
System.out.println("Temperature in Celsius: " + C + "°C");}}
OUTPUT
e) To accept principle, rate of interest and time. Calculate and display simple
interest and compound interest.
Answer ->
INPUT
package com.me;
import java.util.Scanner;
public class Main { public static void main(String[] args) {
double pr, rate, t, sim,com;
Scanner sc=new Scanner (System. in);
System.out.println("Enter the amount:");
pr=sc.nextDouble();
System. out. println("Enter the No.of years:");
t=sc.nextDouble();
System. out. println("Enter the Rate of interest");
rate=sc.nextDouble();
sim=(pr * t * rate)/100;
com=pr * Math.pow(1.0+rate/100.0,t) - pr;
System.out.println("Simple Interest="+sim);
System.out. println("Compound Interest="+com);}}
OUTPUT
DECIDE IF OR
ELSE
Selection Structures
i. If or Else
Answer->
INPUT
package com.me;
import java.util.Scanner;
public class Main { public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Enter Sub 1 marks : "); int sub1 = sc.nextInt();
System.out.print("Enter Sub 2 marks : "); int sub2 = sc.nextInt();
System.out.print("Enter Sub 3 marks : "); int sub3 = sc.nextInt();
System.out.print("Enter Sub 4 marks : "); int sub4 = sc.nextInt();
System.out.print("Enter Sub 5 marks : "); int sub5 = sc.nextInt();
int total = sub1 + sub2 + sub3 + sub4 + sub5;
double perc = total / 5;
System.out.println();
System.out.println("Percentage: " + perc);
if(perc>=80)
System.out.println("Excellent !");
else if(perc>=60 && perc<80)
System.out.println("Very Good !");
else if (perc>=40 && perc<60)
System.out.println("Good !");
else
System.out.println("Work Hard !");}}
OUTPUT
Answer->
INPUT
Answer->
INPUT
package com.me;
import java.util.Scanner;
public class Main { public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Enter a Alphabet: "); char choice = sc.nextLine().charAt(0);
switch (choice) {
case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' -> System.out.println(choice + " is a
Vowel.");
default -> System.out.println(choice + " is a Consonant.");}}}
OUTPUT
WHILE
STATEMENT
Repetition Structures
i. While Statement
a) Accept any 5 numbers from the user, Calculate square of the number and
print result.
Answer->
INPUT
package com.me;
import java.util.Scanner;
public class Main { public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Enter the 1st Number: "); int num1 = sc.nextInt();
System.out.print("Enter the 2nd Number: "); int num2 = sc.nextInt();
System.out.print("Enter the 3rd Number: "); int num3 = sc.nextInt();
System.out.print("Enter the 4th Number: "); int num4 = sc.nextInt();
System.out.print("Enter the 5th Number: "); int num5 = sc.nextInt();
System.out.println();
int i = 0;
while (i<1) {
System.out.println("Square of " + num1 + ": " + (num1*num1));
i++;
System.out.println("Square of " + num2 + ": " + (num2*num2));
i++;
System.out.println("Square of " + num3 + ": " + (num3*num3));
i++;
System.out.println("Square of " + num4 + ": " + (num4*num4));
i++;
System.out.println("Square of " + num5 + ": " + (num5*num5));
i++;}}}
OUTPUT
a) Print ASCII values and their equivalent characters. ASCII value varies from 0
to 255.
Answer->
INPUT
package com.me;
public class Main { public static void main(String[] args) {
int i = 0;
do {
System.out.println("The ASCII Value of " + (char)i + " = " + i);
i++;}
while(i<=255);}}
OUTPUT
b) Display Fibonacci Series using do while loop.
Answer->
INPUT
package com.me;
public class Main { public static void main(String[] args) {
int count = 12, num1 = 0, num2 = 1;
System.out.println("Fibonacci Series of " + count + " numbers: ");
int i = 1;
do {System.out.print(num1+ " ");
int x = num1 + num2;
num1 = num2;
num2 = x;
i++;}
while(i<=count);}}
OUTPUT
c) Print all the even numbers from 1 to 20
Answer->
INPUT
package com.me;
public class Main { public static void main(String[] args) {
int n = 20;
System.out.println("Even Numbers from 1 to 20 are:");
for ( int i=1; i<=20; i++ ) {
if(i % 2 == 0) {
System.out.print(i + " " );}}}}
OUTPUT
FOR LOOP
STATEMENT
iii. FOR LOOP STATEMENT
Answer->
INPUT
package com.me;
public class Main { public static void main(String[] args) {
double[] marks = {420, 384, 470, 259.6, 397.5};
for (int i = 0; i < 5; i++)
{double percentage = (marks[i]/500)*100;
String result;
if (percentage >= 40) result = "Passed";
else result = "Failed";
System.out.print((i+1) + "\t");
System.out.print(marks[i] + "\t");
System.out.print(percentage + "\t\t");
System.out.println(result);}}}
OUTPUT
c) Write a program in Java to print the square of every alternate number in an
array.
Answer->
INPUT
package com.me;
public class Main { public static void main(String[] args) {
int [] num = {2, 4, 5, 4, 6};
for (int i = 0; i < 5; i = i+2)
{System.out.println("Alternate Elements: " + num[i]);
int sq = num[i]*num[i];
System.out.println("Square of Alternate Elements: " + sq);}}}
OUTPUT
d) WAP to print the sum, product and average of elements entered by the user.
Answer->
INPUT
package com.me;
import java.util.Scanner;
public class Main { public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int[] num = new int[5];
System.out.print("Enter 5 Numbers: ");
for (int i=0;i<5;i++)
{num[i] = sc.nextInt();}
int sum =0;
System.out.println();
System.out.print("Sum: ");
for(int i=0;i<5;i++)
{sum = sum + num[i];}
System.out.println(sum);
int product=1;
for(int i=0; i<5;i++)
{product=product*num[i];}
System.out.println("Product: " + product);
int avg = sum / 5;
System.out.println("Average: " + avg);}}
OUTPUT
e) WAP to accept 5 names from user and store them in an array and print them
on screen in order.
Answer->
INPUT
package com.me;
import java.util.Scanner;
public class Main { public static void main(String[] args) {
String [] names = new String[5];
Scanner sc = new Scanner(System.in);
System.out.print("Enter 5 Names: ");
for (int i=0;i<5;i++)
{names[i] = sc.next();}
System.out.println();
System.out.println("Entered Names are: ");
for (int i=0;i<5;i++)
{System.out.println(names[i]);}}}
OUTPUT
f) WAP to print highest and lowest total marks of 10 students using Arrays.
Answer->
INPUT
package com.me;
import java.util.Scanner;
public class Main { public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int [] marks = new int[10];
int [] mylist = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int [] occurrences = {0,0,0,0,0,0,0,0,0,0};
int sum=0,highest=-1,lowest=9999,mylistindex=0;
boolean found;
System.out.println("Enter 10 marks:");
for (int i=0;i<10;i++) {marks[i]=in.nextInt();sum=sum+marks[i];}
System.out.println("The numbers entered are:");
for (int tmp:marks){
System.out.print(tmp+" ");
if (tmp>highest) highest=tmp;
if (tmp<lowest) lowest=tmp;
sum+=tmp;
found=false;
for (int i=0;i<mylistindex;i++){
if (mylist[i]==tmp) {found=true;occurrences[i]++;break;}}
if (!found)
{mylist[mylistindex]=tmp;occurrences[mylistindex]=1;mylistindex++;}}
System.out.println();
System.out.println("The average mark is: "+ sum/10);
System.out.println("Highest mark is: "+ highest);
System.out.println("Lowest mark is: ="+lowest);
for (int i=0;i<mylistindex;i++){
System.out.println(mylist[i]+"\t"+occurrences[i]);}}}
OUTPUT
g) Use binary search to search for an element in a number array. The search
key must be accepted from the user.
Answer->
INPUT
package com.me;
import java.util.Arrays;
public class Main { public static void main(String[] args) {
int[] num = {23,7,56,90,45,77};
Arrays.sort(num);
int key = 56;
System.out.print("Sorted array: ");
for (int j : num) System.out.print(j + " ");
System.out.println();
System.out.println("Element found at index: " +
Arrays.binarySearch(num,key));}}
OUTPUT
STRING
FUNCTION
STRING FUNCTION
Answer->
INPUT
package com.me;
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");}}}
OUTPUT
b) A scenario where ArrayIndexOutOfBoundsException occurs.
Answer->
INPUT
package com.me;
public class Main { public static void main(String[] args) {
try{int a[]=new int[10];
a[11] = 9;}
catch(ArrayIndexOutOfBoundsException e){System.out.println
("ArrayIndexOutOfBounds");}}}
OUTPUT
DATABASE
CONNECTIVITY
Database Connectivity
Answer->
INPUT
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
password);
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
System.out.println();}}
catch(SQLException ex)
{System.out.println(ex.getMessage());} } }
SQL
a) Consider the following tables EMP and SALGRADE, write the query for the
following:
ANSWER->
TABLE: EMPLOYEE
INPUT
OUTPUT
ii. To display NAME AND DESIG of those employees whose sgrade is either
‘S02’ or‘S03’
INPUT
mysql> SELECT NAME,DESIG FROM emp WHERE sgrade ='S02' OR sgrade = 's03';
OUTPUT
iii. To display NAME, DESIG, SGRADE of those employee who joined in the
year 2009
INPUT
mysql> SELECT NAME, Desig, sgrade FROM emp WHERE YEAR(doj) = 2009 ;
OUTPUT
INPUT
OUTPUT
v. To display number of employee working in each SALGRADE from table
EMPLOYEE
INPUT
OUTPUT
vi. To display NAME, DESIG, SALARY, HRA from tables EMPLOYEE and
SALGRADE where SALARY is less than 50000
INPUT
mysql> select NAME , DESIG , SALARY , HRA from emp , salgrade where
emp.sgrade = salgrade.sgrade and salary < 50000 ;
OUTPUT
b) Consider the table SHOPPE and ACCESSORIES, write the query for the
following:
ANSWER->
TABLE: SHOPPE
INPUT
OUTPUT
ii. To display Id and Sname of all the Shoppe location in „Nehru Place‟
INPUT
OUTPUT
iii. To display Name, Minimum and Maximum Price of each Name from
ACCESSORIES table
INPUT
OUTPUT
iv. To display Name, Price of all Accessories and their respective SName
from table SHOPPE and ACCESSORIES where Price is 5000 or more.
INPUT
OUTPUT
v. To display all details of accessories where name contains word „Board‟;
INPUT
OUTPUT
c) Consider the table given below. Write SQL queries for the following:
ANSWER->
TABLE: Gym
INPUT
OUTPUT
ii. To display BRANCH wise count of members in the Gym. (i.e. display the
BRANCH and number of members in each BRANCH)
INPUT
OUTPUT
iii. To display names and date of joining of all the members who joined in
the year 2018.
INPUT
OUTPUT
iv. To display Names and Current weight of all the members in descending
order of Current Weight.
INPUT
OUTPUT
v. To display Gender wise, maximum current weight (i.e. display the
gender and maximum current weight of each gender)
INPUT
OUTPUT
vi. To display names and date of joining of members who have their names
starting with ‘S’ and ending with ‘a’.
INPUT
mysql> select name , doj from gym where name like 'S%A';
OUTPUT
d) Consider the following table SHOP and write the following queries in SQL:
ANSWER->
INPUT
OUTPUT
ii. To display I_NAME and PRICE in descending order of quantity.
INPUT
OUTPUT
INPUT
OUTPUT
iv. To add a new value in SHOP table.
INPUT
OUTPUT
v. To display item name and quantity whose price is more than 10.
INPUT
OUTPUT
e) Consider the following tables EMPLOYEES. Write SQL commands for the
statements:
ANSWER->
INPUT
OUTPUT
INPUT
OUTPUT
iii. To display the content of EMPLOYEES table in descending order of
FIRSTNAME.
INPUT
OUTPUT
INPUT
OUTPUT
v. To delete record of employee who’s EMPID IS 152.
INPUT
OUTPUT
f) Consider the following table named “GYM” with details about Fitness
products
Prcode Prname Unitprice Manufacturer
P101 Cross trainer 25000 Avon fitness
P102 Treadmill 32000 AG fitline
P103 Massage chair 20000 Fit Express
P104 Vibration trainer 22000 Avon fitness
P105 bike 13000 Fit express
i. Display the names and unit price of all the products in the store.
INPUT
OUTPUT
ii. Display details of all the products with unit price in the range 20000 to
25000
INPUT
mysql> select prname,unitprice from gym where unitprice between 20000 and
25000 ;
OUTPUT
INPUT
mysql> select * from gym order by unitprice desc ;
OUTPUT
iv. Display details of all products with manufacturer name starting with
“A”.
INPUT
OUTPUT
v. Add a new row for product with the details: “P106”, “Vibro Exercise”,
23000, “Avon Fitness”
INPUT
OUTPUT