Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

College practical

Rating
-
Sold
-
Pages
30
Grade
A+
Uploaded on
18-02-2024
Written in
2023/2024

Many programs in it

Institution
Course

Content preview

JAIRAM ARTS & SCIENCE COLLEGE, SALEM – 08.
CLASS : II BCA SUBJECT : PROGRAMMING IN JAVA
SUBJECT CODE : 22UCAP04 NO. OF PROGRAMS : 10


Ex.No:1 FIND THE AREA OF SQUARE, RECTANGLE AND CIRCLE USING METHOD
OVERLOADING

AIM:
To write a java program to find area of the square, rectangle and circle using method overloading.

ALGORITHM:

STEP 1: Start the process
STEP 2: Create the class ‘Funoverload’ with necessary member functions of same name with arguments to
calculate area of square, rectangle and circle.
STEP 3: Declare the variables side, length, width and radius
STEP 4: Create the object for the class Funoverload as ob
STEP 5: Get the input from the user using DataInputStream class and read from the keyboard.
STEP 6: Call the member functions using object by passing different parameters and calculate the area for
i. ob.area(side);
Square= side*side (Area of square)
ii. ob.area(length,width);
Rectangle= length* width (Area of rectangle)
iii. ob.area(radius);
Circle= 3.14*radius*radius (Area of circle)
STEP 7: Display the corresponding results in the prompt window
STEP 8: Stop the process


FLOWCHART:


START




Declare side, length, width, radius


area (int side)
Create Object (ob) for the Class

int result= side * side

Prompt Input from User

Print result

Print “Enter The Side For Square”




A

, A
area (int l, int w)

Read side
int result= l * w

Print “Enter Length and Width For Rectangle”

Print result

Read length, width




Print “Enter Radius For Circle”




Read radius area (double r)



ob.area(side) int result= 3.14*r*r



ob.area(length,width)
Print result


ob.area(radius)



STOP




SOURCE CODE:(FunOverload.java)
import java.io.*;
class FunOverload
{
void area(int side)
{
int result =side*side;
System.out.println("Area of square : "+result);
}
void area(int l,int w)
{
int result = l*w;
System.out.println("Area of rectangle : "+result);
}
void area(double r)
{

, double result = 3.14*r*r;
System.out.println("Area of circle : "+result);
}
public static void main(String args[])throws IOException
{
int side,length,width;
double radius;
FunOverload ob = new FunOverload();
DataInputStream in=new DataInputStream(System.in);
System.out.println("\tThe area of a square, rectangle and circle using method
overloading");
System.out.println("\t\t********************************************");
System.out.println("Enter the side of the square");
side=Integer.parseInt(in.readLine());
System.out.println("Enter length and width of a rectangle");
length=Integer.parseInt(in.readLine());
width=Integer.parseInt(in.readLine());
System.out.println("Enter the radius of a circle");
radius=Double.parseDouble(in.readLine());
ob.area(side);
ob.area(length,width);
ob.area(radius);
}
}

SAMPLE INPUT AND OUTPUT:
The area of a square, rectangle and circle using method overloading
********** ********************************************
Enter the side of the square
5
Enter length and width of a rectangle
58
56
Enter the radius of a circle
8
Area of square : 25
Area of rectangle : 3248
Area of circle : 200.96

RESULT:
Thus the above java program to find the area of square, rectangle and circle using method
overloading has been successfully executed.

Written for

Institution
Course

Document information

Uploaded on
February 18, 2024
Number of pages
30
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$21.79
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
varshiniammu585

Get to know the seller

Seller avatar
varshiniammu585 Exam Questions
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions