[JAVA] [ *Collections* ] / List / Vector / Iterator / arraylist / toString / String.format

์œค์ˆ˜์ธยท2023๋…„ 12์›” 1์ผ
0

๐Ÿ—‚๏ธ ์˜ค๋ฅ˜ / ์ •๋ฆฌ

๋ชฉ๋ก ๋ณด๊ธฐ
3/19
post-thumbnail

Java์—์„œ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ํด๋ž˜์Šค์— ์บก์Šํ™”๋œ ๊ธฐ๋Šฅ(์•ˆ์ „/์€๋‹‰)๊ณผ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ํด๋ž˜์Šค์—์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑ
: ์บก์Šํ™”?? - private : ์œผ๋กœ ์„ ์–ธ๋˜์–ด ์™ธ๋ถ€์—์„œ ์ง์ ‘์ ์ธ ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค. ๋Œ€์‹ ์—, ํด๋ž˜์Šค๋Š” ์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” public ๋ฉ”์„œ๋“œ(๋˜๋Š” getter์™€ setter)๋ฅผ ์ œ๊ณตํ•˜์—ฌ ๋ฐ์ดํ„ฐ์— ์ ‘๊ทผํ•˜๊ฑฐ๋‚˜ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

์ปฌ๋ ‰์…˜(Collection) :

  • Java ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ๋‹ค์–‘ํ•œ ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ณ ,๊ทธ๋ฃนํ™”ํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ๊ตฌ์กฐ (Java์—์„œ ๋งค์šฐ ์ค‘์š”)

    List (๋ชฉ๋ก):

    ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ๋ฐ์ดํ„ฐ์˜ ์ง‘ํ•ฉ
    ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•œ ์ˆœ์„œ๋Œ€๋กœ ์ €์žฅํ•˜๋ฉฐ, ์ค‘๋ณต๋œ ๊ฐ’ ํ—ˆ์šฉ
    ์˜ˆ์‹œ: ArrayList( ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์‚ญ์ œํ•˜๋Š” ๋ฐ ํšจ์œจ์ ), LinkedList

    Set (์ง‘ํ•ฉ):

    Set์€ ์ค‘๋ณต๋œ ๊ฐ’์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š” ๋ฐ์ดํ„ฐ์˜ ์ง‘ํ•ฉ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ์ˆœ์„œ๊ฐ€ ์ •ํ•ด์ ธ ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    ์˜ˆ์‹œ: HashSet, TreeSet

    Map (๋งต):

    ํ‚ค-๊ฐ’ ์Œ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋ฉฐ, ๊ฐ ํ‚ค๋Š” ๊ณ ์ •
    (๊ฒ€์ƒ‰๊ณผ ์ˆ˜์ •์— ํŠนํ™”)
    ์˜ˆ์‹œ: HashMap, TreeMap

    Queue (ํ):

    Queue๋Š” ์„ ์ž…์„ ์ถœ(FIFO, First-In-First-Out) ๊ตฌ์กฐ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅ
    ์ฃผ๋กœ ์ž‘์—… ๋Œ€๊ธฐ์—ด ๋“ฑ์— ์‚ฌ์šฉ

Stack (์Šคํƒ):

Stack์€ ํ›„์ž…์„ ์ถœ(LIFO, Last-In-First-Out) ๊ตฌ์กฐ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅ ์ฃผ๋กœ ์—ญ์ถ”์ (backtracking)์ด๋‚˜ ์žฌ๊ท€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋“ฑ์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์ปฌ๋ ‰์…˜ ํ”„๋ ˆ์ž„์›Œํฌ(Collection Framework)๋ž€?
๋ฐ์ดํ„ฐ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ์กฐ์ž‘ํ•˜๊ณ  ๊ตฌ์กฐํ™”ํ•  ์ˆ˜ ์žˆ๋„๋ก ์‚ฌ์šฉํ•˜๋Š”

