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

๐Ÿ’Ž JAVA/๐Ÿ“š๋ช…ํ’ˆ JAVA_ESSENTIAL

หšโ‚Šโœฉโ€งโ‚Š [๋ช…ํ’ˆ JAVA ESSENTIAL] CH4 ์‹ค์Šต๋ฌธ์ œ หšโ‚Šโœฉโ€งโ‚Š

HYEJU01 2021. 10. 11. 19:53

 

"๊ฐœ์ •ํŒ: ๋ช…ํ’ˆ JAVAESSENTIAL(ํ™ฉ๊ธฐํƒœ)"๊ต์žฌ์— ์ˆ˜๋ก๋œ ๋ฌธ์ œ๋“ค์„ ํ’€์–ด์„œ ์˜ฌ๋ฆฝ๋‹ˆ๋‹ค.
๋ฌธ์ œ์˜ ๋ฒˆํ˜ธ๋งŒ ํ‘œ๊ธฐํ•˜๊ณ  ๋‹ต์•ˆ๋งŒ ์ ๋Š” ํ˜•ํƒœ๋กœ ์—…๋กœ๋“œ ํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ฐœ์ธ ํ’€์ด์ด๋ฏ€๋กœ ์˜ค๋‹ต์ด ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ ์˜ค๋‹ต ๋ฐœ๊ฒฌ ์‹œ ๋Œ“๊ธ€ ๋‚จ๊ฒจ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค๐Ÿ˜Š
-
#์ด ํ‘œ์‹œ๋œ ๊ฑด ์•„์ง ํ’€์ง€ ๋ชปํ•œ ๋ฌธ์ œ or ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค!
์ถ”ํ›„์— ๋‹ค์‹œ ํ’€์–ด์„œ ์˜ฌ๋ฆด ์˜ˆ์ •์ด์—์š”!

-ujeyhx-

 

๐Ÿ”Ž์‹ค์Šต๋ฌธ์ œ

 

 

1)

class Song {
	
	String title; 
	
	public Song(String t) {
		title = t;
	}

	public String getTitle() {
		return title;
	}
	
}


public class TEST {

	public static void main(String[] args) {
		
	Song mySong = new Song("Nessun Dorma");
	Song yourSong = new Song("๊ณต์ฃผ๋Š” ์ž  ๋ชป ์ด๋ฃจ๊ณ ");
	System.out.println("๋‚ด ๋…ธ๋ž˜๋Š” " + mySong.getTitle());
	System.out.println("๋„ˆ์˜ ๋…ธ๋ž˜๋Š” " + yourSong.getTitle());
		
	}
}

 

 


2)

import java.util.Scanner;

class Phone {
	
	private String name, tel; 
	public Phone (String name, String tel) {
		this.name = name;
		this.tel = tel;
	}	

	public String getName() {return name; }
	public String getTel() {return tel;}
}


public class TEST {

	public static void main(String[] args) {
	
	Phone []num = new Phone[2];
	Scanner sc = new Scanner(System.in);
	
	for (int i=0; i<num.length;i++) {
		System.out.print("์ด๋ฆ„๊ณผ ์ „ํ™”๋ฒˆํ˜ธ ์ž…๋ ฅ>> ");
		String x = sc.next();
		String y = sc.nextLine();
		num[i]= new Phone(x,y);
	}
	
	for (int i=0; i<num.length;i++) {
		System.out.println(num[i].getName() + "์˜ ๋ฒˆํ˜ธ " + num[i].getTel());
	}
	
	}
}

 

 


3)

import java.util.Scanner;

class Rect {
	private int width, height;
	public Rect(int width , int height) {
		this.width = width; //this -> private
		this.height = height;
	}
	public int getArea() {return width*height;}
}


public class TEST {
	public static void main(String[] args) {
		Rect []rect = new Rect[4];
		Scanner sc = new Scanner(System.in);
		
		for (int i=0; i<rect.length; i++) {
			System.out.print( i+1 + " ๋„ˆ๋น„์™€ ๋†’์ด>> ");
			int x = sc.nextInt(); //๋„ˆ๋น„
			int y = sc.nextInt(); //๋†’์ด
			rect[i]= new Rect(x,y);
		}	
		System.out.println("์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค...");
		int sum = 0;
		for (int i=0; i<rect.length; i++) {
			sum += rect[i].getArea();
		}
		System.out.println("์‚ฌ๊ฐํ˜• ์ „์ฒด ํ•ฉ์€ " + sum);
	
		sc.close();
	}
}

 


#  4)

//๊ฐ’ ์ €์žฅ ์ œ๋Œ€๋กœ ์•ˆ๋จ , exit ์ž…๋ ฅํ• ๋•Œ elseif ๋ถ€๋ถ„๋„ ๋™์‹œ์— ์ถœ๋ ฅ๋จ



