user5473706 user5473706 - 2 months ago 26
Java Question

User input for Java

I am trying to create a program where you enter a letter grade then it will out put the correct grade point.

I have this:

public static int convertToGradePoint(String letterGrade) {

int grade;
System.out.println("Please enter your letter grade: ");
letterGrade=user_input.next();

if (letterGrade = "A+") {
grade = 12;
}

else if (letterGrade = "A") {
grade = 11;
}

else if (letterGrade = "A-") {
grade = 10;
}

else if (letterGrade = "B+") {
grade = 9;
}

else if (letterGrade = "B") {
grade = 8;
}

else if (letterGrade = "B-") {
grade = 7;
}

else if (letterGrade = "C+") {
grade = 6;
}

else if (letterGrade = "C") {
grade = 5;
}

else if (letterGrade = "C-") {
grade = 4;
}

else if (letterGrade = "D+") {
grade = 3;
}

else if (letterGrade = "D") {
grade = 2;
}

else if (letterGrade = "D-") {
grade = 1;
}

else if (letterGrade = "F") {
grade = 0;
}

else {
grade = "Invalid";
}
return grade;
}


When I go to compile it it says it cannot find symbol for user_input.

Please help

Answer

First you have to import the javaScanner Utility. (Before the class declaration.)

import java.util.Scanner

Then create an object of it like

Scanner user_input = new Scanner( System.in );

Now you can use this user_input object to take input from users

Have a good time