首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >(admit.java)我的小程序没有在方法之间传递整数

(admit.java)我的小程序没有在方法之间传递整数
EN

Stack Overflow用户
提问于 2018-10-13 05:57:28
回答 1查看 329关注 0票数 0

我有点困惑,我有一个为学校作业写的小程序,我需要处理的限制是任何方法都不能包含超过15行代码,并且我们不能使用任何for next循环。

我似乎不明白的是,为什么我能够将一个整数传递给我的舍入方法,它甚至返回舍入后的值,但是它跳回到我的if / then语句(它不应该这样做),并且不传递变量。

这是一个非常初级的程序,我的know...my编码技巧不是很好,但如果有任何帮助,将不胜感激。

我需要传递回的变量是testscore和GPA,它们需要返回到main方法,以便可以存储到新的变量中,并最终推送到results方法中。

我对编码和社区以及事情是如何工作的还是个新手……

代码语言:javascript
复制
import java.util.*;

public class Admit {
   public static void main(String[] Args) {
      Scanner console = new Scanner(System.in);
      Introduction();
      double testscore = 0;
      double GPA = 0;
      int Student = 1;
      ACTSATScores(1,0,console);
      double StudentOneTestScore = testscore;
      GPAInfo(0,console);
      double StudentOneGPAScore = GPA;
      Student = 2;
      ACTSATScores(2,0,console);
      double StudentTwoTestScore = testscore;
      GPAInfo(0,console);
      double StudentTwoGPAScore = GPA;
      DisplayResults(StudentOneTestScore,StudentOneGPAScore,StudentTwoTestScore,StudentTwoGPAScore);
      }

   public static void Introduction() {
      System.out.println("This program compares two applicants to");
      System.out.println("determine which one seems like the stronger");
      System.out.println("applicant.  For each candidate I will need");
      System.out.println("either SAT or ACT scores plus a weighted GPA.");
      System.out.println();   
   }

   public static double ACTSATScores(int Student,double testscore,Scanner console) {
      System.out.println("Information for applicant #" + Student + ":");
      System.out.print("do you have 1) SAT scores or 2) ACT scores? ");
      int ACTSAT = console.nextInt();
         if ( ACTSAT == 1) {
            SAT(Student,testscore,console);
         }
         if ( ACTSAT == 2) {
            ACT(Student,testscore,console);
         }
         return testscore;
   }

   public static double SAT(int Student,double testscore,Scanner console) {
       System.out.print("SAT math? ");
       int SATMath = console.nextInt();
       System.out.print("SAT critical reading? ");
       int SATReading = console.nextInt();
       System.out.print("SAT writing? ");
       int SATWriting = console.nextInt();
       testscore = ( ( 2 * SATMath + SATReading + SATWriting ) / 32);
       System.out.println("exam score = " +  roundNumber(testscore));
       return ( ( 2 * SATMath + SATReading + SATWriting ) / 32);
   }

   public static double ACT(int Student,double testscore,Scanner console) {
       System.out.print("ACT English? ");
       int ACTEnglish = console.nextInt();
       System.out.print("ACT math? ");
       int ACTMath = console.nextInt();
       System.out.print("ACT reading? ");
       int ACTReading = console.nextInt();
       System.out.print("ACT science? ");
       int ACTScience = console.nextInt();
       testscore = ( ( 2 * ACTMath + ACTEnglish + ACTReading + ACTScience ) / 1.8 );
       System.out.println("exam score = " + roundNumber(testscore));
       return testscore;
   }

   public static double GPAInfo(double GPA,Scanner console) {
       System.out.print("overall GPA? ");
       double OverallGPA = console.nextDouble();
       System.out.print("max GPA? ");
       double MaxGPA = console.nextDouble();
       System.out.print("Transcript Multiplier? ");
       double TranscriptMultiplier = console.nextDouble();
       GPA = ( OverallGPA / MaxGPA * 100 * TranscriptMultiplier );
       System.out.println("GPA score = " + roundNumber(GPA));
       return GPA;
    }

    public static double roundNumber(double number) {
      return (Math.round(number * 10)) / 10.0;
   }

    public static double DisplayResults(double StudentOneTestScore, double StudentOneGPAScore, double StudentTwoTestScore, double StudentTwoGPAScore) {
       System.out.println("First applicant overall score = " + StudentOneTestScore + StudentOneGPAScore);
       System.out.println("Second applicant overall score = " + StudentTwoTestScore + StudentTwoGPAScore);
       if ( StudentOneTestScore + StudentOneGPAScore > StudentTwoTestScore + StudentTwoGPAScore ) {
       System.out.println("The first applicant seems to be better");
       }
       else if ( StudentOneTestScore + StudentOneGPAScore < StudentTwoTestScore + StudentTwoGPAScore ) {
          System.out.println("The second applicant seems to be better");
       }
       else {
          System.out.println("The two applicants seem to be equal");
       }
       return StudentOneTestScore;
    }
}

预期输出:

代码语言:javascript
复制
This program compares two applicants to
determine which one seems like the stronger
applicant.  For each candidate I will need
either SAT or ACT scores plus a weighted GPA.
 
Information for applicant #1:
    do you have 1) SAT scores or 2) ACT scores? 1
    SAT math? 450
    SAT critical reading? 530
    SAT writing? 490
    exam score = 60.0
    overall GPA? 3.4
    max GPA? 4.0
    Transcript Multiplier? 0.9
    GPA score = 76.5
 
