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

Thread: Arrays

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Arrays

    Hello can anyone help me write this program using blueJ.

    Write a Java program that will:
    Firstly prompt the lecturer to enter the number of students in a programming class in
    range 1-10.
    Secondly, for each student prompt the lecturer to firstly enter their name (string) and
    then secondly enter their test score (integer).
    Hint you should use two equal length arrays one to store the student names and
    one to store the student scores. We can then retrieve/update any student name/score
    pair by using the same index to access each separate array. You may assume that there
    will never be more than 10 students in the class.
    Thirdly, calculate and display the following results from the data entered.
    1. Average mark
    2. Name(s) of student(s) below the average mark
    3. Lowest mark
    4. Highest mark
    5. Name(s) of student(s) achieving highest mark

    This is what i have done so far:

    import uulib.*;
    public class Exam{
    public static void main (String [] args)
    {
    final int SIZE = 10;
    int [] mark = new int [SIZE];
    String [] name = new String [SIZE];

    for (int i = 0; i < mark.length; i=i+1)

    {
    name [i] = GUI.getString ("Enter name");
    mark [i] = GUI.getInt("Enter mark");


    }
    GUI.show (
    "Lowest mark =" + name + lowest (mark) + "\n" +
    "Highest mark = " + name + highest ( mark) +
    " Average mark = " + name + average (mark));

    }


    public static int highest (int[] nums)
    {
    int large = nums [0];

    for (int i = 1; 1<nums.length; i=i+1)
    {
    if (nums [1] > large)
    large = nums [i];
    }

    return large;
    }

    public static int lowest (int [] nums)
    {
    int small = nums[0];

    for (int i = 1; i<nums.length; i=i+1)
    {
    if (nums [i] < small)
    small = nums [i];
    }
    return small;
    }


    public static int average(int[] nums)
    {
    int total = 0;
    for (int i=0; i< nums.length; i++)
    {
    total = total + nums[i];
    }
    return total/nums.length;
    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,246
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Arrays

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Can you explain what problems you are having?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Arrays

    It allows me to input the mark and student name but the program does not show the highest and lowest mark

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,246
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Arrays

    the program does not show the highest and lowest mark
    Can you post what the program does show and add some comments about what it should show?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Arrays

    [B]hey i tried ur question...here is the code i thought about:

    Please don't do the OPs work for him. Help him to understand the problem and to find solutions. Don't spoonfeed full code.
    Last edited by Norm; December 7th, 2012 at 10:19 AM. Reason: Removed spoon feeding of code

Similar Threads

  1. Arrays ?
    By nhiap6 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 17th, 2012, 12:15 PM
  2. Help with Arrays
    By djhunt90 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 16th, 2012, 03:27 PM
  3. Need help using Arrays!
    By asb23698 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 4th, 2012, 06:47 PM
  4. Need Help with Arrays
    By zennbang in forum Object Oriented Programming
    Replies: 3
    Last Post: July 31st, 2011, 07:41 AM
  5. Arrays
    By mlan in forum Java Theory & Questions
    Replies: 2
    Last Post: February 26th, 2010, 10:23 AM