Results 1 to 5 of 5

Thread: Newbie Help

  1. #1
    mattkid is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default Newbie Help

    Hey guys can anyone figure out why this will not compile. It is a test file for a class I wrote that seems ok. I am very new to java and hope it is something easy. Thanks

    public class Examone
    {

    public static void main(String[] args)
    {
    String input;

    Madlib myMadlib = new Madlib();

    {

    input = JOptionPane.showInputDialog("Please enter a adjective ");
    myMadlib.setAdj1(input);

    input = JOptionPane.showInputDialog("Please enter a First name ");
    myMadlib.setFirst(input);

    input = JOptionPane.showInputDialog("Please enter a illness ");
    myMadlib.setIllness(input);

    input = JOptionPane.showInputDialog("Please enter a plural noun ");
    myMadlib.setNoun1(input);

    input = JOptionPane.showInputDialog("Please enter a adjective ");
    myMadlib.setAdj2(input);

    input = JOptionPane.showInputDialog("Please enter a number ");
    myMadlib.setCookies(input);

    input = JOptionPane.showInputDialog("Please enter a adjective ");
    myMadlib.setAdj3(input);

    input = JOptionPane.showInputDialog("Please enter a noun ");
    myMadlib.setNoun2(input);

    input = JOptionPane.showInputDialog("Please enter a place ");
    myMadlib.setPlace(input);

    input = JOptionPane.showInputDialog("Please enter a number ");
    myMadlib.setDegree(input);

    input = JOptionPane.showInputDialog("Please enter a job occupation ");
    myMadlib.setJob(input);

    }

    JOptionPane.showMessageDialog(null, + myMadlib.setAdj1() + "will not be attending school online today. He/she has come down with a case of" + myMadlib.setFirst() + "and" + myMadlib.setIllness() + "has a horrible" + myMadlib.setNoun1() + "and a/an" + myMadlib.setAdj2() + "fever. He/She has tossed their cookies" + myMadlib.setCookies() + " times.");



    JOptionPane.showMessageDialog(null, "We have made an appointment with the" + myMadlib.setAdj3() + "Dr." + myMadlib.setNoun2() + " who studied for many years in" + myMadlib.setPlace() + "and has" + myMadlib.setDegree() + "degrees in" + myMadlib.setJob(). "He will send you all the information you need. Thank You!");

    JOptionPane.showMessageDialog(null, "Sincerely, Your favorite student");
    System.exit(0);
    }

    }
    }

  2. #2
    logicbug's Avatar
    logicbug is offline Member
    Join Date
    Jan 2009
    Location
    The Great White North, eh?
    Posts
    76
    Rep Power
    0

    Default

    what is the error you are getting?

  3. #3
    mattkid is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default

    Microsoft Windows [Version 6.0.6001]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.




    3 errors

    c:\java>javac Examone.java
    Examone.java:56: <identifier> expected
    JOptionPane.showMessageDialog(null, "We have made an appointment with
    the" + myMadlib.setAdj3() + "Dr." + myMadlib.setNoun2() + " who studied for man
    y years in" + myMadlib.setPlace() + "and has" + myMadlib.setDegree() + "degrees
    in" + myMadlib.setJob(). "He will send you all the information you need. Thank Y
    ou!");



    ^
    Examone.java:56: ';' expected
    JOptionPane.showMessageDialog(null, "We have made an appointment with
    the" + myMadlib.setAdj3() + "Dr." + myMadlib.setNoun2() + " who studied for man
    y years in" + myMadlib.setPlace() + "and has" + myMadlib.setDegree() + "degrees
    in" + myMadlib.setJob(). "He will send you all the information you need. Thank Y
    ou!");




    ^
    Examone.java:63: class, interface, or enum expected
    }
    ^
    3 errors

    c:\java>

  4. #4
    mattkid is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default

    Is my code that bad?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by mattkid View Post
    Is my code that bad?
    Yes sorry to say, but it is. You are breaking one of the cardinal rules of coding: you are trying to add good code to bad, and this means that your entire process of coding is wrong.

    I'd scrap this code and start over, and this time only add good code to good. By this, I mean to only add a small amount of code at a time, compile the program after adding this small amount of code, and immediately fix any errors you find then and there. Do not try to add any more code until the current program compiles (and if possible, runs) error free. If you don't do this you'll end up with what you have now: a holy mess.

    A few other suggestions: Make sure you're importing your JOptionPane class, and make sure that you're not calling setXXXX methods when you should be calling getXXX methods.

Similar Threads

  1. I am newbie
    By Seoplanner in forum Introductions
    Replies: 0
    Last Post: 11-11-2008, 01:22 PM
  2. :) newbie...........
    By Somitesh Chakraborty in forum Introductions
    Replies: 1
    Last Post: 08-19-2008, 09:00 AM
  3. newbie newbie newbie
    By krislogy in forum New To Java
    Replies: 9
    Last Post: 08-15-2008, 12:28 AM
  4. newbie needs help...
    By vicky08 in forum New To Java
    Replies: 2
    Last Post: 03-31-2008, 04:26 PM
  5. Newbie
    By CSnoob87 in forum Introductions
    Replies: 2
    Last Post: 02-18-2008, 08:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •