-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkiJumping_Failed.java
173 lines (143 loc) · 4.42 KB
/
SkiJumping_Failed.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package skijumping_failed;
import java.util.ArrayList;
import java.util.List;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class Participant implements Comparable<Participant>{
private String name;
private int points;
private List<Integer> jumps;
public Participant(String name, int points) {
this.name = name;
this.points = 0;
this.jumps = new ArrayList<Integer>();
}
@Override
public String toString() {
return this.name + " (" + this.points + ")";
}
@Override
public int compareTo(Participant part) {
return this.points - part.points;
}
public void addPoints(int points) {
this.points += points;
}
}
package skijumping_failed;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class ParticipantList {
private List<Participant> participants;
// private Random random = new Random();
public ParticipantList() {
this.participants = new ArrayList<Participant>();
}
public void addParticipant(Participant participant) {
this.participants.add(participant);
}
public void sort() {
Collections.sort(this.participants);
}
public void reverseOrder() {
Collections.reverse(this.participants);
}
public int getSize() {
return this.participants.size();
}
@Override
public String toString() {
for (Participant part : this.participants) {
System.out.println(part);
}
}
}
package skijumping_failed;
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class TextUserInterfaceFailed {
private Scanner scanner;
private int round;
private ParticipantList participants;
public TextUserInterfaceFailed() {
this.scanner = new Scanner(System.in);
this.round = 1;
this.participants = new ParticipantList();
}
public void start() {
System.out.println("Kumpula ski jumping week");
System.out.println();
enterParticipants();
roundsStart();
// printResults();
}
public void enterParticipants() {
//ParticipantList jumpers = new ParticipantList();
String inputName;
System.out.println("Write the name of the participants one at a time; an empty string brings you to the jumping phase");
while(true) {
System.out.print(" Participant name: ");
inputName = this.scanner.nextLine();
if (inputName.isEmpty()) {
break;
} else {
Participant newPar = new Participant(inputName, 0);
this.participants.addParticipant(newPar);
}
}
System.out.println("");
System.out.println("The tounament begins!");
System.out.println("");
}
public void roundsStart() {
String command = "";
while(true) {
System.out.print("Write \"jump\" to jump; otherwise you quit: ");
command = this.scanner.nextLine();
System.out.println();
System.out.println("Round " + this.round);
System.out.println();
if(command.isEmpty()) {
break;
} else {
this.participants.sort();
System.out.println("Jumping Order:");
System.out.println("");
printJumpingOrder(this.participants);
System.out.println("");
System.out.println("Results of round " + this.round);
}
this.round++;
}
}
public void printJumpingOrder(ParticipantList participantList) {
for (int i = 0; i < this.participants.getSize(); i++) {
System.out.println(" " + (i + 1) + this.participants.toString());
}
}
}