์ปฌ๋ ‰์…˜ ํ”„๋ ˆ์ž„์›Œํฌ์˜ ์ดˆ๊ธฐ ์šฉ๋Ÿ‰(capacity) :
ex) ArrayList(ํด๋ž˜์Šค) : ๋‚ด๋ถ€ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ด์„œ ์š”์†Œ ์ €์žฅ
-> ๋ฐฐ์—ด์˜ ์ดˆ๊ธฐ ์šฉ๋Ÿ‰ : 10 (๋ณ€๊ฒฝ ๊ฐ€๋Šฅ)

๋‚ด๋ถ€์ ์œผ๋กœ ํฌ๊ธฐ ์กฐ์ • ๋ฉ”์ปค๋‹ˆ์ฆ˜์ด ์žˆ์–ด์„œ ๋ฐ์ดํ„ฐ์˜ ์ƒํ™ฉ์— ๋”ฐ๋ผ ์ถ”๊ฐ€, ์ œ๊ฑฐ ๋“ฑ ํ•„์š”์— ๋”ฐ๋ผ ํฌ๊ธฐ ์กฐ์ ˆํ•จ
ex) ArrayList(ํด๋ž˜์Šค) : ๋ฐฐ์—ด ํฌ๊ธฐ๊ฐ€ ๋ถ€์กฑํ•˜๋ฉด ์ž๋„์‘๋กœ ๋” ํฐ ๋ฐฐ์—ด๋กœ ๋ณต์‚ฌ / ์š”์†Œ ์ œ๊ฑฐํ•˜๊ณ ์‹ถ์œผ๋ฉด ์ž๋™์œผ๋กœ ํฌ๊ธฐ ์ค„์ž„

์ธํ„ฐํŽ˜์ด์Šค (Interfaces):

Collection: ๋ชจ๋“  ์ปฌ๋ ‰์…˜ ์ธํ„ฐํŽ˜์ด์Šค์˜ ์ตœ์ƒ์œ„ ์ธํ„ฐํŽ˜์ด์Šค๋กœ, ๊ธฐ๋ณธ์ ์ธ ์ปฌ๋ ‰์…˜ ๋™์ž‘์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
Set: ์ค‘๋ณต์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š” ์š”์†Œ๋“ค์˜ ์ง‘ํ•ฉ์„ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค.
List: ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์š”์†Œ๋“ค์˜ ๋ชฉ๋ก์„ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค.
Queue: ์„ ์ž…์„ ์ถœ(FIFO) ๊ตฌ์กฐ์˜ ์š”์†Œ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
Map: ํ‚ค-๊ฐ’ ์Œ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋ฉฐ, ๊ฐ ํ‚ค๋Š” ๊ณ ์œ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
ํด๋ž˜์Šค (Classes):

์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•œ ๊ตฌ์ฒด์ ์ธ ํด๋ž˜์Šค๋“ค์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.
์˜ˆ์‹œ: ArrayList, LinkedList, HashSet, HashMap ๋“ฑ.
์•Œ๊ณ ๋ฆฌ์ฆ˜ (Algorithms):

๊ฒ€์ƒ‰, ์ •๋ ฌ, ๋ณต์‚ฌ ๋“ฑ ๋‹ค์–‘ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ œ๊ณต๋˜์–ด ํšจ์œจ์ ์ธ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
์˜ˆ์‹œ: Collections.sort(), Collections.binarySearch() ๋“ฑ.
๋™๊ธฐํ™” (Synchronization):

๋ฉ€ํ‹ฐ์Šค๋ ˆ๋“œ ํ™˜๊ฒฝ์—์„œ ์•ˆ์ „ํ•˜๊ฒŒ ์ปฌ๋ ‰์…˜์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋™๊ธฐํ™”๋œ ์ปฌ๋ ‰์…˜๋„ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.
์˜ˆ์‹œ: Collections.synchronizedList(), Collections.synchronizedMap() ๋“ฑ.
Utility ๋ฉ”์„œ๋“œ (Utility Methods):

