0

Solve the program with function call. Check out the description.

Write a program using function called area() to find the area of a circle, square and rectangle and display to the output as per user's choice. Solve the program along with the function call.

25th Oct 2020, 11:16 AM
Khushi Sinha
Khushi Sinha - avatar
4 Réponses
+ 2
Take Variables according to need of your area formula how many Variables you want for example U need to calculate area of rectangle is l*b here u need two Variables declear length and breadth then for circle u need to declear pi also Then make one Which Which name will be area area() { write here statements to print area } And create object and call your area function if you dont know how to create function u can search on google or you can see solo lessons.
25th Oct 2020, 11:21 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Check this one here you decleared same function name for all so it will give you errors . You should change name or pass different different arguments if you know about constructor then the sign should be different functions name will be same . class pubg { public double area(int r) { double arcircle=3.14*r*r; return(arcircle); } public int area(int s) { int arsquare=s*s; return(arsquare); } public int area(int l,int b) { int arrectangle=l*b; return(arrectangle); } Your another mistake is you missed semicolon where you decleared double p=0 ;
25th Oct 2020, 1:02 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
//To find the area of circle,square,and rectangle import java.io.*; class pubg { public double area(int r) { double arcircle=3.14*r*r; return(arcircle); } public int area(int s) { int arsquare=s*s; return(arsquare); } public int area(int l,int b) { int arrectangle=l*b; return(arrectangle); } public static void main(String args[])throws IOException { DataInputStream x=new DataInputStream(System.in); int r=0,q=0; double p=0, pubg ob= new pubg(); System.out.println("Enter the radius of circle"); int r1=Integer.parseInt(x.readLine()); p=ob.area(r1); System.out.println("Area of circle is:"+p); System.out.println("Enter the side of square"); int s1=Integer.parseInt(x.readLine()); q=ob.area(s1); System.out.println("Enter the length and breadth of rectangle"); int l1=Integer.parseInt(x.readLine()); int b1=Integer.parseInt(x.readLine()); r=ob.area(l1,b1); } }
25th Oct 2020, 12:06 PM
Khushi Sinha
Khushi Sinha - avatar
0
Hey! Can you please add the function calling in this too (menu driven) i.e the area of only shape will be displayed that will be choosen by the user
25th Oct 2020, 1:46 PM
Khushi Verma
Khushi Verma - avatar