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 15 of 15

Thread: Please tell me what i did incorrect

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

    Default Please tell me what i did incorrect

    There are 7 errors in the following program...Tell me what i did incorrect and tell me how to fix it. Also, tell me where the errors are located and what type of errors i made, if they have a specific name
    Do not worry about the math calculations, abbreviations, or missing words in comments. But, I am unfamiliar with writing programs, so worry about the way it is written


    // A class that computes the sample statistics of the ages of
    // family members.
    public class FamilyStats
    {
    public static void main(String[] args)
    {
    /*
    math equations obtained from: */
    Sample Variance -- from Wolfram MathWorld

    // define some ages

    int momsAge= 42; dadsAge= 43;
    int myAge= 22, sistersAge= 16;
    int dogsAge= 6;

    // get the mean

    double ageSum = (momsAge + dadsAge + myAge + sistersAge + DogsAge);
    double average = ageSum / 5

    / calculate the sample variance
    double variance= 0.0;
    variance += (momsAge - average)*(momsAge - average);
    variance += (dadsAge - average)(dadsAge - average);
    variance += (myAge - average)*(myAge - average);
    variance += (sistersAge - average)*(sistersAge - average);
    variance += (dogsAge - average)*(dogsAge - average);
    variance = variance / 4;

    // get the std. dev
    double standardDev= Math.sqrt(variance);
    // output the results
    System.out.println(The sample age mean is: + average);
    System.out.println("The sample age variance is: " + variance);
    System.out.println("The sample age standard deviation is: " + standardDev);
    }


  2. #2
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Please tell me what i did incorrect

    What are the errors?

    I think you do need to change these int's in doubles:

    int momsAge

    Becasue else you won't get out a double value below hen you calculate the mean.

    Als try putting your code between code tags.
    Then it is easyer to read.
    Last edited by Purple01; September 27th, 2012 at 08:33 AM.

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

    Default Re: Please tell me what i did incorrect

    I do not know. I was told that i had 7 errors and i have looked at it for hours and havent found any, but there ARE 7 ...i am too inexperienced to notice them though

  4. #4
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Please tell me what i did incorrect

    Can you copy paste the red text?

    P.s. I adjusted my firts post.

  5. #5
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Please tell me what i did incorrect

    Also I think by looking at you code, that dadsAge is not defined as an int/double.

    Maybe you should make it:

    double momsAge= 42;
    double dadsAge= 43;
    double myAge= 22;
    double sistersAge= 16;
    double dogsAge= 6;

    Also you have a , between myAge and sistersAge.
    That is sure causing 1 error.
    Last edited by Purple01; September 27th, 2012 at 08:39 AM.

  6. #6
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please tell me what i did incorrect

    // A class that computes the sample statistics of the ages of
    // family members.
    public class FamilyStats
    {
    public static void main(String[] args)
    {
    /
    math equations obtained from: /
    Sample Variance -- from Wolfram MathWorld

    // define some ages

    int momsAge= 42; dadsAge= 43;
    int myAge= 22, sistersAge= 16;
    int dogsAge= 6;

    // get the mean

    double ageSum = (momsAge + dadsAge + myAge + sistersAge + DogsAge);
    double average = ageSum / 5

    / calculate the sample variance
    double variance= 0.0;
    variance += (momsAge - average)*(momsAge - average);
    variance += (dadsAge - average)(dadsAge - average);
    variance += (myAge - average)*(myAge - average);
    variance += (sistersAge - average)*(sistersAge - average);
    variance += (dogsAge - average)*(dogsAge - average);
    variance = variance / 4;

    // get the std. dev
    double standardDev= Math.sqrt(variance);
    // output the results
    System.out.println(The sample age mean is: + average);
    System.out.println("The sample age variance is: " + variance);
    System.out.println("The sample age standard deviation is: " + standardDev);
    }
    Last edited by fh123boys; September 27th, 2012 at 08:45 AM.

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

    Default Re: Please tell me what i did incorrect

    How do i put it in code tags?

  8. #8
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Please tell me what i did incorrect

    And also mind the capital letters.
    dogsAge = not the same as: DogsAge.

    Good luck.

  9. #9
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Please tell me what i did incorrect

    Remove the *

    [*code]
    code here
    [*/code]

  10. #10
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please tell me what i did incorrect

    It says" '.class' expected." at double momsAge= 42;...how do i fix it?

  11. #11
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Please tell me what i did incorrect

    I copy pasted your code in my program and these are your errors:

    Your code
    int momsAge= 42; dadsAge= 43;
    int myAge= 22, sistersAge= 16;
    int dogsAge= 6;

    But since you need to define them all:
    double momsAge= 42;
    double dadsAge= 43;
    double myAge= 22;
    double sistersAge= 16;
    double dogsAge= 6;

    Also in your code you have a , between myAge and sistersAge.
    And int cannot have text in it, only numbers.

    And dogsAge = not the same as DogsAge.

    And voila, it should work I think.

  12. #12
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Please tell me what i did incorrect

    What if you would make it: 42.0?

    (I am going home now, I am finished working, might look in this topic in 1 hours again. Good luck.)

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

    Default Re: Please tell me what i did incorrect

    still says class expected

  14. #14
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Please tell me what i did incorrect

    Quote Originally Posted by Purple01 View Post
    Also you have a , between myAge and sistersAge.
    That is sure causing 1 error.
    The following line of code:
    int myAge= 22, sistersAge= 16;
    Is perfectly legal java syntax.

  15. #15
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Please tell me what i did incorrect

    Quote Originally Posted by fh123boys View Post
    still says class expected
    Please post a fresh copy of the code and any error messages you have.

Similar Threads

  1. Can't work out how to detect and incorrect input
    By DrPerry in forum What's Wrong With My Code?
    Replies: 6
    Last Post: August 15th, 2012, 10:27 PM
  2. Incorrect results
    By kprofgold in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 28th, 2012, 07:08 PM
  3. Java Calculation Incorrect
    By cow23 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 14th, 2011, 07:09 AM
  4. Incorrect Key Input
    By risen375 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 28th, 2011, 01:17 PM
  5. [SOLVED] Code is correct, but incorrect output?
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 6th, 2011, 01:32 PM

Tags for this Thread