Results 1 to 2 of 2
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Rep Power

    Default Help with Structure

    Write a short program in java to iterate over a structure and print out the names of all users which have a score less than 70.
    At the end of the structure, also print out the average score of all users who scored 70 or higher.
    Assume a global function/procedure called print which prints all parameters passed to it and that the structure is called Structure.

    Java Code:
    Structure Prototype = [[Name1, Score1], [Name2, Score2], …]
    Example Structure = [[‘Tim’, 98], [‘Tom’, 80], [‘Mike’, 50], [‘Jason’, 25]]
    Example Output =

  2. #2
    susan is offline Member
    Join Date
    Jul 2007
    Rep Power


    Whilst iterating over the whole collection you should do two things. Firstly you print out the names of everyone who got less than 70, and secondly you should add up the scores of all the people who got more than 70 and at the same time you increment a value

    Java Code:
    int averageCount;
    int totalAmount;
    for(int i = 0; i < collection amount; i++)
    if(userScore[i] < 70)
    totalAmount += userScore[i];
    System.out.println("Average of those who scored higher than 70 is: " + (totalAmount/averageCount * 100));
    That's roughly how I personally think it should work. Mind you, I haven't coded in yonks so I could be wrong

    As for the two dimensional array, I'm sure you can figure that part out, it's simple enough to extract the correct value

Similar Threads

  1. Queue data structure
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 09:35 PM
  2. Java Array of Structure
    By PAffiliates in forum New To Java
    Replies: 1
    Last Post: 01-28-2008, 07:08 AM
  3. data structure code
    By vgvt in forum New To Java
    Replies: 1
    Last Post: 01-17-2008, 03:49 PM
  4. Control Structure Question
    By ibanez270dx in forum New To Java
    Replies: 1
    Last Post: 11-12-2007, 11:10 PM
  5. Use if then else structure, help
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:00 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