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: Multi-dimension ArrayList example

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

    Post Multi-dimension ArrayList example

    Declare an array of 25 student scores in a test. Fill the array with random numbers between 1 and 100.
    Get the average of all marks.
    get the average of all students who scored an ‘A’ grade: 80% or over.
    how do i write this program


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Multi-dimension ArrayList example

    Start here (link below)
    The Java™ Tutorials

    If you still need help, read this before asking again: (link below)
    How To Ask Questions The Smart Way

    db

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Multi-dimension ArrayList example

    See this post for how to make multi-dimension ArrayLists: Multi Dimensional ArrayList example

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Multi-dimension ArrayList example

    For a beginning, I think you just need a Student class with name, score and grade attributes. Then, you can define an arraylist of Student with a length of 25. Prompt for student name, use the java.util.Random class to generate a random score for the students, test whether the score generated is more than 80, etc, and assign the relevant score. Add this student to the arraylist. Something like this:

    public class Student {
      private String name;
      private int score;
      private char score;
     
      public void setName( String name ) {
        this.name = name;
      }
     
      public String getName() {
         return name;
      }
     
      public void setScore( int score ) {
        this.score = score;
      }
     
      public int getScore() {
        return score;
      }
     
      public void setGrade( char grade ) {
        this.grade = grade;
      }
     
      public char getGrade() {
        return grade;
      }
     
      public void main( String[] args ) {
        List<Student> students = new ArrayList<Student>();
     
       int i = 0;
       while( i < 25 ) {
            // Generate your scores and grades here
       }
      }
     
     
    }

    I hope this helps.

Similar Threads

  1. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java SE API Tutorials
    Replies: 4
    Last Post: December 21st, 2011, 04:44 AM
  2. Multi Dimensional Array help NEEDED URGENT
    By bonjovi4u in forum Loops & Control Statements
    Replies: 5
    Last Post: February 13th, 2010, 12:44 AM
  3. Multi-dimension ArrayList example
    By helloworld922 in forum Java Programming Tutorials
    Replies: 1
    Last Post: February 3rd, 2010, 11:01 AM
  4. slicer dimension in MDX
    By retail_deepa in forum Java Servlet
    Replies: 3
    Last Post: August 28th, 2009, 04:01 AM
  5. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 01:11 PM