0% found this document useful (0 votes)
5 views

Java Lab3

Uploaded by

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

Java Lab3

Uploaded by

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

EXERCISE:-1(class and objects)

class Volume

int width,height,depth,v;

Volume(int w,int h,int d)

width=w;

height=h;

depth=d;

void volume()

v=width*height*depth;

void display()

System.out.println("the width of box is:"+width+"\n"+"the height of box is:"+height+"\n"+"the


depth of box is:"+depth+"\n"+"the volume of box is:"+v);

class VolumeDemo

public static void main(String[] args)

Volume ob=new Volume(12,14,16);

ob.volume();

ob.display();

}
}

EXERCISE:-2.1 POLYMORPHISM

class Sharp

void area(int x,int y)

System.out.println("the area of rectangle is:"+x*y+" sq units");

void area(float x)

double z=3.14*x*x;

System.out.println("the area of circle is:"+z+" sq units");

void area(double b,double h)

double a;
a=0.5*b*h;

System.out.println("the area of triangle is:"+a+" sq units");

class Area

public static void main(String[] args)

Sharp ob=new Sharp();

ob.area(10,10);

ob.area(5.55f);

ob.area(2.5,4.2);

EXERCISE:-2.2 POLYMORPHISM PROGRAM 2


class MyMath

void add(int x,int y)

System.out.println("addition of two numbers is:"+(x+y));

void add(float x,float y)

System.out.println("addition of two numbers is:"+(x+y));

void add(double x,double y)

System.out.println("addition of two numbers is:"+(x+y));

void mul(int x,int y)

System.out.println("multiplication of two numbers is:"+x*y);

void mul(float x,float y)

System.out.println("multiplication of two numbers is:"+x*y);

void mul(double x,double y)

System.out.println("multiplication of two numbers is:"+x*y);

void pow(int x,int y)

System.out.println("power of two numbers is:"+Math.pow(x,y));

void pow(float x,float y)


{

System.out.println("power of two numbers is:"+Math.pow(x,y));

void pow(double x,double y)

System.out.println("power of two numbers is:"+Math.pow(x,y));

class Overheat

public static void main(String[] args)

MyMath ob=new MyMath();

ob.add(9,9);

ob.add(38.2,38.2);

ob.add(321.12,321.12);

ob.mul(4,4);

ob.mul(7.7,7.7);ob.mul(7.482,7.482);

ob.pow(3,6);ob.pow(3.3,6.6);ob.pow(3.32,6.654);

}
POINT CLASS:-

import java.lang.Math.*;

class point

double x,y;

point()

x=0;

y=0;

point(double q1,double p1)

x=q1;

y=p1;
}

point(point p1)

x=p1.x;

y=p1.y;

point find_distance(double a,double b)

double dx=a-x;

double dy=b-y;

return new point(dx,dy);

point find_distance(point p)

double dx=p.x-x;

double dy=p.y-y;

return new point(dx,dy);

void display()

System.out.println("the points are");

System.out.println("("+x+","+y+")");

}
public static void main(String args[])

point p1=new point (12.4,34.5);

point p2=new point(21.4,65.96);

point p3=new point();

p3=p2;

point k,l=new point();

k=p1.find_distance(523.45,897.52);

l=p1.find_distance(p3);

k.display();

l.display();

You might also like