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

ABC

The document contains 4 code examples that calculate areas and perimeters of shapes using object-oriented programming in Java. The first example calculates the area of a rectangle, circle and square by creating a SetValue object and calling its methods. The second example displays employee data by creating Info objects. The third example calculates areas of a rectangle and circle by overloading the Area method. The fourth example calculates the perimeter and area of a triangle by creating an Input object and accessing its properties.

Uploaded by

jayrampowar102
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)
14 views

ABC

The document contains 4 code examples that calculate areas and perimeters of shapes using object-oriented programming in Java. The first example calculates the area of a rectangle, circle and square by creating a SetValue object and calling its methods. The second example displays employee data by creating Info objects. The third example calculates areas of a rectangle and circle by overloading the Area method. The fourth example calculates the perimeter and area of a triangle by creating an Input object and accessing its properties.

Uploaded by

jayrampowar102
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/ 4

Assi

Q1

class SetValue
{
int len;
int bre;
double rad;
int side;

void SetDim(int l, int b, double r, int s )


{
len=l;
bre=b;
rad=r;
side=s;
}

int Rectangle()
{
return len*bre;
}

double Circle()
{
return 3.14*rad*rad;
}

int Square()
{
return side*side;
}

void Display()
{
System.out.println("Area of rectangle is" +Rectangle());
System.out.println("Area of circle is" +Circle());
System.out.println("Area of square is" +Square());
}

}
class Area
{
public static void main(String args[])

{
SetValue o1 = new SetValue();
o1.SetDim(10,5,7.72,5);

o1.Display();

}
}

Q2

class Info
{
String name;
int year;
String address;
}

class Employee
{
public static void main(String args[])
{
Info e1 = new Info();
e1.name = "Robert";
e1.year = 1994;
e1.address = "64C-WallsStreet";

Info e2 = new Info();


e2.name = "Sam";
e2.year = 2000;
e2.address = "68D-WallsStreet";

Info e3 = new Info();


e3.name = "John";
e3.year = 2016;
e3.address = "26B-WallsStreet";

System.out.println("Name\tYear of joining\t\tAddress");
System.out.println(e1.name+"\t"+e1.year+"\t\t\t"+e1.address);
System.out.println(e2.name+"\t"+e2.year+"\t\t\t"+e2.address);
System.out.println(e3.name+"\t"+e3.year+"\t\t\t"+e3.address);
}
}

Q3

class AreaValue
{
void Area(double l,double b)
{
double area= l*b;
System.out.println("Area of rectangle is:"+area);
}

void Area(double r)
{
double area = 3.14 * r *r;
System.out.println("Area of circle is:"+area);
}

class Value
{
public static void main(String arg[])
{
AreaValue o1 = new AreaValue();
o1.Area(10,5);
o1.Area(7);
}
}

Q4

class Input
{
double a;
double b;
double c;

Input()
{
a=3;
b=4;
c=5;
}

class Triangle
{
public static void main(String arg[])
{
Input t =new Input();

double peri =(t.a +t.b +t.c);


double s= peri/2;
double area = Math.sqrt(s*(s-t.a)*(s-t.b)*(s-t.c));

System.out.println("Perimeter of triangle is:"+peri);


System.out.println("Area of triangle is:"+area);
}
}

You might also like