Академический Документы
Профессиональный Документы
Культура Документы
1
INSTRUCTIONS TO BE FOLLOWED IN MAINTAINING THE RECORD BOOK
The Record should be written neatly with ink on the right hand page only. The left hand page being
reserved for diagrams.
1. The date
2. The number and name of the experiment
3. The aim of the experiment
4. Algorithm
5. Program
6. On the left hand side, Flow charts should be designed
7. On the left hand side, Input & Output should be mentioned.
8. Index must be filled in regularly.
9. You must get your record certified by the concerned staff on the very next class after completing the
experiment
10. You must get your record certified by the concerned staff at the end of every semester.
1. You must bring record observations notebook, while coming to the practical class without you may not be
allowed to the practical.
2. Don’t touch the equipment which is not connected with our experiment.
3. When the system /apparatus is issued, you are advised to check their conditions.
4. You should not leave the laboratory without obtaining the signature of the concerned lecturer after
completing the practical
Note:
2
INDEX
3
taking the input from keyboard. 22
2.Write a program by creating a class vehicle and calculate the range of vehicle.
class Vehicle
{
int passengers;
int fuelcap;
int mpg;
int range()
{
return mpg*fuelcap;
}
}
class RetMeth
{
public static void main(String args[])
{
Vehicle minivan=new Vehicle();
Vehicle sportscar=new Vehicle();
int range1,range2;
minivan.passengers=7;
minivan.fuelcap=16;
minivan.mpg=21;
4
sportscar.passengers=2;
sportscar.fuelcap=14;
sportscar.mpg=12;
range1=minivan.range();
range2=sportscar.range();
System.out.println("Minivan can carry "+minivan.passengers+" with range of
"+range1+" Miles");
System.out.println("Sportscar can carry "+sportscar.passengers+" with range of
"+range2+" Miles");
}
}
class RectangleArea
{
public static void main(String args[])
{
Rectangle rect1=new Rectangle(15,10);
int area1=rect1.rectArea();
System.out.println("Area1="+area1);
}
}
class Overload
{
void ovlDemo()
{
System.out.println("No Parameters");
}
void ovlDemo(int a)
{
System.out.println("One Parameter:"+a);
5
}
int ovlDemo(int a,int b)
{
System.out.println("Two Parameters:"+a+" "+b);
return a+b;
}
double ovlDemo(double a,double b)
{
System.out.println("Two Double Parameters:"+a+" "+b);
return a+b;
}
}
class OverloadDemo
{
public static void main(String args[])
{
Overload ob=new Overload();
int resI;
double resD;
ob.ovlDemo();
System.out.println();
ob.ovlDemo(2);
System.out.println();
resI=ob.ovlDemo(4,6);
System.out.println("Result of ob.ovlDemo(4,6): "+resI);
System.out.println();
resD=ob.ovlDemo(1.1,2.32);
System.out.println("Result of ob.ovlDemo(1.1,2.32): "+resD);
}
}
class OverloadCons
{
public static void main(String args[])
{
Box mybox1=new Box(10,20,15);
Box mybox2=new Box();
Box mycube=new Box(7);
double vol;
vol=mybox1.volume();
System.out.println("Volume of mybox1 is "+vol);
vol=mybox2.volume();
System.out.println("Volume of mybox2 is "+vol);
vol=mycube.volume();
System.out.println("Volume of mycube is "+vol);
}
}
class A
{
int i, j;
A(int a, int b)
{
i = a;
j = b;
}
void show()
{
System.out.println("i and j: " + i + " " + j);
}
}
class B extends A
{
int k;
B(int a, int b, int c)
{
super(a, b);
k= c;
7
}
void show(String msg)
{
System.out.println("k: " + k);
}
}
class Override
{
public static void main(String args[])
{
B subOb = new B(1, 2, 3);
subOb.show("This is k");
subOb.show();
}
}
class AbstractAreas
{
public static void main(String args[])
{
Rectangle r = new Rectangle(9, 5);
Triangle t = new Triangle(10, 8);
Figure figref;
figref = r;
System.out.println("Area is " + figref.area());
figref = t;
System.out.println("Area is " + figref.area());
}
}
package MyPack;
TESTBALANCE.JAVA
import MyPack.*;
class TestBalance
{
9
public static void main(String args[])
{
Balance test=new Balance("J.J.Jaspers",99.88);
test.Show();
}
}
9. Write a program using interface area and compute area of rectangle and
circle.
interface Area
{
final static float pi=3.14f;
float compute(float x,float y);
}
class InterfaceTest
{
public static void main(String args[])
{
Rectangle rect=new Rectangle();
Circle cir=new Circle();
Area area;
area=rect;
System.out.println("Area of Rectangle:"+area.compute(10,20));
area=cir;
System.out.println("Area of Circle:"+area.compute(10,0));
}
}
10
import java.awt.*;
import java.applet.*;
11. Write a program using awt and develop the output as follows.
Yes NO May be
Yes
import java.awt.*;
NO
import java.awt.event.*;
import java.applet.*;
/*
11
<applet code="ButtonDemo" width=250 height=150>
</applet>
*/
Windows 98
Windows 2000
Dos
12
Windows xp false
Windows 98 false
Windows 2000 false
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
13
/*<applet code="Checkboxdemo" width=250 height=200>
</applet>
*/
Dos
XP
Solaris
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="ChoiceDemo" width=300 height=180>
</applet>
15
*/
Red
Blue
Green
Orange
O circle
O square
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
16.
16. WAP to Sele
123
123
import java.awt.*;
import java.applet.*;
/*
<applet code=UserIn.class width=300 height=200>
</applet>
*/
class StringOrdering
{
18
static String name[]={"Madras","Delhi","Ahmedabad","Calcutta","Bombay"};
public static void main(String args[])
{
int size=name.length;
String temp=null;
for(int i=0;i<size;i++)
{
for(int j=i+1;j<size;j++)
{
if(name[j].compareTo(name[i])<0)
{
temp=name[i];
name[i]=name[j];
name[j]=temp;
}
}
}
for(int i=0;i<size;i++)
{
System.out.println(name[i]);
}
}
}
18. Write a program to select values from the Department Table Using JDBC.
import java.io.*;
import java.sql.*;
import sun.jdbc.odbc.*;
class Department
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1)
{
System.out.println("error was caught"+e1.getMessage());
}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:Nani","y06it026","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp26");
19
while(rs.next())
{
System.out.println(rs.getInt(1)+rs.getString(2)+rs.getString(3));
}
}
catch(SQLException e2)
{
System.out.println("error caught"+e2.getMessage());
}
}
}
19. Write a program to insert values into Student Table Using JDBC.
import java.sql.*;
class Emp12
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1)
{
System.out.println("error was caught" +e1);
}
try
{
Connection conn=DriverManager.getConnection("jdbc:odbc:Nani","y06it026","");
PreparedStatement psmt=conn.prepareStatement("insert into std values(?,?,?)");
psmt.setInt(1,104);
psmt.setString(2,"ddd");
psmt.setString(3,"pmcs");
psmt.executeUpdate();
psmt.setInt(1,105);
psmt.setString(2,"fff");
psmt.setString(3,"pmcs");
psmt.executeUpdate();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from std");
while(rs.next())
{
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3));
}
conn.close();
}
20
catch(SQLException e2)
{
System.out.println("error caught"+e2.getMessage());
}
}
}
20. Write a program to alter and Insert the values into Table Using JDBC.
import java.sql.*;
class Stu
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:Nani","y06it026","nani");
Statement stmt=conn.createStatement();
conn.setAutoCommit(false);
stmt.executeUpdate("create table stu999(sno number(5),sname char(10),marks number(5))");
stmt.executeUpdate("alter table stu999 add(totalmarks number(5))");
System.out.println("table altered");
stmt.executeUpdate("insert into stu999 values(101,'aaa',25,50)");
stmt.executeUpdate("insert into stu999 values(102,'bbb',35,40)");
stmt.executeUpdate("insert into stu999 values(103,'ccc',15,60)");
ResultSet rs=stmt.executeQuery("select * from stu999");
while(rs.next())
{
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3)+"\t"+rs.getInt(4));
}
conn.commit();
System.out.println("table updated");
stmt.executeUpdate("update stu999 set sno=104 where sname='aaa'");
Statement stmt1=conn.createStatement();
ResultSet rs1=stmt1.executeQuery("select * from stu999");
while(rs1.next())
{
System.out.println(rs1.getInt(1)+"\t"+rs1.getString(2)+"\t"+rs1.getInt(3)+"\t"+rs1.getInt(4));
}
stmt.close();
stmt1.close();
}
}
21
21. Write a program to delete a Record by giving Input in run-time using
keyboard.
import java.sql.*;
import java.io.*;
class Emp11q
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:Nani","y06it026","");
Statement stmt=conn.createStatement();
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Write EmpNO:");
int no=Integer.parseInt(dis.readLine());
int n=stmt.executeUpdate("delete from ja26 where eno="+no+"");
System.out.println(n+"rows deleted");
conn.close();
}
}
22. Write a program to Insert Values into Book table Using Command Line Arguments.
import java.sql.*;
class Book
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1)
{
System.out.println("error was caught"+e1.getMessage());
}
try
{
Connection conn=DriverManager.getConnection("jdbc:odbc:Nani","y06it026","");
Statement stmt=conn.createStatement();
int bookID=Integer.parseInt(args[0]);
String bookname=args[1];
int price=Integer.parseInt(args[2]);
stmt.executeUpdate("create table book(bookID number(5),bookname
varchar2(20),price number(5))");
22
int n=stmt.executeUpdate("insert into book
values("+bookID+",'"+bookname+"',"+price+")");
if(n>0)
System.out.println("Successfully inserted");
else
System.out.println("not Successfully inserted");
conn.close();
}
catch(Exception e2)
{
System.out.println("error was caught"+e2.getMessage());
}
}
}
23