jeudi 29 octobre 2015

Java restart program and keep count number of tries within the run

I created a quiz program that keeps track of students score. What I am trying to do is if the student received 100% then they get a message that their score is 100%. If the the score is less than 100 then the program should restart and keep the counter of up to 5 tries in the counter integer.

Once the counter reaches int of 5 with the score of less than 3 than break the program and display message "take a quiz later"

What is working right now: I am able to keep track of the "score" int variable and its working if you get 100% or less than 100%.

What I am trying to get working: Get the "counter" int variable working to keep the record of the number of tries so the user gets up to 5 tries and restart the whole console program while maintaining the score on the "counter" variable. for instance:

counter < 5 - try again 
     counter++
counter >= 5 - end the program.

Here is the end of the program. Maybe I should somehow place it in the method and recall it in my public void run but I was unable to accomplish that and keep record of scores. I have many loops so it would be unrealistic to write the whole program in loop one big loop.

Thanks!

   public void run()
    {
        if (score >= 3) 
            {
            println("You have passed the exam with 100%");
            }   
                else if (counter<5) 
                {
                counter++;
                println("You're score is less than 100%.");
                println(" ");
                println("Try Again!");
                //restart the questions until you're out of 5 attempts
                } 
                    else if (counter==5)
                    {
                        println("You're out of your 5 attempts");
                    }
    }

Aucun commentaire:

Enregistrer un commentaire