MapleStory Finger Point Cute Line Smiley Blinking Hello Kitty Angel MapleStory Finger Point

πŸ’Ž JAVA/πŸ“šλͺ…ν’ˆ JAVA_ESSENTIAL

Λšβ‚Šβœ©β€§β‚Š [λͺ…ν’ˆ JAVA ESSENTIAL] CH5 μ‹€μŠ΅λ¬Έμ œ Λšβ‚Šβœ©β€§β‚Š

HYEJU01 2021. 11. 13. 16:24
"κ°œμ •νŒ: λͺ…ν’ˆ JAVAESSENTIAL(ν™©κΈ°νƒœ)"κ΅μž¬μ— 수둝된 λ¬Έμ œλ“€μ„ ν’€μ–΄μ„œ μ˜¬λ¦½λ‹ˆλ‹€.
문제의 번호만 ν‘œκΈ°ν•˜κ³  λ‹΅μ•ˆλ§Œ μ λŠ” ν˜•νƒœλ‘œ μ—…λ‘œλ“œ ν•˜κ³ μžˆμŠ΅λ‹ˆλ‹€.
개인 ν’€μ΄μ΄λ―€λ‘œ μ˜€λ‹΅μ΄ μžˆμ„ 수 있으며 μ˜€λ‹΅ 발견 μ‹œ λŒ“κΈ€ λ‚¨κ²¨μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€πŸ˜Š
-
#이 ν‘œμ‹œλœ 건 아직 풀지 λͺ»ν•œ 문제 or ν—·κ°ˆλ¦¬λŠ” λ¬Έμ œμž…λ‹ˆλ‹€!
좔후에 λ‹€μ‹œ ν’€μ–΄μ„œ 올릴 μ˜ˆμ •μ΄μ—μš”!

-ujeyhx-

 

 

πŸ”Žμ‹€μŠ΅λ¬Έμ œ

 

1)

class Circle {
	private int radius;
	public Circle(int radius) {this.radius = radius;}
	public int getRadius() { return radius;}
}

class NamedCircle extends Circle {
	String name;
	public NamedCircle(int radius, String name) {
		super(radius);
		this.name = name;
	}
	public void show() {
		System.out.print(name + " , λ°˜μ§€λ¦„ = " + getRadius() );
	}
}

public class TEST{
public static void main (String[] args) {
	NamedCircle w = new NamedCircle(5, "waffle");
	w.show();
}
}


2)

interface AdderInterface{
	int add(int x, int y); //public abstract μƒλž΅μƒνƒœ
	int add(int n);
}

class MyAdder implements AdderInterface{ //μΈν„°νŽ˜μ΄μŠ€κ΅¬ν˜„
	
    @Override
    public int add(int x, int y) {
		return x+y;
	}
    
    @Override
	public int add(int n) {
		int sum=0;
			for (int i=1; i<=n; i++) {
				sum += i;
			}
		return sum;
		
	}
}

public class TEST{
public static void main (String[] args) {
	MyAdder adder = new MyAdder();
	System.out.println(adder.add(5,10));
	System.out.println(adder.add(10));
}
}


3)

import java.util.Scanner;

abstract class Calculator{
	protected int a,b;
	abstract protected int calc();
	protected void input() {
		Scanner sc = new Scanner(System.in);
		System.out.print("μ •μˆ˜ 2개λ₯Ό μž…λ ₯ν•˜μ„Έμš” >>");
		a = sc.nextInt();
		b = sc.nextInt();
	}

public void run() {
	input();
	int res = calc();
	System.out.println("κ³„μ‚°λœ 값은 " + res);
	
}
}

class Adder extends Calculator{	
	public int calc() {
		return a+b;
	}
}

class Subtracter extends Calculator{ //μΆ”μƒν΄λž˜μŠ€ κ΅¬ν˜„ν•˜λ©΄ μΌλ°˜ν΄λž˜μŠ€κ°€ 됨
	public int calc() {
		return a-b;
	}
}


public class TEST {
	public static void main (String[] args) {
		Adder adder = new Adder();
		Subtracter sub = new Subtracter();
		
		adder.run();
		sub.run();
	}
}


4)

class Point {
	private int x,y;
	public Point (int x, int y) {
		this.x = x;
		this.y = y;
	}
	public int getX() {
		return x;
	}
	public int getY() {
		return y;
	}
	protected void move(int x, int y) {
		this.x = x;
		this.y = y;
	}

}


class ColorPoint extends Point{
	
	String color;
	
	public ColorPoint(int x, int y, String color) {
		super(x, y);
		this.color = color;
	}

	public void setPoint(int x, int y) {
		move(x,y);
	}
	
	public void setColor(String color) {
		this.color = color;
	}
	
	public void show() {
		System.out.print(color+"μƒ‰μœΌλ‘œ("+ getX() + "," + getY() +")");
	}
}



public class TEST {
	public static void main (String[] args) {
		ColorPoint cp = new ColorPoint(5,5,"YELLOW");
		cp.setPoint(10,20);
		cp.setColor("GREEN");
		cp.show();
	}
}


# 5)

더보기

import java.util.Scanner;
import java.util.Stack;

interface StackInterface {
int length();
String pop();
boolean push(String ob);
}