Information for applicant #2:
    do you have 1) SAT scores or 2) ACT scores? 2
    ACT English? 25
    ACT math? 20
    ACT reading? 18
    ACT science? 15
    exam score = 54.4
    overall GPA? 3.3
    max GPA? 4.0
    Transcript Multiplier? 0.95
    GPA score = 78.4
 
First applicant overall score  = 136.5
Second applicant overall score = 132.8
The first applicant seems to be better

我的输出

代码语言:javascript
复制
This program compares two applicants to
determine which one seems like the stronger
applicant.  For each candidate I will need
either SAT or ACT scores plus a weighted GPA.

Information for applicant #1:
do you have 1) SAT scores or 2) ACT scores? 1
SAT math? 450
SAT critical reading? 530
SAT writing? 490
exam score = 60.0
overall GPA? 3.4
max GPA? 4.0
Transcript Multiplier? 0.9
GPA score = 76.5
Information for applicant #2:
do you have 1) SAT scores or 2) ACT scores? 2
ACT English? 25
ACT math? 20
ACT reading? 18
ACT science? 15
exam score = 54.4
overall GPA? 3.3
max GPA? 4.0
Transcript Multiplier? 0.95
GPA score = 78.4
First applicant overall score = 0.00.0
Second applicant overall score = 0.00.0
The two applicants seem to be equal

已为任何需要它的人更正代码

代码语言:javascript
复制
import java.util.*;

public class Admit {
   public static void main(String[] Args) {
      Scanner console = new Scanner(System.in);
      Introduction();
      int Student = 1;
      double StudentOneTestScore = ACTSATScores(1,console);
      double StudentOneGPAScore = GPAInfo(0,console);
      Student = 2;
      double StudentTwoTestScore = ACTSATScores(1,console);
      double StudentTwoGPAScore = GPAInfo(0,console);
      DisplayResults(StudentOneTestScore,StudentOneGPAScore,StudentTwoTestScore,StudentTwoGPAScore);
      }

   public static void Introduction() {
      System.out.println("This program compares two applicants to");
      System.out.println("determine which one seems like the stronger");
      System.out.println("applicant.  For each candidate I will need");
      System.out.println("either SAT or ACT scores plus a weighted GPA.");
      System.out.println();   
   }

   public static double ACTSATScores(int Student,Scanner console) {
      double testscore = 0;
      System.out.println("Information for applicant #" + Student + ":");
      System.out.print("    do you have 1) SAT scores or 2) ACT scores? ");
      int ACTSAT = console.nextInt();
         if ( ACTSAT == 1) {
            testscore = SAT(console);
         }
         if ( ACTSAT == 2) {
            testscore = ACT(console);
         }
         return testscore;
   }

   public static double SAT(Scanner console) {
       System.out.print("    SAT math? ");
       int SATMath = console.nextInt();
       System.out.print("    SAT critical reading? ");
       int SATReading = console.nextInt();
       System.out.print("    SAT writing? ");
       int SATWriting = console.nextInt();       
       double testscore = ( ( 2 * SATMath + SATReading + SATWriting ) / 32);
       System.out.println("    exam score = " +  roundNumber(testscore));
       return testscore;
   }

   public static double ACT(Scanner console) {
       System.out.print("    ACT English? ");
       int ACTEnglish = console.nextInt();
       System.out.print("    ACT math? ");
       int ACTMath = console.nextInt();
       System.out.print("    ACT reading? ");
       int ACTReading = console.nextInt();
       System.out.print("    ACT science? ");
       int ACTScience = console.nextInt();
       double testscore = ( ( 2 * ACTMath + ACTEnglish + ACTReading + ACTScience ) / 1.8 );
       System.out.println("    exam score = " + roundNumber(testscore));
       return testscore;
   }

   public static double GPAInfo(double GPA,Scanner console) {
       System.out.print("    overall GPA? ");
       double OverallGPA = console.nextDouble();
       System.out.print("    max GPA? ");
       double MaxGPA = console.nextDouble();
       System.out.print("    Transcript Multiplier? ");
       double TranscriptMultiplier = console.nextDouble();
       GPA = ( OverallGPA / MaxGPA * 100 * TranscriptMultiplier );
       System.out.println("    GPA score = " + roundNumber(GPA));
       System.out.println();
       return GPA;
    }

    public static double roundNumber(double number) {
      return (Math.round(number * 10)) / 10.0;
   }

   public static double finalScore(double TestScore, double GPAScore) {
       return TestScore + GPAScore;
   }

    public static double DisplayResults(double StudentOneTestScore, double StudentOneGPAScore, double StudentTwoTestScore, double StudentTwoGPAScore) {
       double StudentOneScore = finalScore(StudentOneTestScore,StudentOneGPAScore);
       double StudentTwoScore = finalScore(StudentTwoTestScore,StudentTwoGPAScore);
       System.out.println("First applicant overall score = " + roundNumber(StudentOneScore)); //StudentOneTestScore + StudentOneGPAScore);
       System.out.println("Second applicant overall score = " + roundNumber(StudentTwoScore)); //StudentTwoTestScore + StudentTwoGPAScore);
       if ( StudentOneTestScore + StudentOneGPAScore > StudentTwoTestScore + StudentTwoGPAScore ) {
       System.out.println("The first applicant seems to be better");
       } else if ( StudentOneTestScore + StudentOneGPAScore < StudentTwoTestScore + StudentTwoGPAScore ) {
          System.out.println("The second applicant seems to be better");
       } else {
          System.out.println("The two applicants seem to be equal");
       }
       return StudentOneTestScore;
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52787467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档