//Author: Asim
//Date: 10th November 2016
//Description: This program is used to ask the user what theyre favourite music genre is. The user receives a score which count towards a team score.
import java.util.Scanner; //Importing the scanner
import java.util.Random; //Importing the dice
public class MiniProject6{
//Main method
public static void main(String[]p){
for(int counter=1; counter<=4; counter++){
Info i1 = new Info();
i1 = setQuestion(i1, "What is the best music genre?"); //Here are the vales which are being set for Question and CorrectAnswer
System.out.print(getQuestion(i1));
i1 = setCorrectanswer(i1, "Drill");
String ans = answer();
int [] pScore = new int[2];
boolean finish;
finish = checker(ans, getCorrectanswer(i1), pScore); //Cross references the users input with the CorrectAnswer
}
}
//End main
//Answer method returns the value the user types
public static String answer()
{
Scanner asim = new Scanner(System.in);
String music;
music = asim.nextLine();
return music;
}
//End answer
//Checker method is used to see if the users answer is the same as the record correct answer
public static boolean checker(String ans, String Correctanswer, int pScore[]){
boolean finish;
if (ans.equals(Correctanswer)){
print("Congrats, " + Correctanswer + " is the correct answer!");
finish = true;
if (finish == true){
int score = dice();
print("The score is " + score);
if (score<6){
print("Lets add another 3 onto the score. ");
pScore[0] = score+3;
print("Total score is: " + pScore[0]);
pScore[1] = pScore[1] + pScore[0];
}
else if (score>5){
print("Lets add another 6 onto the score. ");
pScore[0] = score+6;
print("Total score is: " + pScore[0]);
pScore[1] = pScore[1] + pScore[0];
}
}
System.out.println(finish);
System.out.println("Currently the teamscore is " + pScore[1]);
}
else{
print("The correct answer is " + Correctanswer + ", unfortunately you got it wrong");
finish = false;
System.out.println(finish);
}
return finish;
}
//End Checker
//Dice method is used to create the dice
public static int dice(){
Random Dice = new Random();
int answer = Dice.nextInt(6) + 1;
return answer;
}
//End dice
-1
A
回答
0
如果您希望彙總分數,您需要檢查分數變量的範圍/創建一個未包含在for循環中的分數變量。如果變量在for循環中初始化,那麼每次迭代都會重置該變量。只需將循環外部的變量實例化並在循環內引用即可。然後你的分數不會被重置。
相關問題
- 1. 每次執行後暫停循環
- 2. 如何在發現後停止循環?
- 3. 如何在錯誤後停止循環
- 4. 2次循環後幻燈片停止?
- 5. Applescript/Automator - 在給定的重複次數後停止循環?
- 6. MuleESB。如何停止每個循環?
- 7. 如何在每1000個值之後停止無限循環?
- 8. 如何在第三次無效嘗試後停止While循環?
- 9. 循環jQuery,如何在第二次循環後停止幻燈片放映?
- 10. 停止jQuery每個循環
- 11. 如何在每次完成時停止重新計算價值?
- 12. 團結 - 停止動畫循環
- 13. 如何在iOS中完成循環後停止音頻
- 14. 如何停止成功循環
- 15. 文件循環宏停止後第一次成功
- 16. 如何在重複25次後暫停循環60分鐘?
- 17. mysql_fetch_array - 團體成績
- 18. 如何停止重定向循環?
- 19. 如何停止循環重複?
- 20. jquery循環:幻燈片循環一次後,重新啓動一個,並停止
- 21. 如何在unix中爲每個團隊成員設置java的開發環境
- 22. 第一次「for循環」在第一次迭代後停止python
- 23. For循環停止1循環後
- 24. 停止循環重複表
- 25. 循環停止在第一次迭代
- 26. 如何循環兩個列表後,如何在一次迭代後停止內循環?
- 27. 循環中的jQuery getJson在n個循環後停止循環
- 28. AS3:在每次傳遞時停止for循環
- 29. PHP循環停止在每一次迭代
- 30. 如何停止循環
使用IDE調試代碼 – SkrewEverything