Click here to Skip to main content
15,313,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone help me on how can I use the first score if the score is equals to 3 the player gets to get another attempt to shot.

Here is what I've tried.

if the random attempt shot is equals to 3 then the same players gets another shot, therefore if the player shots another and gets another random score then the first random attempt shot/score will be added to the second attempt random. But the problem is I don't know how can I add it.

Here is my output.

Note that each perfect score or 3 points would let the same player shot again. and I don't get what I want please help.

What I have tried:

Java
LinkedList<String> list = new LinkedList<>();
        int max = 3;
        int min = 0;
        int range = max - min + 1;
        
        int score = 0;
        
        list.add("Player 1: ");
        list.add("Player 2: ");
        list.add("Player 3: ");
        list.add("Player 4: ");
        list.add("Player 5: ");
        
        for (int i = 0; i < list.size(); i++) {
            int att = (int)(Math.random() * range) + min;
            if (att == 3) {
                System.out.println(list.get(i) + att);
                score = att;
                score++;
                
                if (score == 3) {
                    int nextscore = score + att;
                    System.out.println(list.get(i) + nextscore);
                }
            }
            
            if (att <= 2) {
                System.out.println(list.get(i) + att);
            }
            
        }


Java
Player 1: 3 //The random attempt shot is 3 but the score didn't added for the second attempt.
Player 2: 2
Player 3: 1
Player 4: 1
Player 5: 2
Posted
Updated 24-Nov-20 22:30pm

1 solution

Java
if (att == 3) {
    System.out.println(list.get(i) + att);
    score = att; // So score is now equal to 3
    score++;     // ***score is now equal to 4  
    
    if (score == 3) { // this test will always fail
        int nextscore = score + att;
        System.out.println(list.get(i) + nextscore);
    }
}
   
Comments
Pej ML 25-Nov-20 5:15am
   
I see i removed the score++ but I still don't get it.
Richard MacCutchan 25-Nov-20 6:14am
   
Well at that point score is 3 and att is 3 so the answer is 6. But, to be perfectly honest, I am not sure what this code is supposed to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900