import java.util.Scanner; class Circle { double radius; void setValues(double rad) { radius = rad; } void findArea() { double circleArea = Math.PI * radius * radius; System.out.println("Area of circle = " + circleArea); } void findCircumference() { double circleCircumference = 2 * Math.PI * radius ; System.out.println("Circumference of circle = " + circleCircumference); } } class Rectangle { double length,width; void setValues(double len,double wid) { length = len; width=wid; } void findArea() { double rectArea = length * width; System.out.println("Area of Rectangle = " + rectArea); } } public class scratch_paper { public static void main(String[] args) { double radius,length,width; Scanner input= new Scanner(System.in); System.out.println("Type a radius:"); radius= input.nextDouble(); System.out.println("Type a Length:"); length = input.nextDouble(); System.out.println("Type a width:"); width = input.nextDouble(); System.out.println("circle with radius = " + radius); Circle obj = new Circle(); obj.setValues(radius); obj.findArea(); obj.findCircumference(); System.out.println("rectangle with length = " + length+",width"+width); Rectangle obj1 = new Rectangle(); obj1.setValues(length,width); obj1.findArea(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter