-2

So, this may look like a mess but I just started Java a few hours ago and I was building a program I've had in my head for a while. Currently, it hangs up at the last section where it asks if there were any others in the video. Any idea why this is happening? Starts at bottom with variable yn.

import java.util.Scanner;

public class Tagger {
  //inputs should include the type of video, who's in it, and what the game is called.
  //Later versions can alter this, including alternate game titles.
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);

    String mod = null;
    String who2 = null;     
    String group = "SmeggCo";

    System.out.println("Welcome to the Actagger! Let's get started.");
    System.out.println("To start, is this a mod spotlight or a Let's Play?");
    String type = input.nextLine();
    System.out.println("Awesome! A " + type + ", eh? Sounds fun!");
    try {
        Thread.sleep(3000);
    }
    catch (InterruptedException ex){
    }

    System.out.println("What game is it?");
    String game = input.nextLine();

    try {
        Thread.sleep(3000);
    }
    catch (InterruptedException ex){
    }
    System.out.println( game + "? I'll have to check that out!");
    if (type == "mod spotlight"){
        System.out.println("What was the mod's name?");
        mod = input.next();
        System.out.println("Huh, I've never heard of" + mod + ".");
    }

    System.out.println("Alright, last question. Who was in this video?");
    String who = input.next();
    System.out.println(who + " is pretty awesome!");
    try {
        Thread.sleep(3000);
    }
    catch (InterruptedException ex){
    }

    System.out.println("Was anyone else in the vid?");
    String yn = input.next();
    if (yn == "Yes"){
        System.out.println("Who?");
        who2 = input.next();            
        System.out.println("So " + who + " and" + who2 + "? Those two are weirdos!");
        String[] tags = new String[5]; //Setup final array of tags. Will add to this later in 2.0
        tags[0] = type;
        tags[1]=game;
        tags[2]=who;
        tags[3]=who2;
        tags[4]=mod;
        tags[5]=group;
        System.out.println("Here's your tags!");
        System.out.println(tags);
        System.out.println("Does that look right? Good!");
    }
    if (yn == "No"){
        String[] tags = new String[5]; //Setup final array of tags. Will add to this later in 2.0
        tags[0] = type;
        tags[1]=game;
        tags[2]=who;
        tags[3]=who2;
        tags[4]=mod;
        tags[5]=group;
        System.out.println("Here's your tags!");
        System.out.println(tags);
        System.out.println("Does that look right? Good!");
    }
}

}

Ben
  • 7,548
  • 31
  • 45
  • 3
    String comparison is not done using == but should be done with String#equals – MadProgrammer Aug 12 '14 at 12:03
  • 2
    Please don't post a huge block of code and say: "tell me why it behaves this way". It's a recipe for down votes. If you must ask questions of this sort, at least break it down to 2 or 3 lines where the program does not behave as you expect, and then ask for clarification on how those lines are supposed to behave. – Eric Leschinski Aug 12 '14 at 12:04
  • I'm sorry for the long block, this was my first post here and I wasn't sure how much people would need. – Actatus Aug 12 '14 at 14:09

1 Answers1

1

Your equality testing is wrong. You should use the equals() method, not ==

Ben
  • 7,548
  • 31
  • 45