|
| 1 | +/* |
| 2 | +Create a java program: |
| 3 | +class Name: Circle |
| 4 | +Instance Variable: radus (double type) |
| 5 | +Instance Method: |
| 6 | +1. area() |
| 7 | +2. circumfrence() 3. perimeter() |
| 8 | + |
| 9 | +Write a separate class TestCircle with a main() method and test the Circle class methods.create a circle objects and assign it to reference variables obj |
| 10 | + |
| 11 | +Input Format |
| 12 | + |
| 13 | +radius of circile |
| 14 | + |
| 15 | +Constraints |
| 16 | + |
| 17 | +radius>0 |
| 18 | + |
| 19 | +Output Format |
| 20 | + |
| 21 | +prints the result of Area,circumfrence and perimeter of circle. |
| 22 | + |
| 23 | +Sample Input 0 |
| 24 | + |
| 25 | +2 |
| 26 | +Sample Output 0 |
| 27 | + |
| 28 | +Area of circle:12.566370614359172 |
| 29 | +Perimeter of circle:12.566370614359172 |
| 30 | +Circumference of circle:12.566370614359172 |
| 31 | +*/ |
| 32 | +import java.io.*; |
| 33 | +import java.util.*; |
| 34 | +class Circle |
| 35 | +{ |
| 36 | + double radius; |
| 37 | + Circle(double r) |
| 38 | + {radius = r;} |
| 39 | + void area() |
| 40 | + { |
| 41 | + System.out.println("Area of circle:"+3.141592653589793*radius*radius); |
| 42 | + } |
| 43 | + void circumfrence() |
| 44 | + { |
| 45 | + System.out.println("Circumference of circle:"+3.141592653589793*2*radius); |
| 46 | + } |
| 47 | + void parimeter() |
| 48 | + { |
| 49 | + System.out.println("Perimeter of circle:"+3.141592653589793*2*radius); |
| 50 | + } |
| 51 | +} |
| 52 | +public class Solution { |
| 53 | + |
| 54 | + public static void main(String[] args) { |
| 55 | + /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ |
| 56 | + Scanner sc =new Scanner(System.in); |
| 57 | + double r = sc.nextDouble(); |
| 58 | + if(r>0) |
| 59 | + { |
| 60 | + Circle c = new Circle(r); |
| 61 | + c.area(); |
| 62 | + c.parimeter(); |
| 63 | + c.circumfrence(); |
| 64 | + |
| 65 | + } |
| 66 | + else |
| 67 | + System.out.print("invalid input"); |
| 68 | + } |
| 69 | +} |
0 commit comments