0

Is this right? Questions-WAP using a function called area() to find area of circle, square and rectangle as per user's choice.

//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); } }

26th Oct 2020, 4:39 AM
Khushi Verma
Khushi Verma - avatar
1 Respuesta
+ 1
I made it work. I had to fix: - Same signature for circle and square - User input - Semicolon after double p=0 Output is only for circle, I didn't change that Methods have to differ by name and/or parameters, different return value is not enough https://code.sololearn.com/cJvZJc6zPyLS/?ref=app
26th Oct 2020, 8:06 PM
Benjamin Jürgens
Benjamin Jürgens - avatar