class StringStack implements StackInterface{

int length;

Stack<String> stack = new Stack<>();

@Override
public int length() {
return this.length;
}
@Override
public String pop() {

for (int i =0; i<length(); i++) {
System.out.print(stack.pop());
}

return stack.pop();
}

@Override
public boolean push(String ob) {
if (stack.empty()) {
stack.push(ob);
}
return stack.empty();
}



}


public class TEST {
public static void main (String[] args) {

StringStack ss = new StringStack();

Scanner sc = new Scanner(System.in);

System.out.print(">>");

for (int i =0; i<5; i++) {
ss.push(sc.next());
}




}
}

 

import java.util.Scanner;

interface StackInterface {
	int length();
	String pop();
	boolean push(String ob);
}


class StringStack implements StackInterface {
	
	private String[] element;
	
	private int index;
	
	public StringStack(int capacity) {
		element = new String[capacity];
		index = 0; // μ•žμœΌλ‘œ λ“€μ–΄κ°ˆ λ°°μ—΄μ˜ 인덱슀 
	}
	
	@Override
	public int length() {
		return index;
	}

	@Override
	public String pop() {
		if(index == 0) // μŠ€νƒμ΄ λΉ„μ—ˆμŒ
			return null;
		index--; // μŠ€νƒ 포인터 κ°μ†Œ
		return element[index];
	}

	@Override
	public boolean push(String ob) {
		if(index == element.length)
			return false; // μŠ€νƒμ΄ λ‹€ 찼음
		element[index++] = ob; // μš”μ†Œ μŠ€νƒμ— μ €μž₯ ν›„ μŠ€νƒ 포인터 증가
		return true;
	}
}


public class TEST {
	public static void main (String[] args) {
		
		StringStack ss = new StringStack(10);
		Scanner sc = new Scanner(System.in);
		
		System.out.print(">>");
		for (int i=0; i<5; i++) {
			String text = sc.next();
			ss.push(text);
		}
			
		int cnt = ss.length();
		
		for (int i=0;i<cnt; i++)
			System.out.print(ss.pop()+" ");
		
		sc.close();
	}
}


#κ΅¬ν˜„ λ„ˆλ¬΄ λ³΅μž‘ν•΄μ Έμ„œ λ‹€μ‹œ μ•Œμ•„λ³΄κ³  ν’€μ–΄μ•Όκ² μŒ

6)

import java.util.Scanner;


abstract class Shape {
	public abstract void draw();
}

class Line extends Shape {
	@Override
	public void draw() {
		System.out.print("Line");
	}
}

class Rect extends Shape {
	@Override
	public void draw() {
		System.out.print("Rect");
	}
}

class Circle extends Shape {
	@Override
	public void draw() {
		System.out.print("Circle");
	}
}

public class TEST {
	
	static void paint(Shape p) {
		p.draw();
	}
	
	public static void main (String[] args) {
		Line l = new Line();
		int cnt = 0;
		Shape[] s = new Shape[cnt];
		Scanner sc = new Scanner(System.in);

		while(true) {
			System.out.print("μ‚½μž…(1),μ‚­μ œ(2), λͺ¨λ‘λ³΄κΈ°(3), μ’…λ£Œ(4)>>");
			int num = sc.nextInt();

			switch(num){
				case 1: 
				
					cnt++;
					while(true) {
						System.out.print("λ„ν˜• μ’…λ₯˜ Line(1), Rect(2), Circle(3)>>");
						int num2 = sc.nextInt();
						switch(num2){
							case 1: 
								s[cnt] = l;
								break;
							case 2:
								s[cnt] = new Rect();
								break;
							case 3:
								s[cnt] = new Circle();
								break;
							default: System.out.print("잘λͺ»μž…λ ₯ν•˜μ…¨μŠ΅λ‹ˆλ‹€."); 
						}
					break;
					}
			break;
			
					
			case 2:
					System.out.print("μ‚­μ œν•  λ„ν˜•μ˜ μœ„μΉ˜>>");
					int pos = sc.nextInt();
					if (pos<s.length) { // μœ„μΉ˜κ°’μ΄λž‘ κ°’ 넣은 κ±°λž‘ 
						System.out.println("μ‚­μ œν•  수 μ—†μŠ΅λ‹ˆλ‹€.");
						System.out.println();
					}	
					else {
						//μ‚­μ œμ½”λ“œ
						System.out.println("μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
					}
					break;
				case 3:
					for (int i=0; i<s.length; i++) {
						paint(s[i]);
						System.out.println();
					}
					break;
				case 4:
					System.out.print("ν”„λ‘œκ·Έλž¨μ„ μ’…λ£Œν•©λ‹ˆλ‹€...");
					break;
				default: System.out.print("잘λͺ»μž…λ ₯ν•˜μ…¨μŠ΅λ‹ˆλ‹€."); 
			}
			
		}
	}
}

 


bouns1)

interface Shape {
	final double PI = 3.14;
	void draw();
	double getArea();
	default public void redraw() {
		System.out.println("--λ‹€μ‹œκ·Έλ¦½λ‹ˆλ‹€---");
		draw();
	}
}

class Circle implements Shape{
	int radius;
	
	public Circle(int radius) {
		this.radius = radius;
	}
	public void draw() {
		System.out.print("λ°˜μ§€λ¦„" + radius);
	}
	public double getArea() {
		return radius* radius * PI;
	}
}


public class TEST {
	public static void main (String[] args) {
	Shape coin = new Circle(10);
	coin.redraw();
	System.out.println(" μ½”μΈμ˜ 면적은 " + coin.getArea());
	}
}