英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论