SHOW:
|
|
- or go back to the newest paste.
| 1 | - | public static boolean processCompareGuesses(double secretPrice, double[] playerGuess) {
|
| 1 | + | public class assignment8 {
|
| 2 | - | int nearest = -1; |
| 2 | + | |
| 3 | - | bustPlayers = 0; |
| 3 | + | public static void main(String[] args) {
|
| 4 | - | int bestDistanceFoundYet = Integer.MAX_INTEGER; |
| 4 | + | int round = 1; |
| 5 | - | // We iterate on the array... |
| 5 | + | |
| 6 | - | for (int i = 0; i < playerGuess.length; i++) {
|
| 6 | + | while(round < 4){
|
| 7 | - | // if we found the desired number, we return it. |
| 7 | + | double secretPrice = getSecretPrice(); |
| 8 | - | while(bustPlayers != playersGuess.length){
|
| 8 | + | double[] playerGuess = getPlayerGuess(); |
| 9 | ||
| 10 | - | bustPlayers++; |
| 10 | + | for(int i = 0; i < playerGuess.length; i++){
|
| 11 | - | if (playerGuess[i] == secretPrice) {
|
| 11 | + | |
| 12 | - | return playerGuess[i]; |
| 12 | + | bustPlayers++; |
| 13 | - | } else {
|
| 13 | + | } else {
|
| 14 | - | // else, we consider the difference between the desired number and the current number in the array. |
| 14 | + | String compareGuesses = processCompareGuess(); |
| 15 | - | int d = Math.abs(secretPrice - playerGuess[i]); |
| 15 | + | } |
| 16 | - | if (d < bestDistanceFoundYet) {
|
| 16 | + | round++; |
| 17 | - | // For the moment, this value is the nearest to the desired number... |
| 17 | + | |
| 18 | - | String nearest = ("Player" + i + "is the cloest guess with" + playerGuess[i]);
|
| 18 | + | } |
| 19 | - | d = bestDistanceFoundYet; |
| 19 | + | } |
| 20 | - | } |
| 20 | + | displayResults(); |
| 21 | - | } |
| 21 | + | } |