Collections ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ์œ ์šฉํ•œ ๋ฉ”์„œ๋“œ๋“ค์ด ์ œ๊ณต๋˜์–ด ๋ฐ์ดํ„ฐ ์กฐ์ž‘์„ ๊ฐ„ํŽธํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ์‹œ: Collections.addAll(), Collections.max(), Collections.shuffle() ๋“ฑ.

์ธํ„ฐํŽ˜์ด์Šค (์ €์žฅ๊ณต๊ฐ„์œผ๋กœ๋„ ์‚ฌ์šฉ)

  • Collection :

    โ‘  ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ํ•ด์„œ ๋ชจ์•„๋†“๋Š” ๊ฒƒ
    โ‘ก ๋ฐฐ์—ด์ด๋ž‘ ๋˜‘๊ฐ™์ง€๋งŒ, ์ปฌ๋ ‰์…˜ ํ”„๋ ˆ์ž„์›Œํฌ์˜ ์ดˆ๊ธฐ ์šฉ๋Ÿ‰(capacity) : ๊ธฐ๋ณธ default ์šฉ๋Ÿ‰ = 10๊ฐœ / ๋ฐ์ดํ„ฐ๊ฐ€ ์•Œ์•„์„œ ๋Š˜์–ด๋‚˜๊ณ , ์ค„์ด๋Š”๊ฑด ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๊ฐ€๋Šฅ
    ex) List, Vector, Set, Map, LinkedList, HashSet, TreeSet, Hashtable

    -------------------------------------------------------------------------------

  • list(์ธํ„ฐํŽ˜์ด์Šค) - Vector (ํด๋ž˜์Šค) : ๋™๊ธฐํ™” ์ง€์› โ†’ ArrayLsit๋ณด๋‹ค ๋Š๋ฆผ

  • list(์ธํ„ฐํŽ˜์ด์Šค) - ArrayLsit (ํด๋ž˜์Šค) : ๋™๊ธฐํ™” ์ง€์› X โ†’ Vector๋ณด๋‹ค ๋น ๋ฆ„

    -------------------------------------------------------------------------------

  • Iterator :

    Collection ๊ฐ์ฒด๋ฅผ ๋Œ์•„๋‹ค๋‹ˆ๋ฉด์„œ ์ ‘๊ทผํ•˜๊ณ , Collection์˜ ๋‚ด์šฉ์„ ์ˆœ์„œ๋Œ€๋กœ ์ฝ์„ ์ˆ˜ ์žˆ์Œ
