BlueJ error: incompatible types
Complete noob at Java here. School just started and I'm taking APCS. Our
teacher showed us this cool class called Scanner, but he hasn't taught us
it yet. I thought it was pretty cool, so I decided to research it more.
After I did a little research, I found out that it basically allows you to
use information imputed into the System into your code. I tried to make my
own little program using this code. The idea is very simple.
Ask the user to input his first name.
After receiving the users first name, ask him to verify that it is his
name (no spelling errors, wrong name, etc.).
Use if/else statement, if yes: print a thank you. if no: print a random
string making fun of him.
At this point I intended to use and if/else statement. This is something
that we as a class have yet to cover. After typing out my if else
statement, I got a compile-time error. Here's what BlueJ gave me:
incompatible type
This is the code:
public class useInfo
{
public static void main(String[] args)
{
String firstName;
String verifyFirstName;
Scanner keyboardInput = new Scanner(System.in);
Scanner verification = new Scanner(System.in);
System.out.print("Please Enter your first name here --->");
firstName = keyboardInput.nextLine();
System.out.println("Thank you! Your first name is " + firstName + " ,
correct?");
keyboardInput.close();
verifyFirstName = verification.nextLine();
if (verifyFirstName = "Yes") //this is the section I get the error on.
RIGHT HERE.
{
System.out.println("Great! Thanks for you time.");
}
else
{
System.out.println("You need to get your stuff together. How can
you not even type your own name correctly?");
}
}
}
Thanks in advance for your help!
Sincerely, Abdi
No comments:
Post a Comment