Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Score Board Java

I am quite new to java programming

Preparing a scoreboard and in Java Program, I am struggling with Carry Over score in the for loops
appreciate if I can have simple example of how I can prepare such board in java.

Round 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • Carry Over Score : 0
  • Current: 5
  • Total: 5

Round 2

  • Carry Over Score : 5
  • Current :10
  • Total 15

Round 3

  • Carry Over Score: 15
  • Current: 5
  • Total : 20

Round 4

  • Carry Over Score: 20
  • Current: 7
  • Total : 27

>Solution :

I assume this is what you intend to do:

int carryOverScore = 0;
int currentScore = 0;
int totalScore = 0;

int gameRounds = 5;
for (int i = 0; i < gameRounds; i++) {
    currentScore = 5; //you should use some method to calculate current score instead of hardcoding the value
    carryOverScore = totalScore;
    totalScore = totalScore + currentScore;

    System.out.println("Carry over: " + carryOverScore);
    System.out.println("Current: " + currentScore);
    System.out.println("Total: " + totalScore);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading