We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,939 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Program in java for reading username and password

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
1 Day
Discussion Span
7 Months Ago
Last Updated
4
Views
Julie29
Newbie Poster
2 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

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.

Julie29
Newbie Poster
2 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

JamesCherrill
... trying to help
Moderator
8,515 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0623 seconds using 2.75MB