I need my code to display the users name, their GPA, and then a credit which is their GPA times 10

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

I need my code to display the users name, their GPA, and then a credit which is their GPA times 10

问题

我需要我的代码显示用户的姓名,他们的GPA,然后是一个学分,该学分是他们的GPA乘以10。下面是

英文:

I need my code to display the users name, their GPA, and then a credit which is their GPA times 10. The code below is what I have so far but every time I run the program the output is just, "EEEEEEEEEE EEEEEE....". Can you guys please tell me what I can do to fix this? All help is appreciated and thanks in advance!

import java.util.Scanner;
public class BookstoreCredit {

public static void main (String args[])
{
    String name;
    double gpa;
    Scanner inputDevice = new Scanner(System.in);

    System.out.print ("Please enter your name >>> ");
    name = inputDevice.nextLine();
    System.out.print ("Please enter your grade point average >>> ");
    gpa = inputDevice.nextDouble();
    
    System.out.print (name);
    System.out.print (", your GPA is ");   
    System.out.print (gpa);
    System.out.print (", so your credit is $");
    
}

public static void computeDiscount(String name, double gpa)
{
        double credit;
        credit = gpa * 10.0;
}
}

答案1

得分: 0

你是不是在说这样的内容?

import java.util.Scanner;

public class BookstoreCredit {

    public static void main(String args[]) {
        String name;
        double gpa;
        Scanner inputDevice = new Scanner(System.in);

        System.out.print("Please enter your name >>> ");
        name = inputDevice.nextLine();
        System.out.print("Please enter your grade point average >>> ");
        gpa = inputDevice.nextDouble();

        System.out.print(name);
        System.out.print(", your GPA is ");
        System.out.print(gpa);
        System.out.print(", so your credit is " + computeDiscount(gpa));

    }

    public static double computeDiscount(double gpa) {
        double credit;
        credit = gpa * 10.0;
        return credit;
    }
}
英文:

Are you talking something like this?:

import java.util.Scanner;

public class BookstoreCredit {

    public static void main(String args[]) {
        String name;
        double gpa;
        Scanner inputDevice = new Scanner(System.in);

        System.out.print("Please enter your name >>> ");
        name = inputDevice.nextLine();
        System.out.print("Please enter your grade point average >>> ");
        gpa = inputDevice.nextDouble();

        System.out.print(name);
        System.out.print(", your GPA is ");
        System.out.print(gpa);
        System.out.print(", so your credit is " + computeDiscount(gpa));

    }

    public static double computeDiscount(double gpa) {
        double credit;
        credit = gpa * 10.0;
        return credit;
    }
}

huangapple
  • 本文由 发表于 2020年9月29日 07:13:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64110791.html
匿名

发表评论

匿名网友

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

确定