import java.util.Scanner;

class Phone {
	
	private String name, tel; 
	public Phone (String name, String tel) {
		this.name = name;
		this.tel = tel;
	}	

	public String getName() {return name; }
	public String getTel() {return tel;}
}


public class TEST {

	public static void main(String[] args) {
	
	Scanner sc = new Scanner(System.in);
	System.out.print("์ธ์›์ˆ˜>> ");
	int nmbrPpl = 0;
	nmbrPpl = sc.nextInt();
	
	Phone []num = new Phone[nmbrPpl];
	
	for (int i=0; i<num.length;i++) {
		
		System.out.print("์ด๋ฆ„๊ณผ ์ „ํ™”๋ฒˆํ˜ธ(๋ฒˆํ˜ธ๋Š” ์—ฐ์†์ ์œผ๋กœ ์ž…๋ ฅ)>> ");
		String x = sc.next();
		String y = sc.nextLine();
		num[i]= new Phone(x,y);
		
	}
	
	System.out.println("์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค...");
	

	while (true) {
		System.out.print("๊ฒ€์ƒ‰ํ•  ์ด๋ฆ„>>");
		String name = sc.nextLine();
		
		for (int i=0; i<num.length;i++) {
		String [] name1 = new String[num.length]; 
		name1[i] = num[i].getName();
			
		if(name.equals(name1[i])) {
				System.out.println(name1[i]+ "์˜ ๋ฒˆํ˜ธ๋Š” "+ num[i].getTel());
				break;
			}
		else if (!(name.equals(name1[i]))) {
				System.out.println(name + "์ด ์—†์Šต๋‹ˆ๋‹ค");
				break;
			}
		
		if(name.equals("exit")) {
			System.out.print("ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค...");
			break;
		}

	
		}
	}
	
	
	}
}

 

 


5) 

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

class CircleManager{
	static void copy(Circle src, Circle dest) {
		dest.setRadius(src.getRadius());
	}
	static boolean equals(Circle a, Circle b) {
		if (a.getRadius()==b.getRadius()) {
			return true;
		}
		else {
			return false;
		}
	}
}


public class TEST{
	public static void main(String[] args) {
		Circle pizza = new Circle(5);
		Circle waffle =new Circle(1);
		
		boolean res = CircleManager.equals(pizza, waffle);
		if (res == true)
			System.out.println("pizza์™€ waffle ํฌ๊ธฐ ๊ฐ™์Œ");
		else
			System.out.println("pizza์™€ waffle ํฌ๊ธฐ ๋‹ค๋ฆ„");
		
		CircleManager.copy(pizza, waffle);
		res = CircleManager.equals(pizza, waffle);
		if(res==true)
			System.out.println("pizza์™€ waffle ํฌ๊ธฐ ๊ฐ™์Œ");
		else
			System.out.println("pizza์™€ waffle ํฌ๊ธฐ ๋‹ค๋ฆ„");
	}
}

 


6) 

public class TEST{
	private int width, height;
	private char fillchar;
	public TEST() {
		this(10,1);
	}
	public TEST(int width, int height) {
		this.width = width;
		this.height = height;
	}
	
	public void draw() {
		for (int i=0; i<height; i++) {
			for (int j=0; j<width; j++) {
				System.out.print(fillchar);
			}
			System.out.println();
		}
	}
	
	public void fill(char c) {
		fillchar = c;
	}
	
	public static void main(String[] args) {
		TEST a = new TEST();
		TEST b = new TEST(20,3);
		a.fill('*');
		b.fill('%');
		a.draw();
		b.draw();
	}
}

 


Bonus 1)

import java.util.Scanner;
class Player{
	private String name;
	public Player (String name) { this.name = name; }
	public String getName() { return name;}
}

public class TEST{
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		Player [] p = new Player[2];
		for (int i = 0; i<p.length; i++) {
			System.out.print("์„ ์ˆ˜์ด๋ฆ„์ž…๋ ฅ >>");
			p[i] = new Player(sc.next());
		}
	
		int n = 0;
		while(true) {
		System.out.print(p[n].getName() + "<Enter ์™ธ์— ์•„๋ฌดํ‚ค๋‚˜ ์น˜์„ธ์š”>");
		sc.next();
		int [] val = new int [3];
		for(int i=0; i<val.length; i++) {
			val[i] = (int)(Math.random()*3);
			System.out.print(val[i] + "\t");
		}
		System.out.println();
		if(val[0] == val[1] && val[1] == val[2]) {
			System.out.print(p[n].getName() + "์Šน๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
			break;
		}
		n++;
		n = n%2;
		}
		sc.close();

	}
}