Answer to Question #288602 in Java | JSP | JSF for yash

Question #288602

Write a program to create a class Circles with the following information:



radius in integer.



Add two constructors, (a) default constructor, and (b) constructor to pass on radius of a Circle.



Add a method printData( ) to print the radius of the Circle in console.



Add methods printArea( ) and printPerimeter( ) to compute and print the area and perimeter of Circle in console.



Create two objects of this class, c1 and c2. Show the output of both the constructors and all methods of these two objects

1
Expert's answer
2022-01-18T17:22:29-0500


class Circles {
	private int radius;
	private int breadth;


	/**
	 * (a) default constructor
	 */
	public Circles() {
	}


	/**
	 * onstructor to pass on radius of a Circle.
	 * 
	 * @param radius
	 */
	public Circles(int radius) {
		this.radius = radius;
	}


	/**
	 * Add a method printData( ) to print the radius of the Circle in console.
	 */
	public void printData() {
		System.out.println("Radius: " + radius);
	}


	public void printArea() {
		double area = Math.PI * radius * radius;
		System.out.println("Area: " + area);
	}


	/**
	 * print the perimeter of Circle in console.
	 */
	public void printPerimeter() {
		double perimeter = 2 * Math.PI * radius;
		System.out.println("Perimeter: " + perimeter);
	}
}


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		// Create two objects of this class, c1 and c2. Show the output of both the
		// constructors and all methods of these two objects
		Circles с1 = new Circles();
		Circles с2 = new Circles(4);
		с1.printData();
		с1.printArea();
		с1.printPerimeter();


		с2.printData();
		с2.printArea();
		с2.printPerimeter();


	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog