Skip to content
Advertisement

Fix the int convert and add a return for a class [closed]

I have a code done but has a couple of issues that need to be fixed, however, I tried many different ways is not work, could anyone give me some help here?

My error parts are total = getScore; and return total;

… means no worry I am sure those are not necessary and correct

 public class Main {
     public static void main(String[] args) {
         int total;
         boolean winLoss;
         int win = 0;
         int loss = 0;
         int point = 0;
         for(int i=0; i<100000;i++){
             total = getScore(); 
             if...
             ...
             while(true){
                 total = getScore();
                 if(total == point){...
                      ...
                 }   
             }
        ...
     private static void getScore(){
         int dice1 = (int)(Math.random()*(6-1)+1);
         int dice2 = (int)(Math.random()*(6-1)+1);
         int total = dice1+dice2;
         return total;
     }
}

Advertisement

Answer

Your function getScore() should be of type int.

public class run {
      public static void main(String[] args) {
        int total;
        boolean winLoss;
        int win = 0;
        int loss = 0;
        int point = 0;
        for(int i=0; i<100000;i++){
            total = getScore(); 
            if...
            ...
            while(true){
                total = getScore();
                if(total == point){...
                    ...
                }   
            }
            ...
        }
      private static int getScore(){
         int dice1 = (int)(Math.random()*(6-1)+1);
         int dice2 = (int)(Math.random()*(6-1)+1);
         int total = dice1+dice2;
         return total;
      }
}   
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement