简体   繁体   中英

java won't seen to execute the second method

I suppose to ask the team of four runners individually for their disability class and then get the total of then, afterwards, if the score is greater than 32 it is illegal if not, then it is legal. all that has to be done in For Loops and using more than one methods. the code is listed down below.

public class Runner11 {
    public static void main(String[] p) {
        int Points;
        int total = DisabilityClass();
        int Runner1;
        int Runner2;
        int Runner3;
        int Runner4;
        System.exit(0);
    }

    public static int DisabilityClass() {
        Scanner Scanner = new Scanner(System.in);
        System.out.println("What is the disability class of Runner 1?");
        int Runner1 = Scanner.nextInt();
        System.out.println("What is the disability class of Runner 2?");
        int Runner2 = Scanner.nextInt();
        System.out.println("What is the disability class of Runner 3?");
        int Runner3 = Scanner.nextInt();
        System.out.println("What is the disability class of Runner 4?");
        int Runner4 = Scanner.nextInt();
        int total = Runner1 + Runner2 + Runner3 + Runner4;
        return total;
   }

    public static void Points(int total) {
        int i;
        for(i=32; i >= total; i++) {
            System.out.println("That team has "+total+" points so it's legal");
        }
        return;
    }
}

You do not need the four separate runners, also remove the System.exit(0). also you declare a second set of runners in your disability class. Remove all the runners and try this code inside your disability class

int runner = 0;
int total = 0;

for(int i = 0; i<4; i++){
    System.out.println("What is the disability class");
    runner = sc.nextInt();
    total +=runner;
}

Use this code in your points method.

if(total<=32){
      System.out.println("That team has "+total+" points so it's legal")
}else{
      System.out.println("That team has "+total+" points so it's illegal");
}

All this can be done in the main method, however if you have to use separate methods. just paste the code in there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM