简体   繁体   中英

Need advice on what I am doing wrong

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);

    }**

    }

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);

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