需要关于我做错了什么的建议。

huangapple go评论76阅读模式
英文:

Need advice on what I am doing wrong

问题

import java.util.Scanner;

public class BookstoreCredit {
    public static void main(String args[]) {
        String studentName;
        double gradeAverage;
        Scanner inputDevice = new Scanner(System.in);
        System.out.println("Enter Student name: ");
        studentName = inputDevice.nextLine();
        System.out.println("Enter student GPA: ");
        gradeAverage = inputDevice.nextDouble();

        computeDiscount(studentName, gradeAverage);
    }

    public static void computeDiscount(String name, double gpa) {
        double credits;
        credits = gpa * 10;
        System.out.println(name + "your GPA is " +
                gpa + "so your credit is $ ." + credits);

    }
}
英文:

I have been working this for a few days and cannot figure out what I am doing wrong. The name and GPA print out fine, but I cannot get the last part of the program to print. The bold portion will not print out.
Thank you

    import java.util.Scanner;
    public class BookstoreCredit 
    {
    public static void main (String args[]) 
    {
    String studentName;
    double gradeAverage;
    Scanner inputDevice = new Scanner(System.in);
    System.out.println("Enter Student name: ");
    studentName = inputDevice.nextLine();
    System.out.println("Enter student GPA: ");
    gradeAverage = inputDevice.nextDouble();  
    }

   **public static void computeDiscount(String name, double gpa) 
   {
    double credits;
    credits = gpa * 10;
    System.out.println(name + "your GPA is " +
    gpa + "so your credit is $ ." + credits);

    }**

    }

答案1

得分: 1

最后一部分是一个静态方法,而且,你没有在主方法内调用它,所以那个代码块不能执行。你可以尝试在 gradeAverage = inputDevice.nextDouble(); 之后添加这行代码:

gradeAverage = inputDevice.nextDouble();
computeDiscount(studentName, gradeAverage);
英文:

The last part is a static method, and moreover, you are not calling it inside the main method, so that block can't execute. You can try to add this line after gradeAverage = inputDevice.nextDouble();

gradeAverage = inputDevice.nextDouble();
computeDiscount(studentName, gradeAverage);

huangapple
  • 本文由 发表于 2020年9月11日 03:01:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63836134.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定