day14_RectangleTest

육희영·2021년 10월 28일
0
package com.java1.day14;

class Shape1 {
	public int x;
	public int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	void print() {
		System.out.println("x좌표: " + x + "y좌표: " + y);
	}
}

class Rectangle extends Shape1 {
	private int width;
	private int height;

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	double area() {
		return (double) width * height;
	}

	void draw() {
		System.out.println("(" + this.getX() + "," + this.getY() + ") 위치에 " + "가로: " + width + "세로: " + height);
	}
}

public class RectangleTest {
	public static void main(String[] args) {
		Rectangle r1 = new Rectangle();
		Rectangle r2 = new Rectangle();

		r1.setX(5);
		r1.setY(3);
		r1.setWidth(10);
		r1.setHeight(20);

		r2.setX(8);
		r2.setY(9);
		r2.setWidth(10);
		r2.setHeight(20);

		r1.print();
		r1.draw();
		r2.print();
		r2.draw();

	}
}

출력결과

x좌표: 5y좌표: 3
(5,3) 위치에 가로: 10세로: 20
x좌표: 8y좌표: 9
(8,9) 위치에 가로: 10세로: 20

0개의 댓글

Powered by GraphCDN, the GraphQL CDN