ccrt javapgm
TRANSCRIPT
-
8/2/2019 ccrt javapgm
1/92
1
Program 1
Aim : Program To Generation of Next Date
Program :
import java.io.*;class Nextdate{
public static void main(String args[])throws IOException{
int dd,mm,yyy;int nd=0,nm=0,ny=0;DataInputStream o=new DataInputStream(System.in);
System.out.println("Current Date is.......");dd=Integer.parseInt(o.readLine());System.out.println("Current Month is........");mm=Integer.parseInt(o.readLine());System.out.println("Current Year is........");yyy=Integer.parseInt(o.readLine());if(mm==12){
if(dd==31){
nd=1;
nm=1;ny=yyy+1;}
}else if(dd==28){
if(mm==2){
if((yyy%4==0) || (yyy%100==0)){
nd=dd+1;
nm=mm;ny=yyy;
}else{
nd=1;nm=mm+1;
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
2/92
2
ny=yyy;}
}}
else if(dd==29){if(mm==2){
nd=1;nm=mm+1;ny=yyy;
}}else if(dd==30){
if( mm==1 || mm==3 || mm==5 || mm==7 ||mm==8 || mm==10)
{nd=dd+1;nm=mm;ny=yyy;
}else{
nd=1;nm=mm+1;
ny=yyy;}
}else if(dd==31){
nd=1;nm=mm+1;ny=yyy;
}else{
nd=dd+1;nm=mm;ny=yyy;
}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
3/92
3
System.out.println("Next Date is........");System.out.println(nd+"/"+nm+"/"+ny);
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
4/92
4
Output :
Current Date is.......4
Current Month is........11Current Year is........2011Next Date is........5/11/2011
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
5/92
5
Program 2
Aim : Program To Sum Of Diagonal Elements Of A Square Matrix.
Program :
import java.io.*;import java.lang.*;class Diasum{
public static void main(String args[])throws IOException{
int i,j,m,s=0;int a[][]=new int[3][3];
BufferedReader in=new BufferedReader(newInputStreamReader(System.in));System.out.println("Enter the order of matrix");m=Integer.parseInt(in.readLine());System.out.println("Enter the matrix elements");for(i=0;i
-
8/2/2019 ccrt javapgm
6/92
6
s=s+a[i][j];}
}}
System.out.println("The sum of the diagonal elemnts is "+s);}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
7/92
7
Output :
Enter the order of matrix3
Enter the matrix elements
963
852
741The matrix is
9 6 3
8 5 2
7 4 1
The sum of the diagonal elemnts is 15
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
8/92
8
Program 3
Aim : Program to Book Shop.
Program :
import java.io.*;class Book{
String author;String title;String publisher;int price;int stock;Book(String t,String at,int p,String pb, int stck){
title=t;author=at;price=p;publisher=pb;stock=stck;
}void display(){
System.out.println("Book Title:"+title);System.out.println("Author:"+author);
System.out.println("Book Price:"+price);System.out.println("Book Publisher:"+publisher);System.out.println("No.of copies:"+stock);
}int order(int noc){
int f=0;if(noc
-
8/2/2019 ccrt javapgm
9/92
9
else{
System.out.println("Required no. of copies not in stock");f=0;
}
return f;}void update(int p){
price=p;System.out.println("New price updated");
}}class Bookshop{
public static void main(String arg[]) throws IOException
{int scount=0,fcount=0;int op=0;Book b[]=new Book[10];int ch,n,f=0;DataInputStream d=new DataInputStream(System.in);System.out.println("Add new book details");System.out.println("Enter the no. of books");n=Integer.parseInt(d.readLine());for(int i=0;i
-
8/2/2019 ccrt javapgm
10/92
10
System.out.println("2.Update Price");System.out.println("3.Transaction Details");System.out.println("Enter your choice");ch=Integer.parseInt(d.readLine());switch(ch)
{ case 1:System.out.println("Enter the title and author of
the book:");String titl=d.readLine();String auth=d.readLine();for(int i=0;i
-
8/2/2019 ccrt javapgm
11/92
11
if(b[i].title.compareTo(til)==0){
b[i].update(pr);b[i].display();
}
}break;case 3:System.out.println("No.of successful transactions:");System.out.println(scount);System.out.println("No.of unsuccessful transactions:");System.out.println(fcount);break;default:System.out.println("Wrong choice !");break;
}System.out.println("Do you want to continue (1/0)?");op=Integer.parseInt(d.readLine());
}while(op==1);
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
12/92
12
Output :
Add new book detailsEnter the no. of books2
Enter the book title:JavaEnter the author:BalaguruswamyEnter the price:350Enter the publisher:McGrawEnter the no.of copies:2Enter the book title:
Computer FundamentalEnter the author:SahniEnter the price:450Enter the publisher:Universities PressEnter the no.of copies:3Bookshop Menu----------------
1.Order of Books2.Update Price3.Transaction DetailsEnter your choice1Enter the title and author of the book:JavaBalaguruswamy***BOOK DETAILS***Book Title:JavaAuthor:BalaguruswamyBook Price:350Book Publisher:McGrawNo.of copies:2Enter the no.of copies required2
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
13/92
13
Total cost of Book:700Order is successfully placedDo you want to continue (1/0)?1Bookshop Menu
----------------1.Order of Books2.Update Price3.Transaction DetailsEnter your choice2Enter the book titleComputer FundamentalEnter the new book price:500New price updated
Book Title:Computer FundamentalAuthor:SahniBook Price:500Book Publisher:Universities PressNo.of copies:3Do you want to continue (1/0)?1Bookshop Menu----------------1.Order of Books2.Update Price
3.Transaction DetailsEnter your choice3No.of successful transactions:1No.of unsuccessful transactions:0Do you want to continue (1/0)?1Bookshop Menu----------------
1.Order of Books2.Update Price3.Transaction DetailsEnter your choice1
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
14/92
14
Enter the title and author of the book:Java
Balaguruswamy***BOOK DETAILS***
Book Title:JavaAuthor:BalaguruswamyBook Price:350Book Publisher:McGrawNo.of copies:0Enter the no.of copies requiredDo you want to continue (1/0)?0
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
15/92
15
Program 4
Aim : Program to Sorting of Strings.
Program :
import java.io.*;import java.lang.*;class Sortnames{
public static void main(String args[])throws IOException{
BufferedReader in= new BufferedReader(newInputStreamReader(System.in));
int n,i,j;
String temp;String x[]= new String[10];System.out.println("Enter the limit");n=Integer.parseInt(in.readLine());System.out.println("Enter the Names");for(i=0;i
-
8/2/2019 ccrt javapgm
16/92
16
Output :
Enter the limit5Enter the elements
RAMANNAGEETHABALUROYThe names after the sorting isANNA
BALU
GEETHA
RAM
ROY
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
17/92
17
Program 5
Aim : Program to String Palindrome Using Command LineArgument.
Program :
import java.io.*;import java.lang.*;class Comndpali{
public static void main(String args[]){
char ch,ch1;boolean flag=true;
int l,i,j;String p =args[0];l=p.length();for( j=0,i=l-1 ;j
-
8/2/2019 ccrt javapgm
18/92
18
Output :
H:\crt>java Comndpali COMPUTERNot Palindrome
H:\crt>java Comndpali POPPalindrome
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
19/92
19
Program 6
Aim : Program To Simple Interest Using Constructor Overloading.
Program :import java.io.*;class Deposit{
int p,n;float r;Deposit(){}Deposit(int pr,int nu,float ra)
{ p=pr;n=nu;r=ra;
}Deposit(int pr,float ra){
p=pr;r=ra;n=5;
}
Deposit(int nu,int pr){n=nu;p=pr;r=10;
}public void interest(){
float si=p*n*r/100;float a=si+p;System.out.println("SIMPLE INTEREST :\t" +si);
System.out.println("AMOUNT :\t" +a);}
}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
20/92
20
class Simpleinterest{
public static void main(String arg[]) throws IOException{
int p,n;
float r;DataInputStream d= new DataInputStream(System.in);Deposit d1=new Deposit();System.out.println("Enter the principle amount");p=Integer.parseInt(d.readLine());System.out.println("Enter the no: of years");n=Integer.parseInt(d.readLine());System.out.println("Enter the rate");r=Float.parseFloat(d.readLine());Deposit d2=new Deposit(p,n,r);d2.interest();
System.out.println();System.out.println("SIMPLE INTEREST AFTER 5YRS");System.out.println("Enter the principle amount");p=Integer.parseInt(d.readLine());System.out.println("Enter the rate");r=Float.parseFloat(d.readLine());Deposit d3=new Deposit(p,r);d3.interest();System.out.println();System.out.println("SIMPLE INTEREST WITH RATE 10%");System.out.println("Enter the principle amount");
p=Integer.parseInt(d.readLine());System.out.println("Enter the no: of years");n=Integer.parseInt(d.readLine());Deposit d4=new Deposit(n,p);d4.interest();
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
21/92
21
Output :
Enter the principle amount25000Enter the no: of years
5Enter the rate10SIMPLE INTEREST : 12500.0AMOUNT : 37500.0
SIMPLE INTEREST AFTER 5YRSEnter the principle amount5600Enter the rate12
SIMPLE INTEREST : 3360.0AMOUNT : 8960.0
SIMPLE INTEREST WITH RATE 10%Enter the principle amount5000Enter the no: of years4SIMPLE INTEREST : 2000.0AMOUNT : 7000.0
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
22/92
22
Program 7
Aim : Program To Publication.
Program :import java.io.*;import java.lang.*;class Publication{
String title;float price;public void getdata(String t,float p){
title=t;
price=p;}public void putdata(){
System.out.println("TITLE :\t" +title);System.out.println("PRICE :\t" +price);
}}class Books extends Publication{
int pagecnt;
public void getd(String t,float p,int pg){
getdata(t,p);pagecnt=pg;
}public void putd(){
putdata();System.out.println("PAGE COUNT :\t" +pagecnt);
}}
class Tape extends Publication{
float playtime;public void getd(String t,float p,float pt)
{
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
23/92
23
getdata(t,p);playtime=pt;
}public void putd(){
putdata();System.out.println("PLAY TIME :\t" +playtime);}
}class Publicationdemo{
public static void main(String arg[]) throws IOException{
BufferedReader br=new BufferedReader(newInputStreamReader(System.in));
String ta;
float p,pl;int pa,n,i,m;Books b[]=new Books[10];Tape t[]=new Tape[10];System.out.println("Enter the number of books");n=Integer.parseInt(br.readLine());System.out.println("ENTER BOOK DETAILS");for(i=0;i
-
8/2/2019 ccrt javapgm
24/92
24
System.out.println("Enter the title of "+(i+1)+"th"+" tape");ta=br.readLine();System.out.println("Enter the price of "+(i+1)+"th"+"
tape");p=Float.parseFloat(br.readLine());
System.out.println("Enter the play time of "+(i+1)+"th"+" tape");pl=Float.parseFloat(br.readLine());t[i].getd(ta,p,pl);
}System.out.println("DETAILS OF BOOKS");for(i=0;i
-
8/2/2019 ccrt javapgm
25/92
25
Output
Enter the number of books1
ENTER BOOK DETAILSEnter the title of 1th bookJavaEnter the price of 1th book525Enter the pagecount of 1th book1250
Enter the number of tapes2ENTER TAPE DETAILS
Enter the title of 1th tapeNew Malayalam SongsEnter the price of 1th tape125.95Enter the play time of 1th tape56.30Enter the title of 2th tapeEnglish RapEnter the price of 2th tape99.99Enter the play time of 2th tape
10.10DETAILS OF BOOKSTITLE : JavaPRICE : 525.0PAGE COUNT : 1250DETAILS OF TAPESTITLE : New Malayalam SongsPRICE : 125.95PLAY TIME : 56.3TITLE : English RapPRICE : 99.99PLAY TIME : 10.1
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
26/92
26
Program 8
Aim : Program To Employee Database Using Abstract Class
Program :
import java.io.*;import java.lang.*;abstract class Employee{
int id;String name;Employee(int i,String c){
id=i;name=c;
}abstract void display();
}
class Teaching extends Employee{
String dept1;double salary;Teaching(int i,String c,String dept,double sal){
super(i,c);dept1=dept;salary=sal;
}void display(){
System.out.println("Id : "+id);System.out.println("Name : "+name);System.out.println("Department : "+dept1);System.out.println("Salary : "+salary);
}
}
class NonTeaching extends Employee{
double salary1;NonTeaching(int i,String c,double sal1)
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
27/92
27
{super(i,c);salary1=sal1;
}void display()
{ System.out.println("Id : "+id);System.out.println("Name : "+name);System.out.println("Salary : "+salary1);
}}class Professor extends Teaching{
Professor(int i,String c,String dept,double sal){
super(i,c,dept,sal);
}void display(){
System.out.println("Id : "+id);System.out.println("Name : "+name);System.out.println("Department : "+dept1);System.out.println("Salary : "+salary);
}}class Lecture extends Teaching{
String grade;Lecture(int i,String c,String dept,double sal,String g){
super(i,c,dept,sal);grade=g;
}
void display(){
System.out.println("Id : "+id);System.out.println("Name : "+name);
System.out.println("Department : "+dept1);System.out.println("Salary : "+salary);System.out.println("Grade : "+grade);
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
28/92
28
class Clerical extends NonTeaching{
String grade1;Clerical(int i,String c,double sal1,String g1)
{ super(i,c,sal1);grade1=g1;
}void display(){
System.out.println("Id : "+id);System.out.println("Name : "+name);System.out.println("Salary : "+salary1);System.out.println("Grade : "+grade1);
}
}class Administrator extends NonTeaching{
Administrator(int i,String c,double sal1){
super(i,c,sal1);}void display(){
System.out.println("Id : "+id);System.out.println("Name : "+name);
System.out.println("Salary : "+salary1);}
}class Employeedet{
public static void main(String args[])throws IOException{
BufferedReader br=new BufferedReader(newInputStreamReader(System.in));
Employee e;
int i;String c;String dept;double sal;double sal1;String g;String g1;
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
29/92
29
System.out.println("Enter The Teacher Details");System.out.println("Id of Teacher is");i=Integer.parseInt(br.readLine());System.out.println("Name of the Teacher");c=br.readLine();
System.out.println("Department of Teacher");dept=br.readLine();System.out.println("Salary of a Teacher");sal=Integer.parseInt(br.readLine());Teaching t=new Teaching(i,c,dept,sal);System.out.println("Enter The NonTeaching details");System.out.println("Id of nonTeacher is");i=Integer.parseInt(br.readLine());System.out.println("Name of non Teacher");c=br.readLine();System.out.println("Salary of non Teacher");
sal1=Integer.parseInt(br.readLine());NonTeaching nt=new NonTeaching(i,c,sal1);System.out.println("Enter The Professor Details");System.out.println("Id of Professor is");i=Integer.parseInt(br.readLine());System.out.println("Name of the Professor");c=br.readLine();System.out.println("Department of Professor");dept=br.readLine();System.out.println("Salary of a Professor");sal=Integer.parseInt(br.readLine());
Professor p=new Professor(i,c,dept,sal);System.out.println("Enter The Lecture Details");System.out.println("Id of Lecture is");i=Integer.parseInt(br.readLine());System.out.println("Name of the Lecture");c=br.readLine();System.out.println("Department of Lecture");dept=br.readLine();System.out.println("Salary of a Lecture");sal=Integer.parseInt(br.readLine());System.out.println("Grade of Lecture");
g=br.readLine();Lecture l=new Lecture(i,c,dept,sal,g);System.out.println("Enter The Clerical details");System.out.println("Id of Clerk is");i=Integer.parseInt(br.readLine());System.out.println("Name of the Clerk");
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
30/92
30
c=br.readLine();System.out.println("Department of Clerk");dept=br.readLine();System.out.println("Salary of a Clerk");sal=Integer.parseInt(br.readLine());
System.out.println("Grade of Clerk");g1=br.readLine();Clerical cl=new Clerical(i,c,sal1,g1);System.out.println("Enter The Administrator Details");System.out.println("Id of Administrator is");i=Integer.parseInt(br.readLine());System.out.println("Name of the Administrator");c=br.readLine();System.out.println("Salary of a Clerk");sal=Integer.parseInt(br.readLine());Administrator a=new Administrator(i,c,sal1);
System.out.println("Teacher Details");t.display();System.out.println("NonTeaching details");nt.display();System.out.println("Professor Details");p.display();System.out.println("Lecture Details");l.display();System.out.println("Clerical details");cl.display();System.out.println("Administrator Details");
a.display();}
}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
31/92
31
Output :
Enter The Teacher DetailId of Teacher is55
Name of the TeacherAnnaDepartment of TeacherComputer ScienceSalary of a Teacher15000Enter The NonTeaching deId of nonTeacher is77Name of non TeacherBabu
Salary of non Teacher10000Enter The Professor DetaId of Professor is40Name of the ProfessorGopalDepartment of ProfessorBiologySalary of a Professor25000
Enter The Lecture DetailId of Lecture is10Name of the LectureGeethaDepartment of LectureMathsSalary of a Lecture18000Grade of LectureA
Enter The Clerical detaiId of Clerk is101Name of the ClerkLeela
Department of Clerk
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
32/92
32
MathsSalary of a Clerk14000Grade of ClerkC
Enter The AdministratorId of Administrator is401Name of the AdministratoRajuSalary of a Clerk20000Teacher DetailsId : 55Name : AnnaDepartment : Computer Sc
Salary : 15000.0NonTeaching detailsId : 77Name : BabuSalary : 10000.0Professor DetailsId : 40Name : GopalDepartment : BiologySalary : 25000.0Lecture Details
Id : 10Name : GeethaDepartment : MathsSalary : 18000.0Grade : AClerical detailsId : 101Name : LeelaSalary : 10000.0Grade : CAdministrator Details
Id : 401Name : RajuSalary : 10000.0
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
33/92
33
Program 9
Aim : Program To Result Preparation.
Program :import java.io.*;interface Sports{
final int smark=10;public void putwt();
}class Student{
String name;
int rollno;void getno(String a, int b){
name=a;rollno=b;
}void putno(){
System.out.println("Roll number is " +rollno);System.out.println("Name of the student is " +name);
}
}class Test extends Student{
int m1,m2;void getmark(int x,int y){
m1=x;m2=y;
}void putmark(){
System.out.println("Mark of Subject1 " +m1);System.out.println("Mark of Subject2 " +m2);
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
34/92
34
class Result extends Test implements Sports{
double res;public void putwt(){
System.out.println("Weightage mark for sports " +smark);}void display(){
putno();putmark();putwt();res=m1+m2+smark;System.out.println("Total mark of Student " +res);
}}
class StudentInter{
public static void main(String args[])throws IOException{
int l,s1,s2,i;Result r[]=new Result[10];BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));System.out.println("Enter the number of students...");l=Integer.parseInt(br.readLine());for(i=1;i
-
8/2/2019 ccrt javapgm
35/92
35
for(i=1;i
-
8/2/2019 ccrt javapgm
36/92
36
Output
Enter the number of students...2Enter the name...
AnnaEnter the rollno....12Enter the two subject's marks of a student.8799Enter the name...AppuEnter the rollno....20Enter the two subject's marks of a student.
8990DETAILS OF STUDENTRoll number is 12Name of the student isAnnaMark of Subject187Mark of Subject299Weightage mark for sports 10Total mark of Student 196.0Roll number is 20Name of the student isAppu
Mark of Subject189Mark of Subject290Weightage mark for sports 10Total mark of Student 189.0
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
37/92
37
Program 10
Aim : Program To Implementing Interface
Program :import java.io.*;interface Quad{
void area();void volume();
}class Rectangle implements Quad{
int l,b,h;
Rectangle(int length,int breadth,int height){l=length;b=breadth;h=height;
}public void area(){
int ar=l*b;System.out.println("The area of Rectangle is "+ar);
}
public void volume(){
int v=l*h*b;System.out.println("The volume of Rectangle is "+v);
}}class Square implements Quad{
int s;Square(int side){
s=side;}public void area( ){
int ar=s*s;System.out.println("The area of Square is "+ar);
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
38/92
38
}public void volume(){
int v=s*s*s;System.out.println("The volume of Square is "+v);
}}class Areavolume{
public static void main(String args[])throws IOException{
BufferedReader bi=new BufferedReader(newInputStreamReader(System.in));
int le,br,ht,sqr;System.out.println("Enter the length,breadth and height
of rectangle ");
le=Integer.parseInt(bi.readLine());br=Integer.parseInt(bi.readLine());ht=Integer.parseInt(bi.readLine());Rectangle r=new Rectangle(le,br,ht);r.area();r.volume();System.out.println("Enter the sides of square");sqr=Integer.parseInt(bi.readLine());Square sq = new Square(sqr);sq.area();sq.volume();
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
39/92
39
Output :
Enter the length,breadth and height of rectangle1565
45The area of Rectangle is 975The volume of Rectangle is 43875Enter the sides of square7The area of Square is 49The volume of Square is 343
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
40/92
40
Program 11
Aim : Program To Implementation Of Two Packages.
Program :/*Student Package*/package Stud;public class Student{
int rol;String name;public Student(int a,String n){
rol=a;
name=n;}public void show(){
System.out.println("Student Roll no:"+rol);System.out.println("Student Name:"+name);
}}
/*Teacher Package*/
package Teach;public class Teacher{
int id;String tname;public Teacher(int a,String n){
id=a;tname=n;
}public void showt()
{System.out.println("Teacher ID:"+id);System.out.println("Teacher Name:"+tname);
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
41/92
41
/*Main Program*/import Stud.Student;import Teach.Teacher;import java.io.*;class StudTeachPack
{public static void main(String args[])throws IOException{
int n1,n2;String na1,na2;BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));System.out.println("Enter The Student Details");System.out.println("Enter the rollnum");n1=Integer.parseInt(br.readLine());System.out.println("Enter the name");
na1=br.readLine();Student s=new Student(n1,na1);System.out.println("Enter The Teacher Details");System.out.println("Enter the id");n2=Integer.parseInt(br.readLine());System.out.println("Enter the name");na2=br.readLine();Teacher t=new Teacher(n2,na2);System.out.println("Student Details");System.out.println("-----------------------);s.show();
System.out.println("Teacher Details");System.out.println("-----------------------);t.showt();
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
42/92
42
Output :
H:\crt>javac Stud/Student.java
H:\crt>javac Teach/Teacher.java
H:\crt>javac StudTeachPack.java
H:\crt>java StudTeachPack
Enter The Student DetailsEnter the rollnum1168Enter the nameRamEnter The Teacher Details
Enter the id101Enter the nameBaluStudent Details--------------------Student Roll no:1168Student Name:RamTeacher Details---------------------Teacher ID:101
Teacher Name:Balu
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
43/92
43
Program 12
Aim : Program To Exception Handling.
Program :import java.io.*;class Driverdemo extends Exception{
public static void main(String args[])throws IOException{
String name,add;int n,i,a;BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the limit");n=Integer.parseInt(in.readLine());for(i=0;i60){
System.out.println("Exception occured");throw new Driverdemo();
}}catch(Driverdemo e){
System.out.println("Exception caught "+e);}
}}
}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
44/92
44
Output :
Enter the limit2Enter the name
RamEnter the addressRamvillaEnter the age56Enter the nameBabuEnter the addressGeethamEnter the age61
Exception occuredException caught Driverdemo
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
45/92
45
Program 13
Aim : Program To Counter Using Thread.
Program :import java.io.*;class Counterthread{
public static void main(String arg[])throws IOException{
int n;DataInputStream p;p=new DataInputStream(System.in);System.out.println("Enter the limit");
n=Integer.parseInt(p.readLine());Thread t=Thread.currentThread();try{
for(int i=0;i
-
8/2/2019 ccrt javapgm
46/92
46
Output :
Enter the limit100
123456789
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
47/92
47
Program 14
Aim : Program To Threads using thread priority1.1,2,3,...........
2.1,3,5,7...............3.2,4,6,8.................
Program :
import java.io.*;class Pattern1 implements Runnable{
Thread t;int n;Pattern1(int p,int nu)
{t=new Thread(this,"PATTERN1");t.setPriority(p);n=nu;t.start();
}public void run(){
for(int i=1;i
-
8/2/2019 ccrt javapgm
48/92
48
for(int i=1;i
-
8/2/2019 ccrt javapgm
49/92
49
System.out.println("Thread Interrupted");}
}}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
50/92
50
Output :
Enter the limit
10
1,2,3,4,5,6,7,8,9,10,
1,3,5,7,9,
2,4,6,8,10,
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
51/92
51
Program 15
Aim : Program To Marquee Using Applet.
Program :import java.awt.*;import java.applet.*;/**/public class Marque extends Applet implements Runnable{
String msg="Hai Friends......How Are You? ";
Thread t=null;int state;boolean stopFlag;public void init(){
setBackground(Color.cyan);setForeground(Color.red);
}public void start(){
t=new Thread(this);
stopFlag=false;t.start();
}public void run(){
char ch;for( ; ;){
try{
repaint();
Thread.sleep(250);ch=msg.charAt(0);msg=msg.substring(1,msg.length());msg +=ch;if(stopFlag)break;
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
52/92
52
}catch(InterruptedException e){}
}
}public void stop(){
stopFlag=true;t=null;
}public void paint(Graphics g){
g.drawString(msg,50,30);}
}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
53/92
53
Output :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
54/92
54
Program 16
Aim : Program To Graphics Using Applet
Program :import java.awt.*;import java.applet.*;/*
*/public class Picturen extends Applet{
public void paint(Graphics g)
{ g.setColor(Color.red);g.drawLine(231,22,210,10);g.drawLine(220,30,210,10);
g.drawLine(256,22,256,5);g.drawLine(245,20,256,5);
g.drawOval(210,20,75,75);g.setColor(Color.blue);g.fillOval(210,80,100,100);
g.setColor(Color.red);g.fillOval(233,36,10,10);g.fillOval(245,35,10,10);
g.setColor(Color.black);g.drawLine(244,45,245,58);g.drawLine(233,59,255,58);
g.drawArc(145,60,145,120,-70,-100);}
}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
55/92
55
Output :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
56/92
56
Program 17
Aim : Program to Event Handling Program
Program :import java.io.*;import java.awt.*;import java.awt.event.*;import java.applet.*;/*
*/public class KeyEventHand extends Applet implements KeyListener{
String msg="";int X=10,Y=20;public void init(){
addKeyListener(this);}public void keyPressed(KeyEvent ke){
showStatus("Key Down");}public void keyReleased(KeyEvent ke)
{showStatus("Key Up");
}public void keyTyped(KeyEvent ke){
msg+=ke.getKeyChar();repaint();
}public void paint(Graphics g){
g.drawString(msg,X,Y);
}}
Output :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
57/92
57
Program 18
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
58/92
58
Aim : Program to Prepare a Feedback Form using AWT Control
Program :
import java.awt.*;import java.applet.*;import java.awt.event.*;/*
*/public class Feedbackdemo extends Applet implements ActionListener{
String msg=" ";String str;Label form,name,ge,pl,em,co;TextField namet,emt;TextArea com;Button res,sub;CheckboxGroup gen;Checkbox male,female;Choice loc;public void init(){
setLayout(null);
form=new Label("FEEDBACK FORM");form.setBounds(400,10,150,50);add(form);name=new Label("NAME");name.setBounds(100,100,100,50);add(name);namet=new TextField(20);namet.setBounds(350,100,200,30);add(namet);ge=new Label("GENDER");ge.setBounds(100,150,100,50);
add(ge);gen=new CheckboxGroup();male=new Checkbox("MALE",gen,true);male.setBounds(350,150,200,40);add(male);
female=new Checkbox("FEMALE",gen,false);
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
59/92
59
female.setBounds(550,150,250,40);add(female);pl=new Label("PLACE");pl.setBounds(100,190,200,50);add(pl);
loc=new Choice();loc.setBounds(350,200,200,140);loc.add("-Select-");loc.add("Trivandrum");loc.add("Kollam");loc.add("Alappuzha");loc.add("Pathanamthitta");loc.add("Kottayam");loc.add("Idukki");loc.add("Eranakulam");loc.add("Thrissur");
loc.add("Palakkad");loc.add("Mallapuram");loc.add("Kozhikode");loc.add("Wayanad");loc.add("Kannur");loc.add("Kasargod");add(loc);em=new Label("EMAIL");em.setBounds(100,250,100,50);add(em);emt=new TextField(20);
emt.setBounds(350,250,200,30);add(emt);co=new Label("COMMENTS");co.setBounds(100,300,100,50);add(co);com=new TextArea();com.setBounds(350,300,400,100);add(com);sub=new Button("SUBMIT");sub.setBounds(400,550,50,30);add(sub);
res=new Button("RESET");res.setBounds(500,550,50,30);add(res);sub.addActionListener(this);
res.addActionListener(this);
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
60/92
60
}public void actionPerformed(ActionEvent ae){
str=ae.getActionCommand();if(str.equals("SUBMIT"))
{ msg="FEEDBACK FORM SUBMITTED SUCCESSFULLY";}else if(str.equals("RESET")){
msg="FORM RESETTED. ENTER NEW DATA";namet.setText(" ");emt.setText(" ");com.setText(" ");gen.setSelectedCheckbox(male);male.setState(false);
female.setState(false);loc.select("-Select-");
}else{
msg="WRONG COMMAND";}repaint();
}public void paint(Graphics g){
g.drawString(msg,400,650);}
}
Output :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
61/92
61
Program 19
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
62/92
62
Aim : Program To Flow Laylout And Border Layout
Program :
/** Flow Laylout */
import java.awt.*;import java.awt.event.*;import java.applet.*;/**/public class FlowLayoutDemo extends Applet implements ItemListener{
String msg=" ";Checkbox crab,prawn,tuna,shark;public void init(){
setLayout(new FlowLayout(FlowLayout.LEFT));crab = new Checkbox("CRAB",null,true);prawn= new Checkbox("PRAWN");tuna = new Checkbox("TUNA");shark = new Checkbox("SHARK");add(crab);
add(prawn);add(tuna);add(shark);crab.addItemListener(this);prawn.addItemListener(this);tuna.addItemListener(this);shark.addItemListener(this);
}public void itemStateChanged(ItemEvent ie){
repaint();
}public void paint(Graphics g){
msg= "Current state: ";g.drawString(msg,6,80);
msg= "CRAB: "+ crab.getState();
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
63/92
63
g.drawString(msg,6,100);msg= "PRAWN: "+ prawn.getState();g.drawString(msg,6,120);msg= "TUNA: "+ tuna.getState();g.drawString(msg,6,140);
msg= "SHARK: "+ shark.getState();g.drawString(msg,6,160);}
}
Output :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
64/92
64
Program
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
65/92
65
/** Border Layout */
import java.awt.*;
import java.awt.event.*;import java.applet.*;/**/public class BorderLayoutDemo extends Applet{
public void init(){
setLayout(new BorderLayout());
add(new Button("Kerala Tourism"),BorderLayout.NORTH);add(new Button("Beaches"),BorderLayout.SOUTH);add(new Button("Heritage sites"),BorderLayout.EAST);add(new Button("Backwaters"),BorderLayout.WEST);String msg=" Kerala is known for its tropical backwaters and\n "+"\npristine beaches such as Kovalam \n" +"\n Popular attractions in the state "+"\n include the beaches at Kovalam Cherai and Varkala \n"+"\n The hill stations of Munnar\n"+"\nNelliampathi Ponmudi and Wayanad ";add(new TextArea(msg),BorderLayout.CENTER);
}}
Output :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
66/92
66
Program 20
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
67/92
67
Aim : Program To PopUp Menu
Program :
import java.awt.*;import java.awt.event.*;import java.applet.*;/*
*/class MenuFrame extends Frame implements ActionListener{
String msg=" ";MenuFrame(String title){
super(title);MenuBar mbar=new MenuBar();setMenuBar(mbar);Menu file=new Menu("File");MenuItem nw,open,save,line,print,exit;file.add(nw=new MenuItem("New"+" "+"Ctrl+N"));file.add(open=new MenuItem("Open"+" "+"Ctrl+O"));file.add(save=new MenuItem("Save"+" "+"Ctrl+S"));file.add(line=new MenuItem("-"));file.add(print=new MenuItem("Print"+" "+"Ctrl+p"));file.add(exit=new MenuItem("Exit"));mbar.add(file);Menu view=new Menu("View");Menu explorerbars=new Menu("Explorer Bar");MenuItem history,search;explorerbars.add(history=new MenuItem("History"));explorerbars.add(search=new MenuItem("Search"));view.add(explorerbars);mbar.add(view);nw.addActionListener(this);open.addActionListener(this);save.addActionListener(this);line.addActionListener(this);print.addActionListener(this);
exit.addActionListener(this);history.addActionListener(this);
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
68/92
68
search.addActionListener(this);}public void actionPerformed(ActionEvent ae){
msg="You have selected \t ";
String arg=(String)ae.getActionCommand();msg+=arg;repaint();
}public void paint(Graphics g){
g.drawString(msg,10,220);}
}public class Popupmenu extends Applet{
Frame f;public void init(){
f=new MenuFrame("Menu Demo");int width=Integer.parseInt(getParameter("width"));int height=Integer.parseInt(getParameter("height"));setSize(new Dimension(width,height));f.setSize(width,height);f.setVisible(true);
}public void start()
{f.setVisible(true);
}public void stop(){
f.setVisible(false);}
}
Output :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
69/92
69
Program 21
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
70/92
70
Aim : Program To Simple calculator using RMI.
Program :
/**Interface */
import java.rmi.*;public interface Calintf extends Remote{
int add(int d1,int d2) throws RemoteException;int sub(int d1,int d2) throws RemoteException;int mul(int d1,int d2) throws RemoteException;int div(int d1,int d2) throws RemoteException;
}
/**Implementing Interface */
import java.rmi.*;import java.rmi.server.*;public class Calimp extends UnicastRemoteObject implements Calintf{
public Calimp() throws RemoteException{}public int add(int d1,int d2) throws RemoteException
{return d1+d2;
}public int sub(int d1,int d2) throws RemoteException{
return d1-d2;}public int mul(int d1,int d2) throws RemoteException{
return d1*d2;}
public int div(int d1,int d2) throws RemoteException{
return d1/d2;}
}
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
71/92
71
/**Server class*/
import java.net.*;import java.rmi.*;public class Calserver
{public static void main(String args[]){
try{
Calimp c=new Calimp();Naming.rebind("rmi://localhost/calserver",c);System.out.println("Server is ready");
}catch(Exception e){
System.out.println("Exception "+e);}
}}
/**Client Class*/
import java.rmi.*;import java.io.*;
public class Calclient{
public static void main(String arg[]){
BufferedReader br=new BufferedReader( newInputStreamReader(System.in));
String ch;int cn;String name="rmi://localhost/calserver";try{
Calintf cal=(Calintf)Naming.lookup(name);do{
System.out.println("Enter first no : ");
int d1=Integer.parseInt(br.readLine());System.out.println("Enter second no : ");
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
72/92
72
int d2=Integer.parseInt(br.readLine());System.out.println("Enter the operator(+,-,*,/)");ch=br.readLine();if(ch.equals("+"))System.out.println("Sum : "+cal.add(d1,d2));
else if(ch.equals("-"))System.out.println("Difference : "+cal.sub(d1,d2));else if(ch.equals("*"))System.out.println("Product : "+cal.mul(d1,d2));else if(ch.equals("/"))System.out.println("Quotient : "+cal.div(d1,d2));elseSystem.out.println("Wrong Choice");System.out.println("Do you want to continue?(0/1)");cn=Integer.parseInt(br.readLine());
}while(cn!=0);
}catch(Exception e){
System.out.println("Exception : "+e);}
}}
Output :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
73/92
73
H:\crt\RMI>javac Calintf.java
H:\crt\RMI>javac Calimp.java
H:\crt\RMI>javac Calserver.java
H:\crt\RMI>javac Calclient.java
H:\crt\RMI>rmic Calimp
H:\crt\RMI>start rmiregistry
H:\crt\RMI>java CalserverServer is ready
H:\crt\RMI>java Calclient 192.168.1.2Enter first no :23Enter second no :44Enter the operator(+,-,*,/)+Sum : 67Do you want to continue?(0/1)0
H:\crt\RMI>java Calclient 192.168.1.2Enter first no :11Enter second no :2Enter the operator(+,-,*,/)*Product : 22Do you want to continue?(0/1)1Enter first no :
11
Enter second no :33
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
74/92
74
Enter the operator(+,-,*,/)+Sum : 44Do you want to continue?(0/1)1
Enter first no :55Enter second no :33Enter the operator(+,-,*,/)-Difference : 22Do you want to continue?(0/1)1Enter first no :78
Enter second no :2Enter the operator(+,-,*,/)/Quotient : 39Do you want to continue?(0/1)0
Project I
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
75/92
75
q1:Employee and Department database
Create table Emptable and Depttable and Insert values .Depttable :-Dno(primary key),Dname,FloorEmptable:-Empno(primary key),Empname,Dno(Foreign Key),Salary,Age
Ans:
SQL> create table depttable(Dno varchar(10) PRIMARY KEY,Dnamevarchar(20),Floor
varchar(10));
Table created.
SQL> insert into depttable values('D-501','Toy','F-102');
1 row created.
SQL> insert into depttable values('D-503','Shoe','S-202');
1 row created.
SQL> insert into depttable values('D-505','Clothes','T-302');
1 row created.
SQL> insert into depttable values('D-506','Books','F-109');
1 row created.
SQL> insert into depttable values('D-507','Toy','S-210');
1 row created.
SQL> insert into depttable values('D-504','Sweets','T-307');
1 row created.
SQL> insert into depttable values('D-509','Jewels','F-110');
1 row created.
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
76/92
76
SQL> select * from depttable ;
DNO DNAME FLOOR---------- -------------------- ----------D-501 Toy F-102
D-503 Shoe S-202D-505 Clothes T-302D-506 Books F-109D-507 Toy S-210D-504 Sweets T-307D-509 Jewels F-110
7 rows selected.
SQL> create table emptable(Empno varchar(10) PRIMARY KEY,Enamevarchar(20),
Dno varchar(20),Salary numeric(10),Age numeric(10),FOREIGN KEY(Dno) REFERENCES depttable(Dno));
Table created.
SQL> insert into emptable values('E12','Anna','D-507',8000,35);
1 row created.
SQL> insert into emptable values('E15','Ram','D-505',5000,55);
1 row created.
SQL> insert into emptable values('E16','Raj','D-503',3000,45);
1 row created.
SQL> insert into emptable values('E17','Leela','D-504',6500,40);
1 row created.
SQL> insert into emptable values('E18','Kuttu','D-501',4000,42);
1 row created.
SQL> insert into emptable values('E20','Biju','D-504',9500,30);
1 row created.
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
77/92
77
SQL> insert into emptable values('E25','Siju','D-509',1000,25);
1 row created.
SQL> insert into emptable values('E26','Giri','D-506',2500,20);
1 row created.
SQL> select * from emptable;
EMPNO ENAME DNO SALARY AGE---------- -------------------- -------------------- ---------- --E12 Anna D-507 8000 35E15 Ram D-505 5000 55E16 Raj D-503 3000 45E17 Leela D-504 6500 40
E18 Kuttu D-501 4000 42E20 Biju D-504 9500 30E25 Siju D-509 1000 25E26 Giri D-506 2500 20
8 rows selected.
q2:
Find out the name of all employees.
Ans :
SQL> Select Ename from emptable;
ENAME--------------------AnnaRamRajLeelaKuttuBijuSijuGiri8 rows selected.
q3:
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
78/92
78
Retrive the names of depatartment in Assending order and theiremployees in desending order.
Ans :
SQL> select Dname ,Ename from depttable,emptable wheredepttable.Dno=emptable.Dno order by Dname asc, Ename desc;
DNAME ENAME-------------------- -----------Books GiriClothes RamJewels SijuShoe RajSweets Leela
Sweets BijuToy KuttuToy Anna
8 rows selected.
q4 :
Find Name,Age and Salary of Raj and Ram.
Ans :
SQL> select Ename,Age,Salary from emptable where EnameIN('Raj','Ram');
ENAME AGE SALARY------- -------------------------Ram 55 5000Raj 45 3000
q5 :
Find out all the employee names of emptable with a any where in thename.
Ans :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
79/92
79
SQL> select Ename from emptable where Ename like ('%a%');
ENAME--------------------
AnnaRamRajLeela
q6 :
Find out which employee either works in Toy or Shoe department.
Ans :
SQL> select Ename, Dname from emptable,depttable whereemptable.Dno=depttable.Dno and Dname IN('Toy','Shoe');
ENAME DNAME---------- ------------Anna ToyRaj ShoeKuttu Toy
q7:
Dispaly the Department of employee Raj.Ans :
SQL> select Dname from depttable,emptable where Ename='Raj' andemptable.Dno=depttable.Dno;
DNAME----------Shoe
q8 :
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
80/92
80
Modify the emptable.To include 2 more fields,Manager varchar(10) andJob varchar(10) and Insert values;
Ans :
SQL> alter table emptable add(Manager varchar(25),Job varchar(10));
Table altered.
SQL> select * from emptable;
EMPNO ENAME DNO SALARY AGE MANAGER JOB------------------------- -------------------- -------- ---------------
E12 Anna D-507 8000 35
E15 Ram D-505 5000 55
E16 Raj D-503 3000 45
EMPNO ENAME DNO SALARY AGE MANAGER JOB------------------------- -------------------- -------- ---------------
E17 Leela D-504 6500 40
E18 Kuttu D-501 4000 42
E20 Biju D-504 9500 30
EMPNO ENAME DNO SALARY AGE MANAGER JOB------------------------- -------------------- -------- ---------------
E25 Siju D-509 1000 25
E26 Giri D-506 2500 20
8 rows selected.
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
81/92
81
SQL> update emptable SET Manager='Biju',job='Ast.Mngr' whereEmpno='E12';
1 row updated.
SQL> update emptable SET Manager='Anil',job='Sales' where Empno='E15';
1 row updated.
SQL> update emptable SET Manager='Rajan',job='Executive' whereEmpno='E16';
1 row updated.
SQL> update emptable SET Manager='Biju',job='Clerk' where Empno='E17';
1 row updated.
SQL> update emptable SET Manager='Rani',job='Accounter' whereEmpno='E18';
1 row updated.
SQL> update emptable SET Manager='Null',job='Manager' whereEmpno='E20';
1 row updated.
SQL> update emptable SET Manager='Nila',job='Sweeper' whereEmpno='E25';
1 row updated.
SQL> update emptable SET Manager='Geetha',job='Sweeper' whereEmpno='E26';
1 row updated.
SQL> select* from emptable;
EMPNO ENAME DNO SALARY AGE MANAGER JOB------------------------- -------------------- -------- ---------------------
E12 Anna D-507 8000 35 Biju Ast.Mngr
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
82/92
82
E15 Ram D-505 5000 55 Anil Sales
E16 Raj D-503 3000 45 Rajan Executive
EMPNO ENAME DNO SALARY AGE MANAGER JOB------------------------- -------------------- -------- -----------------------
E17 Leela D-504 6500 40 Biju Clerk
E18 Kuttu D-501 4000 42 Rani Accounter
E20 Biju D-504 9500 30 Null Manager
EMPNO ENAME DNO SALARY AGE MANAGER JOB------------------------- -------------------- -------- ----------------------
E25 Siju D-509 1000 25 Nila Sweeper
E26 Giri D-506 2500 20 Geetha Sweeper
8 rows selected.
q9 :
Dispaly the Empno,Ename and job of employee who are not Clerk and
Whose salary is less than the salary of Clerk.Ans :
SQL> select Empno,Ename,job from emptable where salary
-
8/2/2019 ccrt javapgm
83/92
83
q10 :
Select the name of employee and department of all employees fromemptable,depttable.
Ans :
SQL> select Ename,Dname from emptable,depttable whereemptable.Dno=depttable.Dno;
ENAME DNAME-------------- ---------------Anna ToyRam ClothesRaj ShoeLeela SweetsKuttu ToyBiju SweetsSiju JewelsGiri Books
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
84/92
84
Project II
q1 :
Student Database
Create Studtable:Studtable :-Name,Rollno,Date of Birth,Sub1,Sub2,Sub3,Sub4,Sub5
Ans :
SQL> create table Studtable(name varchar(10),rollnonumeric(5)PRIMARY KEY,DOB date,sub1 numeric(5),sub2 numeric(5),
sub3 numeric(5),sub4 numeric(5),sub5 numeric(5));
Table created.
q2 :
Insert 5 row values and display 5 rows.
Ans :
SQL> insert into Studtable values('amith',110,TO_DATE('12-12-1989','DD-MM-YY'),89,75,99,95,87);
1 row created.
SQL> insert into Studtable values('aruna',118,TO_DATE('15-7-1988','DD-MM-YY'),88,56,75,65,50);
1 row created.
SQL> insert into Studtable values('sunitha',225,TO_DATE('4-8-1990','DD-MM-
YY'),75,65,88,77,90);
1 row created.
SQL> insert into Studtable values('krishna',544,TO_DATE('17-4-1995','DD-MM-YY'),88,70,80,78,65);
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
85/92
85
1 row created.
SQL> insert into Studtable values('leela',780,TO_DATE('8-8-1985','DD-MM-
YY'),70,70,50,60,65);
1 row created.
SQL> select * from Studtable;
NAME ROLLNO DOB SUB1 SUB2 SUB3 SUB4 SUB5---------- ---------- --------- ---------- ---------- ---------- ---------------------amith 110 12-DEC-89 89 75 99 95 87
aruna 118 15-JUL-88 88 56 75 65 50
sunitha 225 04-AUG-90 75 65 88 77 90
NAME ROLLNO DOB SUB1 SUB2 SUB3 SUB4 SUB5---------- ---------- --------- ---------- ---------- ---------- ---------------------
krishna 544 17-APR-95 88 70 80 78 65
leela 780 08-AUG-85 70 70 50 60 65
q3 :
Modify the studtable to include 2 fields total and percent.
Ans :
SQL> alter table Studtable ADD(total numeric(10),percent numeric(10));
Table altered.
SQL> select * from Studtable;
NAME ROLLNO DOB SUB1 SUB2 SUB3 SUB4 SUB5 TOTAL PERCENT---------- ---------- --------- ---------- ---------- ---------- -------------------------------amith 110 12-DEC-89 89 75 99 95 87
aruna 118 15-JUL-88 88 56 75 65 50
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
86/92
86
sunitha 225 04-AUG-90 75 65 88 77 90
NAME ROLLNO DOB SUB1 SUB2 SUB3 SUB4 SUB5 TOTAL PERCENT---------- ---------- --------- ---------- ---------- ---------- -------------------------------
krishna 544 17-APR-95 88 70 80 78 65
leela 780 08-AUG-85 70 70 50 60 65
q4 :
Calculate Total and Percent and dispaly.
Ans :
SQL> update Studtable SET total=sub1+sub2+sub3+sub4+sub5;
5 rows updated.
SQL> update Studtable SET percent=total/500*100;
5 rows updated.
SQL> select * from Studtable;
NAME ROLLNO DOB SUB1 SUB2 SUB3 SUB4 SUB5 TOTAL PERCENT---------- ---------- --------- ---------- ---------- ---------- -------------------------------
amith 110 12-DEC-89 89 75 99 95 87 445 89
aruna 118 15-JUL-88 88 56 75 65 50 334 67
sunitha 225 04-AUG-90 75 65 88 77 90 395 79
NAME ROLLNO DOB SUB1 SUB2 SUB3 SUB4 SUB5 TOTAL PERCENT---------- ---------- --------- ---------- ---------- ---------- -------------------------------
krishna 544 17-APR-95 88 70 80 78 65 381 76
leela 780 08-AUG-85 70 70 50 60 65 315 63
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
87/92
87
q5 :
Select the details of student whose name starts with a having 5 letters.
Ans:
SQL> select * from Studtable where name like('a____');
NAME ROLLNO DOB SUB1 SUB2 SUB3 SUB4 SUB5 TOTAL PERCENT---------- ---------- --------- ---------- ---------- ---------- -------------------------------
amith 110 12-DEC-89 89 75 99 95 87 445 89
aruna 118 15-JUL-88 88 56 75 65 50 334 67
q6 :
Give additional 5 marks to those student whose % is above 80.
Ans :
SQL> select name,rollno,DOB,sub1,sub2,sub3,sub4,sub5,total+5 astotal,(total+5)/5 as percent from Studtable where percent > 80;
NAME ROLLNO DOB SUB1 SUB2 SUB3 SUB4 SUB5 TOTAL PERCENT
---------- ---------- --------- ---------- ---------- ---------- -------------------------------
amith 110 12-DEC-89 89 75 99 95 87 450 90
q7 :
Display number of rows in the table;
Ans :
SQL> select count(*) from Studtable;
COUNT(*)----------
5
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
88/92
88
q8 :
Select the name of student with highest mark;
Ans :
SQL> select name from Studtable where (total=(Select max(total) fromStudtable));
NAME----------Amith
q9 :
Select name and age whose age is greater than the others.
Ans :
SQL> select name,(TO_CHAR(sysdate,'YYYY')-TO_CHAR(DOB,'YYYY')) asage from Studtable where DOB= (Select min(DOB) from Studtable);
NAME AGE---------- ----------leela 26
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
89/92
89
Project III
q1 :
Item Database
Create item table.Item:- Itemno, Itemname, Itemprice,Qtyonhand
Ans:
SQL> create table item(itemno numeric(5)PRIMARY KEY,itemnamevarchar(10),itemprice numeric(3,2),qtyonhand numeric(3));
Table created.
q2 :
Insert values And display all details of item.
Ans :
SQL> insert into item values(1,'Screw',2.25,50);
1 row created.
SQL> insert into item values(2,'Nut',5.00,110);
1 row created.
SQL> insert into item values(3,'Bolt',3.99,75);
1 row created.
SQL> insert into item values(4,'Hammer',9.99,125);
1 row created.
SQL> insert into item values(5,'Washer',1.99,100);
1 row created.
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
90/92
90
SQL> insert into item values(6,'Nail',0.99,300);
1 row created.
SQL> select * From item;
ITEMNO ITEMNAME ITEMPRICE QTYONHAND---------- ------------------ ----------------- --------------
1 Screw 2.25 502 Nut 5 1103 Bolt 3.99 754 Hammer 9.99 1255 Washer 1.99 1006 Nail .99 300
6 rows selected.
q3:
Find the total value of each item based on qtyonhand.
Ans :
SQL> select itemname,itemprice*qtyonhand "Total value" from item;
ITEMNAME Total value---------- --------------------Screw 112.5Nut 550Bolt 299.25Hammer 1248.75Washer 199Nail 297
6 rows selected.
q4:
Display item with unit price of atleast 5
Ans:SQL> select UPPER(itemname) as item,itemprice from item where
itemprice>=5;
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
91/92
91
ITEM ITEMPRICE------------ ------------NUT 5HAMMER 9.99
q5:
Find item with a unit price between 2 and 5.
Ans:
SQL> select * from item where itemprice between 2 and 5;
ITEMNO ITEMNAME ITEMPRICE QTYONHAND------------- ---------- ---------- ---------------------------
1 Screw 2.25 502 Nut 5 1103 Bolt 3.99 75
q6 :
Find the total,average,highest and lowest unit prices
Ans:
SQL> select sum(itemprice),avg(itemprice),max(itemprice),min(itemprice) from item;
SUM(ITEMPRICE) AVG(ITEMPRICE) MAX(ITEMPRICE) MIN(ITEMPRICE)---------------------- ----------------------- ----------------------- ----------------------
24.21 4.035 9.99 .99
q7:
Display item price rounded to nearest price.
Ans :
SQL> select itemname,ROUND(itemprice,0) from item;
M.Sc Computer ScienceAssumption College, Changanacherry.
-
8/2/2019 ccrt javapgm
92/92
92
ITEMNAME ROUND(ITEMPRICE,0)----------------- ----------------------------Screw 2Nut 5
Bolt 4Hammer 10Washer 2Nail 1
6 rows selected.
q8:
Delete records in which itemprice lessthan 2 .
Ans :
SQL> delete from item where itemprice select * from item;
ITEMNO ITEMNAME ITEMPRICE QTYONHAND--------------- -------------- ---------- ------------------------
1 Screw 2.25 502 Nut 5 1103 Bolt 3 99 75