lterator <String> it = lists.iterator( );
while( it.hasNext() ) {
  String s = it.next( );
  System.out.println(s);

โ‘  Collection Framework(๋ฐฉ๋ฒ•๋“ค)์—์„œ ๋งŽ์ด ์‚ฌ์šฉ
โ‘ก Iterator ๋ฉ”์„œ๋“œ :
- hasNext( ) : ๋‹ค์Œ๊ฑฐ๋ฅผ ํ™•์ธํ•˜๋Š” ๋ฉ”์„œ๋“œ
- boolean hasNext( ) : ๋‹ค์Œ ์กด์žฌํ™•์ธ (o - true / x - false)
- void remove( ) : ๋Œ์•„๋‹ค๋‹ˆ๋Š” ์š”์†Œ๋ฅผ ์‚ญ์ œ, ์ผ๋ถ€๋Š” ์ง€์› ๋ถˆ๊ฐ€ํ•  ์ˆ˜๋„ ์žˆ์Œ


-------------------------------------------------------------------------------

list :

โ‘  Collection Framework์—์„œ ์ œ๊ณตํ•˜๋Š” Interface
โ‘ก ๋ฐฐ์—ด์˜ ์ผ์ข…์ธ๋ฐ, ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ๋ฐ์ดํ„ฐ์˜ ์ง‘ํ•ฉ
โ‘ข ์ˆœ์„œ ์œ ์ง€ (Ordering) : ์‚ฝ์ž…๋œ ์ˆœ์„œ๋Œ€๋กœ ์œ ์ง€ํ•จ โ†’ index๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Œ
โ‘ฃ ์ค‘๋ณต ํ—ˆ์šฉ : ๋™์ผํ•œ ์š”์†Œ๋ฅผ ์ค‘๋ณตํ•ด์„œ ์ €์žฅ ๊ฐ€๋Šฅ
โ‘ค list ๋ฉ”์„œ๋“œ :
- boolen add(E element) : ๋ฆฌ์ŠคํŠธ์— ์š”์†Œ ์ถ”๊ฐ€
- void add(int index, E element) : index์— ์š”์†Œ ์‚ฝ์ž…
- get(int index): indext ๋ฐ˜ํ™˜
- int size( ) : ๋ฆฌ์ŠคํŠธ ํฌ๊ธฐ ๋ฐ˜ํ™˜
- boolean remove(Object o) : ๋ฆฌ์ŠคํŠธ์—์„œ ์ œ๊ฑฐ
- E remove (int index) : ์ง€์ •๋œ index์„ ๋ฆฌ์ŠคํŠธ์—์„œ ์ œ๊ฑฐํ•˜๊ณ , ๋ฐ˜ํ™˜ํ•จ
- void clear( ) : ๋ฆฌ์ŠคํŠธ ๋ชจ๋“  ์š”์†Œ ์ œ๊ฑฐ
โ‘ฅ list๋ฅผ ์ด๋ฏธ ๋งŒ๋“  ์ฃผ์š” ํด๋ž˜์Šค : ArrayList / Vector / LinkedList...

toString :

  • ์ž๋ฐ”์—์„œ ๋ชจ๋“  ํด๋ž˜์Šค๊ฐ€ ์ƒ์†๋ฐ›๋Š” ๋ฉ”์„œ๋“œ
  • ๊ฐ์ฒด์˜ ํด๋ž˜์Šค ์ด๋ฆ„ / ํ•ด์‹œ์ฝ”๋“œ์„ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜
  • ๋‚ด๊ฐ€ ๋งŒ๋“  ํด๋ž˜์Šค์—์„œ toString( )์„ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•ด์„œ ๊ฐ์ฒด ๋‚ด๋ถ€์ƒํƒœ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๊ตฌํ˜„ํ•  ์ˆ˜ ์ž‡์Œ

String.format :

  • ์ง€์ •๋œ ํ˜•์‹์— ๋งž์ถฐ์„œ ๋ฌธ์ž์—ด ์ƒ์„ฑ๊ฐ€๋Šฅ
  • 'format' = ์ถœ๋ ฅํ•  ๋ฌธ์ž์—ด ํ˜•์‹ ์ง€์ •
    : %๊ธฐํ˜ธ์™€ ๋‹ค์–‘ํ•œ ํ˜•์‹์ง€์ •์ž(์ถœ๋ ฅํ•  ๊ฐ’์˜ ํƒ€์ž…์— ๋”ฐ๋ผ ์ง€์ •)๋กœ ๊ตฌ์„ฑ
    : ์ž˜ ๋‹ด์•„๋†จ๋‹ค๊ฐ€ ์˜ˆ์˜๊ฒŒ ๊พธ๋ฉฐ์„œ ๋ฆฌํ„ด๊ฐ’์œผ๋กœ ๋ฐ˜ํ™˜ํ•ด๋‹ฌ๋ผ๋Š” ๋œป

Test1-1.[ ์ธํ„ฐํŽ˜์ด์Šค ] - Score

Test1-1

๐Ÿ’ป ์ž…๋ ฅ

public interface Score {

	public int input();
	public void print();

}

๐Ÿ’ก **์ถœ๋ ฅ**
์ •์ˆ˜ ์ž…๋ ฅ?32
32์€ ์ง์ˆ˜์ž…๋‹ˆ๋‹ค.


๐Ÿ“Œ Note Code



Test1-2. [ ์ž์‹ํด๋ž˜์Šค ] - ScoreImpl

Test1-2

๐Ÿ’ป ์ž…๋ ฅ


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class ScoreImpl implements Score {

	
	private List<ScoreVO> lists = new ArrayList<ScoreVO>();
	//list = ๋ฐฐ์—ด๋งŒ๋“œ๋Š” ์ธํ„ฐํŽ˜์ด์Šค - arraylist = ํด๋ž˜์Šค
	// ์•„๋ž˜ input()๋ฉ”์„œ๋“œ์— ์•ˆ๋„ฃ๊ณ  private๋กœ ํ•ด์„œ ์ง์›๊ณต์œ ํ•˜๋Š” ์ด์œ  : ๋ฉ”์„œ๋“œ์•ˆ์— ๋„ฃ์œผ๋ฉด new๊ฐ์ฒด๊ฐ€ ๊ณ„์† ๋งŒ๋“ค์–ด์ ธ์„œ ๊ฐ์ž ๋‹ค๋ฅธ ์ฃผ์†Œ๊ฐ€ ๋จ
    
    
	@Override
	public int input() {
		
		int result = 0; 
		
		Scanner sc = new Scanner(System.in);
		
		ScoreVO vo = new ScoreVO(); //input ์‹คํ–‰ ํ• ๋•Œ๋งˆ๋‹ค ํ•œ๋ฒˆ ์ซ™ ์‹ ์ƒ ๋‹ค ๋ฐ›์•„๋‚ด๋‹ˆ๊นŒ forํ•„์š”์—†์Œ
	
		System.out.print("ํ•™๋ฒˆ?");
		vo.setHak(sc.next()); // set์— ์˜ํ•ด ๊ฐ’์ด ๋“ค์–ด๊ฐ
		
		System.out.print("์ด๋ฆ„?");
		vo.setName(sc.next());
		
		System.out.print("๊ตญ์–ด?");
		vo.setKor(sc.nextInt());
		
		System.out.print("์˜์–ด?");
		vo.setEng(sc.nextInt());
		
		System.out.print("์ˆ˜ํ•™?");
		vo.setMat(sc.nextInt());
		
		lists.add(vo);
		
		
		return result;
	}


	@Override
	public void print() {
		
		Iterator<ScoreVO> it = lists.iterator(); //vo์˜ ๋ฐ์ดํ„ฐ ํƒ€์ž… = scorevo
		
		//vo = 5๊ฐœ ๋ณ€์ˆ˜,getter,setter,print 
		
		while(it.hasNext()) {
			
			ScoreVO vo = it.next();
			
			System.out.println(vo); //toString์•ˆ์จ๋„ ์ถœ๋ ฅ๊ฐ€๋Šฅ
			//System.out.println(vo.toString()); 
			
		}
		
	}

}

Test1-3. [ Score ๋ฐ์ดํ„ฐ ์ €์žฅ๊ณต๊ฐ„ ] - ScoreVO

Test1-3

๐Ÿ’ป ์ž…๋ ฅ


public class ScoreVO {// Value Object : ์—ฌ๊ธฐ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ• ๊บผ์•ผ
//VO๋ฅผ ์“ฐ๋ฉด ๋ฐ์ดํ„ฐ์ €์žฅ์†Œ 
//VO์•ˆ์“ฐ๊ณ  DB์™€ ์—ฐ๋™ํ•˜๋ฉด -?DTO 

	private String hak, name;
	private int kor;
	private int eng;
	private int mat;
	
	
	public String getHak() {
		return hak;
	}
	public void setHak(String hak) {
		this.hak = hak;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getKor() {
		return kor;
	}
	public void setKor(int kor) {
		this.kor = kor;
	}
	public int getEng() {
		return eng;
	}
	public void setEng(int eng) {
		this.eng = eng;
	}
	public int getMat() {
		return mat;
	}
	public void setMat(int mat) {
		this.mat = mat;
	}

	@Override //ScoreVO์˜ ๋ถ€๋ชจ - object  
	public String toString() { //๋ชจ๋“ ํƒ€์ž…์„ ๋‹ค ๋ฌธ์ž๋กœ ๋ณด์—ฌ์ค˜
		
		String str;
		
		//์ŠคํŠธ๋งํฌ๋งท ?  ์ž˜ ๋‹ด์•„๋†จ๋‹ค๊ฐ€ ์˜ˆ์˜๊ฒŒ ๊พธ๋ฉฐ์„œ ๋ฆฌํ„ด๊ฐ’์œผ๋กœ ์ค˜ 
		str = String.format("%5s %6s %4d %4d %4d %4d %4d",hak,name,
				kor,eng,mat,(kor+eng+mat),(kor+eng+mat)/3);
		
		return str;
	}

	// get/set

}

Test1-5. ScoreMain

Test1-5

๐Ÿ’ป ์ž…๋ ฅ


import java.util.Scanner;

public class ScoreMain {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		
		//input,print๊ฐ€ ํด๋ž˜์Šค๋ผ์„œ ๊ฐ์ฒด ์ƒ์„ฑ
		
		//์ธํ„ฐํŽ˜์ด์Šค - ํด๋ž˜์Šค
		Score ob = new ScoreImpl();
	//	Score ob = new ScoreImpl();
		
	int ch;
	while (true) {

		do {
			System.out.print("1.์ž…๋ ฅ? 2.์ถœ๋ ฅ 3.์ข…๋ฃŒ?");
			ch = sc.nextInt(); // ์‚ฌ์šฉํ•œํ…Œ ๋ฐ›์€ ๊ฐ’์„ ch์— ๋ฐ›์„๊ฑฐ์•ผ

		} while (ch < 1); //ch>3์„ ์•ˆ์“ด ์ด์œ ๋Š” ์•„๋ž˜ switch๋ฌธ์—์„œ default๊ฐ’์„ 3๋ฒˆ ์ดํ›„์—๋Š” ๋‹ค ์ข…๋ฃŒํ• ๊ฑฐ๊ธฐ๋•Œ๋ฌธ์—

		switch (ch) {

		case 1:
			ob.input();
			break;
		case 2:
			ob.print();
			break;
		default:
			System.exit(0);//์›๋ž˜๋Š” return์ธ๋ฐ, ์ข…๋ฃŒ์‹œํ‚ค๊ณ ์‹ถ์œผ๋‹ˆ๊นŒ - ์ž๋ฐ”ํ”„๋กœ๊ทธ๋žจ ๊ฐ•์ œ ์ข…๋ฃŒ ๋ช…๋ น์–ด
			}

		}
	
	}

}

๐Ÿ’ก **์ถœ๋ ฅ**
1.์ž…๋ ฅ? 2.์ถœ๋ ฅ 3.์ข…๋ฃŒ?1
ํ•™๋ฒˆ?2015
์ด๋ฆ„?์ˆ˜์ง€
๊ตญ์–ด?10
์˜์–ด?20
์ˆ˜ํ•™?30
1.์ž…๋ ฅ? 2.์ถœ๋ ฅ 3.์ข…๋ฃŒ?2
 2015     ์ˆ˜์ง€   10   20   30   60   20
1.์ž…๋ ฅ? 2.์ถœ๋ ฅ 3.์ข…๋ฃŒ?1
ํ•™๋ฒˆ?2015
์ด๋ฆ„?์ˆ˜์ธ
๊ตญ์–ด?50
์˜์–ด?60
์ˆ˜ํ•™?70
1.์ž…๋ ฅ? 2.์ถœ๋ ฅ 3.์ข…๋ฃŒ?2
 2015     ์ˆ˜์ง€   10   20   30   60   20
 2015     ์ˆ˜์ธ   50   60   70  180   60
1.์ž…๋ ฅ? 2.์ถœ๋ ฅ 3.์ข…๋ฃŒ?

profile
์–ด์ œ๋ณด๋‹ค ์กฐ๊ธˆ ๋” ์„ฑ์žฅํ•˜๊ธฐ!

0๊ฐœ์˜ ๋Œ“๊ธ€