Class Xii Records
Class Xii Records
RELATION –STUDENT
(Create, Insert, View, Delete)
1. Write the SQL queries for the following questions relation STUDENT below
mysql>CREATE DATABASE
itpracticals; mysql>USE
itpracticals;
1. Create table for the above mentioned sno is primarykey.
+ + + + + + +
| SNO|NAME | CLASS | SEC | RESULT | SCHOOLNAME|
+ + + + + + +
| 1 |ARUN | XII |B1 |PASS | DR.NKVV |
| 2 | Magesh |XII |D |PASS |DR.NKVV |
| 3 |Velu |XII |C |Fail |BV |
| 4 | Vanitha |X |A | Pass |Ebenezer |
| 5 |Bala |XII |B | Pass |Dr.NKVV |
+ + + + + + +
5 rows in set (0.03sec)
+ + + + + +
+ 4 rows in set (0.03sec)
5. To display student name, class, school name from the tablestudent.
mysql>Select name, class, schoolname from student ;
The primary key of the table is Employee ID and Manager ID is the foreign key that
references Employee ID
Write SQL commands for the following:
1. Create the above table.
2. Insert values as shownabove.
3. Update the salary of “Amyra” to40000.
4. Alter the table Employee by adding a new columnphone_num.
5. Write a query to display names and salaries of those employees whose
salary are greater than20000.
6. Write a query to display name,salary and bonus details of employees in
descending order ofsalary.
7. Write a query to display the names of employees whose name contains “a” as
thelast
alphabet.
8. Write a query to display the name and Job title of those employees
whoseManager_ID is 1201.
9. Write a query to display the name and Job title of those employees whose
Manager is
“Amyra”.
10. Write a query to display the name and Job title of those employees aged
between 26 years and 30 years (bothinclusive)
QUERIES
+ + +
|EMPLOYEE_NAME | SALARY |
+ + +
| Divya | 50000
|
| Amyra | 40000
|
| Megha | 22000
|
+ + +
3 rows in set (0.00sec)
6. Write a query to display name,salary and bonus details of
employees in descending order ofsalary.
MYSQL> SELECT EMPLOYEE_NAME,SALARY,BONUS FROM EMPLOYEE ORDER BY
SALARY DESC;
+ + + +
| employee_name | salary | bonus |
+ + + +
| Divya | 50000 | NULL|
| Amyra | 40000 | 2500|
|Megha | 22000 | 1300 |
|Rahul | 20000 | 1500|
| Mohit | 16000 | NULL|
| Manish | 15000 | NULL|
+ + +
+ 6 rows in set
(0.00sec)
7. Write a query to display the names of employees whose name contains “a”
as the
lastalphabet.
mysql> SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE EMPLOYEE_NAME
LIKE("%A");
+ +
| EMPLOYEE_NAME|
+ +
| Divya |
| Amyra |
|Megha |
+
9. Write a query to display the name and Job title of those employees whose
Manager is“Amyra”.
mysql> SELECT EMPLOYEE_NAME,JOB_TITLE FROM EMPLOYEE
WHERE EMPLOYEE_NAME="Amyra" AND
JOB_TITLE="MANAGER";
+ + +
| EMPLOYEE_NAME | JOB_TITLE|
+ + +
| Amyra | Manager |
+ +
+ 1 row in set
(0.00sec)
10. Write a query to display the name and Job title of those
employees aged between 26 years and 30 years (both
inclusive)
+ +
+ 2 rows in set
(0.01 sec)
PROGRAM :03
RELATION –STOCK
(Aggregated Functions, Arithmetic
Operartor)
Consider the following the table
+ + +
6 rows in set (0.00sec)
+ +
| sum(stock)|
+ +
| 1475 |
+ +
+ +
| min(price)|
+ +
| 15|
+ +
Combination | (5+(156*(100))-(30+50)/10) |
+ +
| 15597.0000|
+ +
1 row in set (0.00 sec)
PRACTICAL:
04
RELATION –TEACHER
(SELECT &UPDATE )
Consider the following table Teacher and answer for the following questions
6. To retrieve names of all the teachers starting from letter 'L’ along
withsalary.
mysql> SELECT FIRST_NAME,LAST_NAME,SALARY FROM TEACHER WHERE
FIRST_NAME LIKE("L%");
+ + + +
| first_name | last_name|salary |
+ + + +
|Lakshmi | Narayanan | 25000.00|
|Lakshmi | Narasiman | 15000.00|
+ + +
+ 2 rows in set
(0.00 sec)
Table :STORE
Table: SUPPLIERS
7. To display the no of items for each supplier as per scode from the
tablestore.
AIM :To calculate the area of a rectangle using the formula area = length * breadth
SOURCE CODE:
package area;
import
java.util.Scann
er; public class
Area
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \n\t To Calculate the
Area of a Rectangle"); System.out.println("\
nGive the length of the rectangle");
int l=obj.nextInt();
System.out.println("\nGive the breadth of
the rectangle"); int b=obj.nextInt();
int a=l*b;
System.out.println(" \nArea = "+a);
}
}
OUTPUT:
2. Write a java program to get three numbers and print the biggest one
among the three numbers.
AIM :To Find the biggest number from the given three numbers using if
SOURCE CODE:
package biggest;
import
java.util.Scanner;
public class Biggest
{
public static void main(String[] args)
{
int max=a;
if ((b>max) &&(b>c)) max=b;
else if ((c>max) && (c>b)) max= c;
System.out.println(" Biggest number
="+max);
}
}
OUTPUT 1:
To Find the biggest number from the given 3
numbers Give the first number6
Give the second
number 8 Give the
second number 7
Biggest number =8
OUTPUT 2:
To Find the biggest number from the given 3
numbers Give the first number6
Give the second
number 7 Give the
second number 8
Biggest number =8
PROGRAM :
03
CATEGORY OF THE STUDENT
3. Write a java program to get the total marks scored by a student and print
the average and the category in which he/she comes.
AIM :To find the average and to categorize the position of the student in the
class using a multiple if statement.
PROGRAM CODE:
package category;
import
java.util.Scanner;
public class Category
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \n\t To Find the Category of the student");
int total=obj.nextInt();
float ave=total/5;
System.out.println("Your Average is "+ave); if (ave>85)
System.out.println("You are a OutstandingStudent");
else if(ave>=75)
System.out.println("You are in Distinction category");
else if(ave>=60)
System.out.println("You have passed with Firstclass"); else
if(ave>=40)
System.out.println("You have just passed");
else
System.out.println("Sorry .You have failed");
}
}
OUTPUT 1:
To Find the Category of the
student Give the Total marks
scored in 5 subjects 450
Your Average is 90.0
You are a Outstanding Student
OUTPUT 2:
To Find the Category of the
student Give the Total marks
scored in 5 subjects 175
Your Average is35.0
Sorry .You have
failed
PROGRAM : 04
VOWEL OR CONSONANT
4. Write a java program to input a character and check whether it is a vowel or
consonant and print it.
AIM :To Check whether a character is a vowel or consonant using if else statement.
SOURCE CODE:
package vowel;
import
java.util.Scanner;
public class Vowel
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \n\t To Check a character and print vowel or
consonant "); System.out.println("\nType any character");
char ch=obj.next().charAt(0);
if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||
ch=='u'||c h=='U')
System.out.println(ch +" is a
Vowel"); else
System.out.println(ch + “ is a Consonant”);
}
}
OUTPUT 1:
To Check a character and print vowel or
consonant Type any character
O
O is a Vowel
OUTPUT 2:
To Check a character and print vowel or
consonant Type any character
t
t is a Consonant
OUTPUT 3:
To Check a character and print vowel or
consonant Type any character a
a is a Vowel
PROGRAM : 05
5. Write a program to print the name of the month if the month number is given.
AIM:To print the name of the month if the month number is given using switch case
statement.
SOURCE CODE:
Package month;
import
java.util.Scanner;
public class Month
{
public static void main(String[] args)
{
Scanner obj=newScanner(System.in);
System.out.println(" \n\t To print the name of the month for given
number ");
System.out.println("\nType a
number"); int a=obj.nextInt();
switch (a)
{
case 1:
System.out.println("January
"); break;
case 2:
System.out.println("Februar
y"); break;
case 3:
System.out.println("March
"); break;
case 4:
System.out.println("April")
; break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("Jun
e"); break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("Augus
t"); break;
case 9:
System.out.println("Septemb
er"); break;
case 10:
System.out.println("October
"); break;
case 11:
System.out.println("Novemb
er"); break;
case 12:
System.out.println("Decemb
er"); break;
default:
System.out.println("Something is wrong..Enter the number from 1 to
12");
}
}
OUTPUT 1:
October
OUTPUT 2:
NUMBER SEQUENCE
Write a program to print all the numbers from 1 to 50 using for loop.
SOURCE CODE:
package numbersequence;
for(int i=1;i<=50;i++)
System.out.print(i+" ");
}
}
OUTPUT:
To print numbers from 1 to 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2728
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
PROGRAM : 07
Write a java program to find and print square of all the even numbers from 1 to 10.
AIM :To find the square of all even numbers from 1 to 10 using while loop.
SOURCE CODE:
packagesquare;
import
java.util.Scanner;
public class Square
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \t To print the square of even
numbers"); System.out.println("Give the number up
to which you want the squares"); int n=obj.nextInt();
int i=2;
System.out.println(" Square of even numbers up to "+
n+" are"); while (i<=n)
{
System.out.println("Square of "+i+" =
"+i*i); i+=2;
}
}
}
OUTPUT :
MULTIPLES OF THREE
Write a program to display all the multiples of 3 from 1 to 100 using do..while loop
AIM: To display all the multiples of 3 from 1 to 100 using do..while loop.
SOURCE CODE:
Packagethreemultiples
; public class
ThreeMultiples
{
public static void main(String[] args)
{
int i=3;
System.out.println(" \t To print the multiples of three from 1 to
100");
do
{
System.out.print(i+"
"); i+=3;
}
while(i<100); System.out.println("Loop ended!");
}
}
OUTPUT:
To print the multiples of three from 1 to 100
3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75
78 81 84
87 90 93
96 99
Loop ended!
PROGRAM :
09
ARRAYS
9. Write a java program to input an array and to find the smallest and biggest
number in the array.
AIM :To input an array of integers and using array methods sort the array
and print the smallest and biggest number.
SOURCE CODE :
package smallest;
import
java.util.Scanner;
import
java.util.Arrays;
public class Smallest
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \t To Input an array");
System.out.println("Give the number of elements in the array\n");
System.out.println("\nSmallest number
="+small); System.out.println("\nBiggest
number ="+big);
}
}
OUTPUT :
To Input an array
Give the number of elements in the array 5
Enter the elements of the array Element of array
01 -90 Element of array 11 -23
Element of array 21 -56
Element of array 31 -78
Element of array 41 -900
AIM :To input an array and search for an element in the array using Binary search
method.
SOURCE CODE:
Package search;
import
java.util.Scanner;
import java.util.Arrays;
public class Search
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \t To Input an array");
System.out.println("Give the number of elements in the array\
n"); int n=obj.nextInt();
int [] l=new int[n];
int t=obj.nextInt();
System.out.print("\nArray Values are ");
for(int i=0;i<n;i++)
System.out.print(l[i]+"
,"); Arrays.sort(l);
System.out.print("\nSorted Array Values are ");
for(int i=0;i<n;i++)
System.out.print(l[i]+" ,");
int index =Arrays.binarySearch(l,t);
if (index>=0)
System.out.println("\nElement is found at "+ (index+1)+"
position"); else
System.out.println("\nElement not found in the list");
}
}
OUTPUT 1 :
To Input an array
Give the number of elements in the
array 5 Enter the elements of the
array
Element of array - 23
1
Element of array - 56
2
Element of array - 78
3
Element of array - 12
4
Element of array - 9
5
Give the number to be searched in the
array 1 Array Values are 23 ,56 ,78 ,12 ,9
Sorted Array Values are 9 ,12 ,23 ,56 ,78 Element not found in the list
OUTPUT 2 :
To Input an array
Give the number of elements in the
array 5 Enter the elements of the
array
Element of array - 12
1
Element of array - 78
2
Element of array - 45
3
Element of array - 90
4
Element of array - 34
5
Give the number to be searched in the
array 34 Array Values are 12 ,78 ,45
,90 ,34
Sorted Array Values are 12 ,34 ,45
,78 ,90 Element is found at 2
position
PROGRAM : 11
STRING MANIPULATION
SOURCE CODE:
package str;
import
java.util.Scanner;
public class Str
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \n\t String Manipulation");
System.out.println("\nType any String without spaces in between");
String a=obj.next();
System.out.println(" String in Uppercase -"+a.toUpperCase());
System.out.println(" String in Lowercase -"+a.toLowerCase());
System.out.println(" Character at 5th location -"+a.charAt(5));
System.out.println(" Length of the given string -"+a.length());
System.out.println(" Replace all a by e -"+a.replace('a','e'));
System.out.println(" Cancatenation -"+a.concat("Namasthe. "));
System.out.println(" Does the string contain ram
-"+a.contains("ram"));
}
}
OUTPUT:
String Manipulation
AIM :To calculate the area and perimeter of a square by using a class.
SOURCE CODE:
package squareclass;
import
java.util.Scanner;
class Square {
float side;
void area(float side) {
float ar=side*side; System.out.println("Area="+ar);
}
void peri(float side)
{ float pe=4*side;
System.out.println("Perimeter="+pe);
}
{ Scanner obj=new
Scanner(System.in);
System.out.println(" \n\t To Calculate the Area & perimeter of a Square");
System.out.println("Give the side value");
float l=obj.nextFloat();
Square S= new
Square();
System.out.println("If side is
"+ l); S.area(l);
S.peri(l);
}
}
OUTPUT:
To Calculate the Area & perimeter of a
Square Give the side value
7
If side is 7.0 Area=49.0 Perimeter=28.0
PROGRAM : 13
CONSTRUCTOR
13. Write a java program to find the total and average of a student using
class with a constructors.
AIM :To calculate the total and average of a student using class with a
constructors.
SOURCE CODE:
package
studentcons; import
java.util.Scanner;
class Student{
int m1,m2,m3;
Student() {
m1=0;
m2=0
;
m3=0
;
}
int total() {
int
tot=m1+m2+m3;
return tot;
}
double average() {
double
avg=(m1+m2+m3)/3;
return avg;
}
}
public class StudentCons {
public static void main(String[] args)
{
Scanner obj=new
Scanner(System.in); Student s=
new Student();
System.out.println(“To find the total and average of a student”);
System.out.print("Enter English
mark="); s.m1=obj.nextInt();
System.out.print("Enter IT mark=");
s.m2=obj.nextInt();
System.out.print("Enter Accountancy
mark="); s.m3=obj.nextInt();
System.out.println("Total="+s.total());
System.out.println("Average="+s.averag
e());
}
}
OUTPUT:
ASSERTION
Write a program to accept two numbers and print all the numbers between
them using appropriate assertion statement and rising exception message if
any.
AIM: To accept two numbers and print all the numbers between
them using appropriate assertion statement.
SOURCE CODE:
package
assertdemo; import
java.util.Scanner;
public class
AssertDemo
{
public static void main(String[] args)
{
Scanner obj=new
Scanner(System.in);
System.out.print("Enter the starting
no:"); int a=obj.nextInt();
System.out.print("Enter the ending
no:");
int b=obj.nextInt();
assert b>a:"Starting number is greater than the ending
number"; for(int i=a;i<=b;i++)
System.out.print(i+" ");
}
}
OUTPUT :1
Enter the starting
no:10 Enter the
ending no:5
Exception in thread "main" java.lang.AssertionError: Starting number is
greater than the ending number at
assertdemo.AssertDemo.main(AssertDemo.java:16) C:\Users\GKSVV\
AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
Java returned: 1
OUTPUT 2:
Enter the
starting no:
7 Enter the
ending no:
15
7 8 9 10 11 12 13 14 15
PROGRAM :15
EXCEPTION HANDLING
Write a java program to input 2 numbers and print the quotient if it is
divisible using exception handling.
}
OUTPUT 1:
Enter the
first
number 8
Enter the
second
number 4
p=2
Safe Execution
OUTPUT 2:
Enter the
first
number 5
Enter the
second
number 0
/ by zero
Safe Execution