0

Hi, can anybody help me with this? I am doing an Introduction to Programming module using Java and am stuck at this question. Write a program which reads in a username and a password, and expects the username to be "brian" and the password to be "spam". The program should print a welcome message if these are both correct. Thanks.

3
Contributors
3
Replies
7
Views
4 Years
Discussion Span
Last Post by JamesCherrill
Featured Replies
  • 1

    Lots of people here to help. Can you explain your problem? Post the code you are having problems with and ask any questions you have. Read More

  • There are quite a few syntax errors there - missing () etc. Compile your program to get a list of syntax errors and fix them (start at the top and re-compile after each one, as an error early in the code can disrupt parsing of the code that follows). Then … Read More

1

Lots of people here to help. Can you explain your problem? Post the code you are having problems with and ask any questions you have.

1

public class Bridget {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

    String username1; // Username of person
    String password1; // Password of person


    System.out.println (" Please enter a username:()");
    username1 = ;

    System.out.println (" Please enter a " + password1);
    password;

    if username1 = Brian;
    System.out.println("Welcome");

    else
    System.out.println ("Incorrect username");

    if (password1 = spam);
    System.out.println ("Welcome");

    else
    System.out.println("Incorrect password");

}end main( //)

end class //

This is what I have so far.

1

There are quite a few syntax errors there - missing () etc. Compile your program to get a list of syntax errors and fix them (start at the top and re-compile after each one, as an error early in the code can disrupt parsing of the code that follows).
Then a couple of hints:
To compare Strings you can't use == (even less =, which is assignment). YOU need the equals method (documented in the standard API doc for String)
You can use a Scanner with System.in to read input from the user. Google for more detail.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.