-
May 25th, 2023, 11:00 PM
#1
Play for Ozzy (my program is not working correctly)
I have this cool program that uses a logical operator to join two conditions in an if statement. Basically for a person to get a job playing for Ozzy Osbourne you have to play a LesPaul and you have to have long hair. I did this program in C++ and I think it's cool so I wanted to transpose it over to a Java program.
But for some reason the statement in the if part does not run. Even if I enter LesPaul and Long the program wants to skip the statement that says "Congratulations you've got the gig!", and it wants to always print "Sorry you do not qualify for this gig".
I don't know why it wants to do that.
Here is my program:
Code:
import java.util.Scanner;
public class PlayForOzzy
{
public static void main(String[] args)
{
String guitar = "LesPaul";
String hairStyle = "Long";
String personsGuitar;
String personsHairStyle;
@SuppressWarnings("resource")
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the model of guitar you play: ");
personsGuitar = keyboard.nextLine();
System.out.print("Enter in your hairstyle: ");
personsHairStyle = keyboard.nextLine();
if(personsGuitar == guitar && personsHairStyle == hairStyle)
System.out.print("Congratulations! You got the gig!");
else
System.out.print("Sorry...you do not qualify for this gig");
}
}
I must be close but something is off somewhere.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|