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

Thread: Help me please !

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help me please !

    Hi

    I have to solve this program and I don't have too much time could you please help me ..
    if someone can solve it or explain it to me its will be better ..

    ------------------------------
    Write a java program that calls the following methods:
    1. ReadStudentsData that takes as parameters an array NAMES of String and another array SCORES of int. It should read an unspecified number of students’ scores and names. This method will return the number of students’ data read.
    To stop entering data, the user must type a negative score. A valid score is a number between 0 and 100. Assume that the total number of students’ data is 10.
    2. CalculateAverage takes as parameters the array SCORES and the number of students. It should calculate and return the class average.
    3. AboveAverageNumber takes as parameters the array SCORES, the number of students and the average. It should determine how many scores are above or equal to the average.
    4. BelowAverageNumber takes as parameters the array SCORES, the number of students and the average. It should determine how many scores are below the average.
    5. BestStudents takes as parameters NAMES of String, SCORES of int and the number of students. It should determine and display the students’ names who got the best score.
    6. WorstStudents takes as parameters NAMES of String, SCORES of int and the number of students. It should determine and display the students’ names who got the worst score.

    thank you

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help me please !

    What have you tried?
    Do you have any specific questions about your assignment?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help me please !

    yes I wrote it above its about ( array )

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help me please !

    I wrote it above
    What was posted looks like the assignment, not your questions.
    Do you have any specific questions about your assignment?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help me please !

    okey I want to know how can I determine how many scores are above or equal to the average.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help me please !

    how can I determine how many scores are above or equal to the average.
    Use a loop to go through the list of scores and inside the loop use an if statement to compare the scores against the average. Count those that are in the desired range.
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    FTMMM (December 19th, 2013)

  8. #7
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help me please !

    Thnx Norm I got that

  9. #8
    Junior Member
    Join Date
    Dec 2013
    Location
    Estonia
    Posts
    18
    My Mood
    Happy
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Help me please !

    Do you have more questions? Perhaps i can help too

  10. The Following User Says Thank You to clyxee For This Useful Post:

    FTMMM (December 19th, 2013)

  11. #9
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help me please !

    I tried to do it twice but it didn't work . there are a lot of errors and I didn't know how to fix it .

     import java.util.*;
        public class assignment_3  
       {
          static Scanner console=new Scanner(System.in);
           public static void main(String[]args)
          {int i,j,avg;
             String name;
             int grad;
             int[]tab1=new int[1000];       
             String[]tab2=new String[1000];
     
     
     
                for (i=0;i<tab1.length;i++)
     
                {
                  System.out.println("enter a grade of student , to stop enter -1");
             grad=console.nextInt();
             while (grad!=-1)
     
             if (grad<=100&&grad>=0)
                  tab1[i]=grad; 
     
                   else
     
                      System.out.print("error  in the grade it more than 100 or less than 0 ");
     
                   for(j=i;j<=i;j++)
     
     
     
                   {
                      System.out.print("enter the name of the student");
                      name=console.next();
                      tab2[j]=name;
     
     
                   }    
     
             }
     
             avg=calculate(tab1);
             System.out.print("the avrage of the student is"+avg);
          }
           public static  int calculate(int[]tab1)
          {
             int sum,i,avg;
             sum=0;
             for(i=0;i<tab1.length;i++)
                sum=sum+tab1[i];
             avg=sum/i;
             return avg;
          }
     
       }

    import jave.util.*;
    public class assignment
    { 
    static Scanner console=new Scanner(System.in);
    public static void main (String[]args)
    {int s;
    String[]name=new String[s];
    int[]mark=new int[s];
    System.out.print("plaese enter the number of the student");
    S=console.nextInt();
    enter(name,mark);
     
    } 
    public static void enter(String[]name,int[] mark)
    {
    int i;
    int m;
    int n;
    for(i=0;i<name.length;i++)
    {
    do
    System.out.print("enter the mark of the student")
    m=consol.nextInt()
    while (m>100&&m<0)
    {
     
    System.out.print("error, enter the mark roght");
    m=console.nextInt();
    }
    mark[i]=m;
    System.out.println("enter name of the student");
    name[i]=console.next();
    System.out.println("enter the  number of the student,to stop enter -1")
    n=console.nextInt();
    while(n!=-1);
    }
    }
     
     
     
    }
    Last edited by Norm; December 19th, 2013 at 06:02 AM. Reason: changed quote tags to code

  12. #10
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help me please !

    Post the errors.

  13. #11
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help me please !

    1.error
    when I want to stop running it didn't work .

    2.error
    assinment.java:22: error: while expected
    system.out.println("enter the mark of the student");

    assinment.java:23: error: illegal start of expression
    m=consol.nextInt();
    ^
    assinment.java:23: error: ')' expected
    m=consol.nextInt();
    ^
    assinment.java:23: error: ';' expected
    m=consol.nextInt();

    assinment.java:33: error: ';' expected
    System.out.println("enter the number of the student,to stop enter -1")

    5 errors

  14. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help me please !

    The assignment class has lost all its formatting. The nested statements need to be indented like those in the assignment_3 class. Please edit the post and fix the formatting of the code.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #13
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help me please !

    I don't get it how can I fix the formatting of the code

    --- Update ---

    what about assignment_3 why I can't run it correctly

  16. #14
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help me please !

    Your code indenting and formatting is all over the place, making your code very difficult to read and the errors harder to spot.

    I recommend that you enclose all clauses in braces, even the single-line clauses. Get rid of unnecessary blank lines. Why have the first line of a for clause separated from the for statement by 5 blank lines? Make sure you have matching open/close braces, they're in the right places, and they line up properly.

    Once you get the code formatted correctly, recompile and repost the in code tags followed by any errors you still want help with.

  17. #15
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help me please !

    I tried my best it didn't wooooork .what should I do I'm beginner I don't know exactly what I have to correct in assignment_3 it works well but it won't stop what I have to do to make it stop and go to the next operation.

  18. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help me please !

    Edit the code for the class Assignment_3 so that it looks like this:
           final Runnable doHelloWorld = new Runnable() {
               public void run() {
                   System.out.println("Hello World on " + Thread.currentThread()); 
               }
           };
     
           Thread appThread = new Thread() {
               public void run() {
                   try {
                       SwingUtilities.invokeAndWait(doHelloWorld);
                   }
                   catch (Exception e) {
                       e.printStackTrace();
                   }
                   System.out.println("Finished on " + Thread.currentThread()); 
               }
           };
           appThread.start();

    There should NOT be any code following a {
    or before a }
    The } should be in the same column as the start of a line with the { that it pairs with.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #17
    Junior Member
    Join Date
    Dec 2013
    Location
    Estonia
    Posts
    18
    My Mood
    Happy
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Help me please !

    if you are doing your code at eclipse then ctrl+shift+f makes the code beautiful.