Answer to Question #199926 in Java | JSP | JSF for Aniket Nayak

Question #199926

A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, PointType in Java, that can store and process a point in the x-y plane.Every circle has a center and a radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine its position in the x-y plane. The center of a circle is a point in the x-y plane. Design a class, CircleType that can store the radius and center of the circle. Because the center is a point in the x-y plane and you designed the class to capture the properties of a point from PointType class. You must derive the class CircleType from the class PointType. You should be able to perform the usual operations on a circle, such as setting the radius, printing the radius, calculating and printing the area and circumference, and carrying out the usual operations on the center.


1
Expert's answer
2021-05-28T06:16:39-0400


class PointType{
	private int x;
	private int y;
	
	/**
	 * Constructor
	 * @param x
	 * @param y
	 */
	public PointType(int x,int y){
		this.x=x;	
		this.y=y;
	}
	
	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}
	/**
	 * @param x the x to set
	 */
	public void setX(int x) {
		this.x = x;
	}
	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}
	/**
	 * @param y the y to set
	 */
	public void setY(int y) {
		this.y = y;
	}	
}


class CircleType extends PointType{
	private double radius;
	
	/**
	 * Constructor
	 * @param x
	 * @param y
	 * @param radius
	 */
	public CircleType(int x,int y,double radius) {
		super(x, y);
		this.radius=radius;
	}


	/**
	 * @return the radius
	 */
	public double getRadius() {
		return radius;
	}


	/**
	 * @param radius the radius to set
	 */
	public void setRadius(float radius) {
		this.radius = radius;
	}
	/**
	 * Calculates area
	 * @return
	 */
	public double calculateArea() {
		return Math.PI*Math.pow(radius, 2.0);
	} 
	/**
	 * Calculates circumference
	 * @return
	 */
	public double calculateCircumference() {
		return 2*Math.PI*radius;
	} 
	public void moveLeft() {
		setX(getX()-1);
	} 
	public void moveRight() {
		setX(getX()+1);
	} 
	public void moveUp() {
		setY(getY()+1);
	} 
	public void moveDown() {
		setY(getY()-1);
	} 
}


public class Q199926 {


	public static void main(String[] args) {
		CircleType circleType=new CircleType(10, 10,10);
		System.out.println("Current Circle");
		displayCircle(circleType);
		circleType.moveRight();
		System.out.println("\nMove right");
		displayCircle(circleType);
		circleType.moveLeft();
		System.out.println("\nMove left");
		displayCircle(circleType);
		circleType.moveUp();
		System.out.println("\nMove Up");
		displayCircle(circleType);
		circleType.moveDown();
		System.out.println("\nMove Down");
		displayCircle(circleType);
	}
	/**
	 * Displays circle
	 * @param circleType
	 */
	static void displayCircle(CircleType circleType) {
		System.out.println("Circle X-coordinate: "+circleType.getX());
		System.out.println("Circle Y-coordinate: "+circleType.getY());
		System.out.println("Circle radius: "+circleType.getRadius());
		System.out.println("Circle area: "+circleType.calculateArea());
		System.out.println("Circle circumference: "+circleType.calculateCircumference());
	}
}




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
APPROVED BY CLIENTS