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

Thread: Assignment please Help :(

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wink Assignment please Help :(

    Our teacher was always on leave and so she doesn't teach us about java programming. She always leave a problem to us without even knowing how to deal with that kind of problem and what codes should we use for it.

    Here's the problem I hope you can help me.


    1. Write a program that would store the square of the first 7 even numbers (2, 4, 6, 8, 10, 12, 14) into array with 7 elements. Program must then display all the array elements together with its sum.


    2. Barney has 10 children. Write a program that would enter the age of his 10 children into an array with 10 elements. The age of his youngest child will go into the 1st element and so on with the age of the oldest child going into the last element. Program must then display the following:

    a. age of all his children form the oldest to the youngest.
    b. The average age
    c. Count of all teenagers (teenagers are from age 13 – 19, inclusive)
    d. Count of all adults (adults are age 20 and above)


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Assignment please Help :(

    That's not how this works. We are not a homework service. What have you done so far? Where are you stuck? Please read the link in my signature on asking smart questions, then post an SSCCE with a specific question.

    You violated just about every unwritten rule about posting. Your post title is vague and will be ignored by most users. Complaining about your educator makes you seem lazy- many people here are self-taught, without the aid of a classroom, an educator, classmates, etc. And simply dumping your homework questions here pretty much guarantees that nobody is going to help you.

    But like I said, post an SSCCE demonstrating what you tried and where you're stuck, ask a specific question, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Assignment please Help :(

    Uhm okay so I'm now only stuck with the number 2 problem I don't know the codes for how to output letter c and d
    here's my code:

    import java.util.Scanner;
    import java.util.Arrays;
     
    public class arrays{
    public static void main(String args[]){
     
    int sum=0;
    int average;
    int age = 10;
     
    int []number = new int[age];
     
    Scanner input = new Scanner(System.in);
     
     
    for(int index=0; index<age; index++)
    {
    System.out.print("Enter Barney's children's age: ");
    number[index] = input.nextInt();
    }
    Arrays.sort(number);
    System.out.println("Ages of Barney's children are sorted in ascending order"+"\n"+ Arrays.toString(number));
    System.out.println();
     
    for(int i=0; i<= 9; i++)
      sum = sum + number[i];
        System.out.print("the average age is " + sum/10+"\n");
     
     
    }
    }

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Assignment please Help :(

    Well, how would you do this "by hand" without a computer or code? Write out what you're trying to do, in English, in specific steps. Pretend you have a friend who has no idea how to figure out how many people are teenagers and how many are adults. When you have instructions that you could give to this friend, you'll have an algorithm that should be pretty easy to translate to code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Really need help on assignment
    By coorscollector in forum Java Theory & Questions
    Replies: 2
    Last Post: January 16th, 2012, 06:08 PM
  2. please help me in my assignment :(
    By asdfg in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 18th, 2010, 07:59 AM
  3. need help on an assignment :(
    By gamfreak in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 23rd, 2010, 04:20 PM
  4. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  5. Need help with assignment
    By TonyL in forum Loops & Control Statements
    Replies: 2
    Last Post: February 20th, 2010, 09:44 PM

Tags for this Thread