如何停止扫描仪重复自身?

问题描述 投票:0回答:1

我正在尝试创建多种方法来成功地比较两个学生及其分数。到目前为止,我已经弄清楚了这些方法,我想在它们之间进行比较。但是,一旦用户为两个学生输入,循环便会重复,我将回到“您有...”的一角。

我想知道如何使扫描仪停止运行并成功使用底部的比较方法。

import java.util.*;

public class studentComp{      
     public static double askExamScore(){
         System.out.println("Do you have: 1.  SAT's scores or 2. ACT's scores?");
         Scanner key = new Scanner(System.in);
         double examType;
         examType = key.nextDouble();
         double scoreSAT;
         double scoreACT;            

         if(examType == 1){
             scoreSAT = satScore();
             return scoreSAT;
         }
         else{
             scoreACT = actScore();
             return scoreACT;
        }                 
   }                                

   public static double satScore(){
       Scanner key = new Scanner(System.in);
       System.out.println("Put in your math score ");
       int mathScoreS = key.nextInt();

       System.out.println("Put in your critical reading score ");
       int critRScore = key.nextInt();

       System.out.println("Put in your writing score ");
       int writScore = key.nextInt();

       double test = (2 * mathScoreS + critRScore + writScore) / 34;
       return test;
   }                     

   public static double actScore(){
       Scanner key = new Scanner(System.in);

       System.out.println("Put in your English score ");
       int engScore = key.nextInt();

       System.out.println("Put in your Math score ");
       int mathScore = key.nextInt();

       System.out.println("Put in your Reading score ");
       int readScore = key.nextInt();

       System.out.println("Put in your Science score ");
       int sciScore = key.nextInt();

       double test = (engScore + 2 * mathScore + readScore + sciScore) / 2.1;
       return test;
   }    

   public static double getGPAscore(){
       Scanner key = new Scanner(System.in);

       System.out.println("Put in your GPA ");
       double realgpa = key.nextDouble();

       System.out.println("Enter your transcript multiplier ");
       double transMult = key.nextDouble();

       double gpaScore = realgpa / 4.0 * transMult * 100;
       return gpaScore; 
   }

   public static double getStudentScore(){
       double totalScore;
       double gpaScore;
       double test;
       gpaScore = askExamScore();
       test = getGPAscore();

       totalScore = test + gpaScore;
       return totalScore;
   }

   public static void compare(double s1, double s2){
       if(s1 > s2){
           System.out.println("First applicant overall score = " + s1);
           System.out.println("Second applicant overall score = " + s2);
           System.out.println();
           System.out.println("The first applicant is better");
       }
       else{
           System.out.println("First applicant overall score = " + s1);
           System.out.println("Second applicant overall score = " + s2);
           System.out.println();
           System.out.println("The second applicant is better");
       }
   }            

   public static void main(String[] args){
       double s1;
       double s2;
       s1 = getStudentScore();
       askExamScore();
       s2 = getStudentScore();

       compare(s1, s2);
   }
}
java input methods java.util.scanner repeat
1个回答
1
投票
  public static void main(String[] args){

    double s1;
    double s2;
    s1 = getStudentScore();
    //askExamScore(); ---> comment this
    s2 = getStudentScore();

    compare(s1, s2);
  }
© www.soinside.com 2019 - 2024. All rights reserved.