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: my code is not compiling

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question my code is not compiling

    i am beginner in java. i had this problem but it wont compile it says i have an error in the system.out method. but i cant find it.
    heres what i got.


    import javax.swing.JOptionPane;

    public class Name
    {
    public static void main(String[] args)
    {
    String name;
    int age = 0;
    double annualPay = 0;
    double averageMonthlyPay = 0;
    averageMonthlyPay = (annualPay/12);

    name = JOptionPane.showInputDialog(null, "What is your name? ");

    age= Integer.parseInt(JOptionPane.showInputDialog(null, "What is your age? "));

    annualPay= Double.parseDouble(JOptionPane.showInputDialog("Wh at is your annual pay? "));


    System.outprintln( "My name is," + name + "my age is"+ age +
    "and/nMy annual pay is" + annualPay +
    "/nMy average montly pay is", + averageMonthlyPay);


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: my code is not compiling

    Welcome! If it's your first time here please read.
    Please post the full error message that you get.
    It seems like you forgot to put a dot symbol b/w out and println.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: my code is not compiling

    thank you, i put the missing period and i know get this error.2014-01-29-22-50-30.jpg

  4. #4
    Member Ganeprog's Avatar
    Join Date
    Jan 2014
    Location
    Chennai,India
    Posts
    80
    My Mood
    Love
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default Re: my code is not compiling

    Hi,



    your image is not clear. Please copy and post directly what error you are getting.

    thanks,

  5. #5
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: my code is not compiling

    Please format your code and Paste the full error message rather than an image.

    System.outprintln( "My name is," + name + "my age is"+ age +
    "and/nMy annual pay is" + annualPay +
    "/nMy average montly pay is", + averageMonthlyPay);
    Remove the comma that is before the "+ averageMonthlyPay". And you always going to get 0.0 for averageMonthlyPay because you calculated that before taking the input from user for annualPay.

  6. The Following User Says Thank You to aprabhat For This Useful Post:

    kittykat0953 (February 4th, 2014)

  7. #6
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: my code is not compiling

    ok thank you. so in order to get the right amount for annual pay i have to move the average monthly equation elsewhere

  8. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: my code is not compiling

    i have to move the average monthly equation elsewhere
    The code must assign values to all the variables used in the equation BEFORE using them in any computations.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    kittykat0953 (February 4th, 2014)

  10. #8
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: my code is not compiling

    thank you, i found and fixed the program all together. thanks for your help. btw instead of starting a new thread i am trying to get some initials using also the joptionpane. i ask the user there first , middle and last name. but i need to get the initials of that input . but idk what to do.

    this is what i have so far'


    import javax.swing.JOptionPane;

    public class Initials
    {
    public static void main(String[] args)
    {
    String name;
    String initials;

    name = JOptionPane.showInputDialog(null, "What is your first, middle, and last name? ");

    initials =

    System.out.println( "Name: " + name + " \nInitials:" + );

    }
    }

  11. #9
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: my code is not compiling

    As you are taking first, middle, and last name as a single String use split(String regex) method to split the String name for first, middle and last name, and then use chatAt(int position) method to get the initials.

    For more details on String Class Read this

  12. The Following User Says Thank You to aprabhat For This Useful Post:

    kittykat0953 (February 4th, 2014)

  13. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: my code is not compiling

    Can you give an example? Show what is in the name variable and what value you want to have in the initials variable.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #11
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: my code is not compiling

    i using the joption to get input from a user. SO as an example the program would ask for first middle and last name and display it as
    Name : Kevin Fern Flower
    Initials: K.F.F

    what im trying to figure out is what to use to extract the initials from the input instead of asking for the initials . i want them to be generated after they put there name.
    idk how to write that in code yet.any help

  15. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: my code is not compiling

    If there are spaces between the parts of the name, the parts could be separated by using the split() method.
    The String class has methods that can be used to get the first character in a String.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #13
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: my code is not compiling

    do you know an article on her on how to do this

  17. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: my code is not compiling

    Which part are you having problems with?
    Splitting the full name into separate parts
    Getting the first character of each part
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Error while compiling.
    By Troy05 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 21st, 2013, 01:16 PM
  2. Help compiling!
    By NoobOfTheMonth in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 19th, 2013, 06:27 AM
  3. Compiling Java
    By TANKDS in forum Java Theory & Questions
    Replies: 6
    Last Post: February 6th, 2012, 01:05 PM
  4. Compiling
    By yavo in forum Java Theory & Questions
    Replies: 1
    Last Post: December 24th, 2011, 06:42 AM
  5. Help with Compiling
    By w.spidey in forum Object Oriented Programming
    Replies: 10
    Last Post: September 9th, 2010, 01:48 PM