Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: boolean

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation boolean

    I have a code and it gives me 4 errors every time that I compile my code, I don't know what is wrong with my code.
    Can someone help me please???? I am using boolean variables here is part of the code:

    {

    boolean done= false;

    while(!done)
    {

    String password= JOptionPane.showInputDialog(null, "Enter Password:");

    if (password==null)


    {
    finish();

    }

    try
    {
    if (checkPassword==true)
    {
    done = true;
    }
    }
    catch
    {}

    JOptionPane.showMessageDialog(null, "Your entry was incorrect! Please try again...", null, JOptionPane.ERROR_MESSAGE);

    }
    JOptionPane.showMessageDialog(null, "Your entry was correct!");
    }

    }

    public static void finish()

    {

    System.exit(0);

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,994
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: boolean

    gives me 4 errors every time that I compile my code
    Please copy the full text of the error messages and paste it here so we can see what the problems are.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: boolean

    [QUOTE=Norm;109146]Please copy the full text of the error messages and paste it here so we can see what the problems are.

    D:\College\Java ++\Lab 8\PasswordManager.java:44: '(' expected
    {}
    ^
    D:\College\Java ++\Lab 8\PasswordManager.java:46: <identifier> expected
    JOptionPane.showMessageDialog(null, "Your entry was incorrect! Please try again...", null, JOptionPane.ERROR_MESSAGE);
    ^
    D:\College\Java ++\Lab 8\PasswordManager.java:60: '}' expected
    }
    ^
    3 errors

    Tool completed with exit code 1

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,994
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: boolean

    PasswordManager.java:44: '(' expected
    What is the code on line 44? Did you try putting a ( where the compiler was expecting it?

    PasswordManager.java:46: <identifier> expected
    You need to format the code so that it can be easily read and understood. This error might mean the {}s are not correctly positioned.

    PasswordManager.java:60: '}' expected
    You need to format the code so that it can be easily read and understood. This error might mean the {}s are not correctly positioned.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: boolean

    It doesn't work

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,994
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: boolean

    Post the code and the full text of the error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: boolean

    import javax.swing.JOptionPane;
    public class PasswordManager

    {

    private static String masterPassword = "secret3";

    public static void main(String[] args)

    {

    boolean done= false;

    while(!done)
    {

    String password= JOptionPane.showInputDialog(null, "Enter Password:");

    if (password==null)


    {
    finish();

    }

    try
    {
    if (checkPassword==true)
    {
    done = true;
    }
    }
    catch
    }
    JOptionPane.showMessageDialog(null, "Your entry was incorrect! Please try again...",null JOptionPane.ERROR_MESSAGE);


    JOptionPane.showMessageDialog(null, "Your entry was correct!");
    }

    }

    public static void finish()

    {

    System.exit(0);

    }
    }



    ERRORS:
    D:\College\Java ++\Lab 8\PasswordManager.java:44: '(' expected
    }
    ^
    D:\College\Java ++\Lab 8\PasswordManager.java:45: ')' expected
    JOptionPane.showMessageDialog(null, "Your entry was incorrect! Please try again...",null JOptionPane.ERROR_MESSAGE);
    ^
    2 errors

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,994
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: boolean

    Did you see this part of my post:
    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    The code you posted needs to be formatted so it can be read and understood.
    The indentations need to be fixed. There are too many statements that start in the first column.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: boolean

    I don't know how to wrap my code. I don't know what you mean by that. Sorry, I am new in this page....

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,994
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: boolean

    Edit your post
    Put this tag before the code:
    [code=java]


    <YOUR CODE HERE>

    Put the following tag after your code.
    [/code]

    It should look like this when you save it:
    public class Test_SL {
     
      	public static void main(String[] args) {

    Also the code needs to properly indented.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: boolean

    import javax.swing.JOptionPane;
    public class PasswordManager
     
    {
     
    	private static String masterPassword = "secret3";
     
        public static void main(String[] args)
     
    {
     
    	boolean done= false;
     
    	while(!done)
    	{
     
    	String password= JOptionPane.showInputDialog(null, "Enter Password:");
     
    	if (password==null)
     
     
    	{
    finish();
     
    }
     
    try
    {
    if (checkPassword==true)
    {
    	done = true;
    }
    }
    catch
    }
    	JOptionPane.showMessageDialog(null, "Your entry was incorrect! Please try again...",null JOptionPane.ERROR_MESSAGE);
     
     
    	JOptionPane.showMessageDialog(null, "Your entry was correct!");
    }
     
    }
     
    public static void finish()
     
    {
     
        System.exit(0);
     
    }
    }

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,994
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: boolean

    That's the first step. Now the code needs to be properly formatted.
    Nested statements need to be indented 3-4 spaces.
    }s should be beneath the start of the statement with the {

    There should not be two }s one beneath the other. The inner one should be indented.

    There are lots of examples on the forum. For example:
    Help with editing offscreen graphics
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: boolean

    How about like this?? Pleaseee help me!! I am trying to undestand Java, but it is a little difficult to me. I am reading my book, but, I don't understand it I have to turn this project tonight. Here is the code:

    import javax.swing.JOptionPane;
    public class PasswordManager
     
    {
    	private static String masterPassword = "secret3";
     
        public static void main(String[] args)
    }
    {
    	boolean done= false;
     
    	while(!done)
    }
     
    	String password= JOptionPane.showInputDialog(null, "Enter Password:");
     
    	if (password.equals(password)
    {
     
    finish();
     
    }
     
    	try
    {
    	if (checkPassword.equals(checkPassword)
     
    	done = true;
     
    }
    	catch
    {
    	JOptionPane.showMessageDialog(null, "Your entry was incorrect! Please try again...",null JOptionPane.ERROR_MESSAGE);
     
    	JOptionPane.showMessageDialog(null, "Your entry was correct!");
     
    public static void finish()
     
    }
    	return code;
        System.exit(0);
     
    }
    }

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,994
    Thanks
    52
    Thanked 2,274 Times in 2,245 Posts

    Default Re: boolean

    The code still is not formatted correctly. Too many } are in the first column.

    }s should be beneath the start of the statement with the {
      void aMethod() {
          if(true) {
          ...
          }
       } //  end aMethod()

    It makes it very hard to read and understand code that is not properly formatted.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Boolean help
    By dx2731 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 3rd, 2013, 06:50 AM
  2. What does '^' do? Is this a boolean?
    By ColeTrain in forum Java Theory & Questions
    Replies: 2
    Last Post: October 19th, 2012, 02:58 PM
  3. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 09:56 AM
  4. Some help with boolean
    By JPetroSS in forum Java Theory & Questions
    Replies: 3
    Last Post: November 2nd, 2010, 05:38 AM
  5. [SOLVED] Modification of Boolean function in Java program
    By lotus in forum Java SE APIs
    Replies: 4
    Last Post: July 10th, 2009, 10:15 AM

Tags for this Thread