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

Time:09-24

I need my code to display the names, 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? I also need to write if-else statements for the program to print out various statements based on various conditions. I get an error like java can find symbol: variable credit [enter image description here][1]

public static void main(String[] args) {
        double gpa;  //declaring GPA has a double for calcuating
        // adding in the scanner
        Scanner inputDevice = new Scanner(System.in);
        // adding statement to make user input their name
        System.out.print("Please enter your name");
        //  Print out the line
        String name = inputDevice.nextLine();
        // make end user enter current GPA
        System.out.println("Enter your GPA");
        // GPA value gets input by the end user
        gpa = inputDevice.nextDouble();
        System.out.print(name);
        //Printing name
        System.out.print(", your GPA is ");
        //printing out user entered GPA
        System.out.print(gpa);

        if (gpa < 2.0) {
            System.out.println(name   "you GPA is"   gpa   " ,  your semester is fall", " your credit is "   credit   ", and your gpa needs improvement");

        } else if (gpa == 3.0) {
            System.out.println(name   "you GPA is"   gpa   " ,  your semester is fall", " your credit is "   credit   ", and your gpa is a B");
        } else if (gpa > 2.0) {
            System.out.println(name   "your GPA is "   gpa   ", your semester is fall", " your credit is"   credit   "and your GPA is above average ");
        }

    }


    public static double computeCredit(double gpa) {
        double credit;
        credit = gpa * 10;
        return credit;
        // returns final credit * 10
    }
}


  [1]: https://i.stack.imgur.com/31ZfH.png

CodePudding user response:

You didn't initialize creadit and assign in the main function.

CodePudding user response:

The reason why your program didn't display credit was because computeCredit() was never called in the first place. All you have to do to fix it was call the function and return the value to the variable you were using it for.

double gpa = inputDevice.nextDouble();
double credit = computeCredit(gpa);

You also have an error possibly because of concatenating statements the wrong way. Since you are using for concatenation, there is no need to add , too.
Do change

System.out.println(name   "you GPA is"   gpa   " ,  your semester is fall", " your credit is "   credit   ", and your gpa needs improvement");

to this

System.out.println(name   " your GPA is"   gpa   " ,  your semester is fall"   " your credit is "   credit   ", and your gpa needs improvement");
  •  Tags:  
  • java
  • Related