Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 3 fuera de 30 páginas
Examen

College practical

Document preview thumbnail
Vista previa 3 fuera de 30 páginas

Many programs in it

Vista previa del contenido

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.

Información del documento

Subido en
18 de febrero de 2024
Número de páginas
30
Escrito en
2023/2024
Tipo
Examen
Contiene
Preguntas y respuestas
$21.79

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
1
Última venta
-


Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes