I am reading in a file in java and adding it to a multi dimensional array.
The file looks like this:
14.9 18.9 -18.6 -7.7 11.5 0.6 -5.3 -15.5 -1.5 -12.5 19.2 -8.8
2.9 -2.9 13.4 -12.8 -9.8 6.2 11.0 0.9 3.7 17.3 -0.2 -18.7
18.5 -2.8 6.7 16.5 7.4 -17.5 17.8 -14.3 -11.2 14.6 7.9 -9.7
7.0 16.8 12.9 -0.2 -7.4 0.7 8.6 11.8 3.4 5.7 3.1 -15.6
-12.2 -5.4 -4.1 -15.6 -14.8 -5.1 -0.6 4.2 14.1 13.5 13.2 -9.9
1.6 2.1 11.5 9.1 -13.8 -3.9 15.8 15.4 8.9 16.8 6.8 20.0
13.7 -12.6 12.2 1.1 18.7 -19.0 -11.4 -10.7 -2.9 -0.6 -9.5 0.4
14.2 -3.3 6.8 -5.9 -4.5 12.2 19.3 -13.0 -3.7 14.5 6.9 14.6
1.9 -10.7 19.2 -3.7 -10.7 -18.5 3.1 -16.5 10.6 -1.9 -17.7 -15.3
-17.4 0.2 4.1 1.1 -12.1 -20.0 -10.4 -9.3 -19.0 15.1 -3.7 -16.7
-14.9 -6.9 -5.9 -11.9 -15.7 -19.7 -8.1 -3.8 8.5 8.0 17.3 9.7
-4.0 -5.4 16.0 7.8 19.6 -7.0 0.2 9.3 -9.4 13.1 -5.3 -7.0
-14.1 -11.8 -6.6 8.5 16.2 -13.6 6.4 2.0 17.0 -0.5 -10.6 18.2
-1.0 18.5 9.1 13.4 6.6 -3.7 -15.1 11.8 10.7 -8.1 14.1 12.8
-2.7 1.2 -3.1 17.0 6.2 14.5 5.3 -12.9 -5.6 12.2 10.5 -17.1
-19.6 11.0 6.1 15.2 5.1 5.7 6.5 -19.6 -18.7 11.2 -1.2 11.0
-5.9 17.9 -15.4 -2.5 8.4 16.8 -2.3 -13.6 -12.5 16.1 -19.6 -16.5
-4.4 2.4 -6.6 3.1 6.3 16.6 -1.5 11.6 14.3 -15.5 -12.7 -11.7
5.2 4.1 -2.1 -18.9 -16.0 1.9 17.3 12.7 -2.8 -3.4 -3.3 12.0
-12.1 5.2 -12.8 -19.9 -11.8 -17.1 -14.6 3.4 -7.1 12.7 8.3 0.5
3.5 2.7 -3.1 -9.9 17.1 2.3 18.1 -8.8 -2.8 -14.2 -4.6 17.3
0.2 18.7 -16.8 18.5 4.5 -7.8 -1.3 -10.0 5.8 -11.4 -11.5 12.4
19.3 13.2 -6.7 3.3 -17.9 -2.4 -6.8 -11.8 9.5 -13.1 -0.7 -3.1
-3.3 6.2 1.3 -11.3 6.2 -5.9 -11.7 14.4 -11.4 0.8 0.1 2.0
-2.0 -8.1 -13.4 13.9 -6.3 -13.3 -14.0 17.9 10.1 19.9 -5.3 -13.3
1.2 -3.5 -2.5 5.5 -12.8 -16.7 -9.7 -18.7 5.5 5.4 -3.8 13.3
-15.5 5.3 -9.4 -19.7 -4.7 -0.8 17.8 3.6 -12.5 -1.7 13.8 -8.2
3.0 12.4 14.8 -19.4 16.2 -3.8 7.4 -6.4 -8.2 5.2 -1.5 18.9
-13.0 12.6 -0.8 -1.3 11.2 -0.4 10.3 -11.8 -4.4 3.2 9.0 -0.1
7.2 -17.0 11.3 14.9 -14.7 18.7 19.6 13.7 13.4 -16.3 7.5 -1.2
Each line represents a game of darts for two players. The first 6 are pairs of 3 for player one and the second 6 are pairs of 3 for player two.
The program reads the file and then spits out the score based for each line.
Example:
input: (14.9, 18.9) (-18.6, -7.7) (11.5, 0.6) (-5.3, -15.5) (-1.5, -12.5) (19.2, -8.8)
output: Player two wins: Player one score 280, Player two score 290.
How do I handle each line to score the first player and then score the second player throws?
Edit
Sorry for not showing code, thought the question could be answered with out.
public class DartBoard {
private double[][] darts;
public DartBoard(String file) throws FileNotFoundException {
Scanner scan = new Scanner(new File(file));
int numberRows = 12;
int numberCols = 30;
darts = new double[numberRows][numberCols];
for(int i = 0; i < numberRows; i++){
for(int j = 0; j < numberCols; j++){
if(scan.hasNextDouble()){
darts[i][j] = scan.nextDouble();
}
}
}
}
public double distance(double x, double y){
return Math.sqrt(x*x + y*y);
}
public int score(double x, double y){
double dist = distance(x,y);
int s = 0;
if(dist < 4){
s = 100;
} else if(dist < 8){
s = 80;
} else if(dist < 12){
s = 60;
} else if(dist < 16){
s = 40;
} else if(dist < 20){
s = 20;
}
return s;
}
}
I am at a lost on how to score each line. Every two doubles would be passed to the method score() and once I got 3 score that would be added for player ones total score and then same for the next 6 doubles. And then repeat until all lines are processed.
double? 5) Pair them? 6) Separate the pairs into 3 for player one and 3 for player 2? 7) If you can do all of that, then what is the problem? --- Voting to close as "Too broad", aka "Needs more focus", since the question is way too open right now, which means it just looks like you want us to write your code for you, and that's not what StackOverflow is about. - Andreasint numberRows = 12; int numberCols = 30;? - Andreas