티스토리 뷰

1. 자바

Array - Player.java

패스트코드블로그 2020. 8. 14. 17:11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package oop;
 
import java.util.Scanner;
class Player {
    private String name;
    private int record;
    
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return this.name;
    }
    public void setRecord(int record) {
        this.record = record;
    }
    public int getRecord() {
        return this.record;
    }
    public void showRecord() {
        System.out.println("이름: "+name+", 기록: "+record+"초");
    }
}
public class PlayerApp {
    public static void main(String[] args) {
         Scanner scanner = new Scanner(System.in);
         Player[] players = new Player[3];
         for(int i=0;i<players.length;i++) {
             Player player = new Player();
             System.out.println("이름: ");
             String name = scanner.next();
             player.setName(name);
             System.out.println("100M 기록: ");
             int time = scanner.nextInt();
             player.setRecord(time);
             players[i] = player;
         }
         
         for(int i=0;i<players.length;i++) {
             players[i].showRecord();
         }
         
         Player[] ranking = new Player[3];
         String name = "";
         if(players[0].getRecord() < players[1].getRecord()
                 && players[0].getRecord()< players[2].getRecord()) {
             name = players[0].getName();
         }else if(players[1].getRecord() < players[0].getRecord()
                 && players[1].getRecord()< players[2].getRecord()) {
            name = players[1].getName();
         }else {
             name = players[2].getName();
         } 
         System.out.println("1등 "+ name);
    }
}
 
 
cs

'1. 자바' 카테고리의 다른 글

자바/JPA/2020-08-26/ application.propetires 한글깨짐 해결하기  (0) 2020.08.26
Array - Score.java  (0) 2020.08.14
OOP - Phone.java  (0) 2020.08.14
CRUD - Person.java  (0) 2020.08.14
CRUD - Member.java  (0) 2020.08.14
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함