Can anyone help me on this problem, i really have no idea how to do it since i'm new to these stuffs. So please be easy on me. Thanks !

Create the algorithm based on the following requirements:
Input:
Four grades per student are entered by the user.
HINT: accept grade1, grade2, grade3, grade4
Processing:
Get the average of the grades per student.
Output:
Arrange the average grades in descending order.
How the program works:
First Run:
Please enter grades of student:
80 91 85 90
Please enter grades of student:
80 91 85 90
Please enter grades of student:
90 86 95 91
Please enter grades of student:
0  0  0 0
Average grades:
90.5 86.5 78
Second Run:
Please enter grades of student:
80 91 85 90
Please enter grades of student:
80 91 85 90
Please enter grades of student:
90 86 95 91
Please enter grades of student:
75 82 91 95
Please enter grades of student:
85 88 89 90
Please enter grades of student:
0  0  0 0
Average grades:
90.5 88 86.5 85.75 78

Recommended Answers

All 8 Replies

Yes, we'll help, but you need to show some effort first. Post what you have done so far.

DaniWeb Member Rules include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Your question itself shows steps of the algorithm.
1. take input
2. calculate average
3. sort in decreasing order.

You will have to write proper algorithm by yourself.

Yes this is what i need. Some explanation.

first, check the previous posts. by not even trying to do anything yourself, even after being told that the community rules dictate you have to, your input is not very productive.
yes, we know that that is what you need, but this is not coderzzforhire or anything like that. we're volunteering to help you perform your tasks, not to do your work for you.

1.take input

It means your program should prompt users for an input. The input means a user type in whatever value you expected using keyboard.

2.calculate average

After you obtain all needed values (all grades/scores of a student), you calculate using mathematic equation to get the result. In this case, you are computing average value -- sum_of_all_values / total_number_of_input

3.check for termination of input

Once you have an average score/grade of a student, you need to determine whether the input is calling for termination. This is important because the requirement implicitly asks you to implement this part.

4.store the computation result

This is also an implicit step in your requirement. You need to store the result for later steps.

5.sort in decreasing order

Once your program stop accepting inputs (terminated values are entered), you need to sort the stored result you obtain from #4.

6.display the result

Then you need to display the sorted result from #5 on the console.

There are 3 combinations to accomplish #4, #5, and #6. One approach is to combine #4 and #5 together. Another approach is to combine #5 and #6 together. One more approach is to combine all #4, #5, and #6 together. But for clarity of steps, I separate them for you.

Ok, i think i'm on the wrong section because what i've thought is that i only have to use simple algorithms consisting of "if/else", "for". But this is the basic of java, so please forgive me. Here's what I've done so far.

begin
        input grade1[4], grade2[4], grade3[4], grade4[4]

        ave1 = grade1[0] + grade1[1] + grade1[2] + grade1[3]
        ave2 = grade2[0] + grade2[1] + grade2[2] + grade2[3]
        ave3 = grade3[0] + grade3[1] + grade3[2] + grade3[3]
        ave4 = grade4[0] + grade4[1] + grade4[2] + grade4[3]

        ave1 = ave1 / 4
        ave2 = ave2 / 4
        ave3 = ave3 / 4
        ave4 = ave4 / 4


        // largest
        if (ave1 > ave2 && ave1 > ave3 && ave1 > ave4) {
            largest = ave1
            }

            elseif (ave2 > ave1 && ave2 > ave3 && ave2 > ave4) {
            largest = ave2
            }

            elseif (ave3 > ave1 && ave3 > ave2 && ave3 > ave4) {
            largest = ave3
            }

            elseif (ave4 > ave1 && ave4 > ave2 && ave4 > ave3) {
            largest = ave4
            }


        // smallest
        if (ave1 < ave2 && ave1 < ave3 && ave1 < ave4) {
            smallest = ave1}

            elseif (ave2 < ave1 && ave2 < ave3 && ave2 < ave4) {
            smallest = ave2
            }

            elseif (ave3 < ave1 && ave3 < ave2 && ave3 < ave4) {
            smallest = ave3
            }

            elseif (ave4 < ave1 && ave4 < ave2 && ave4 < ave3) {
            smallest = ave4
            }

I don't know how to compare the 2nd and 3rd number. And also I'm thinking about using swap like this, but I don't know how to continue.

if(a<b)swap(a,b);// you write the swap function
if(a<c)swap(a,c);
if(a<d)swap(a,d);// now a has the largest value

You are preety good in your approach. But to sort the averages you need to search for sorting algorithms. Basically a loop needs to be implemented which each number and arranges it accordingly.

There are plenty of sorting algorithms, so you just need to pick one. Bubble sort is the most simpliest algorithm but is also one of the worst algorithm.

A simplified (and modified) algorithm of Bubble sort for an array could be as follows...

array <- an array to be sorted

function sortArray(array)
  n <- array size
  for i=1 up to n (inclusive)
    innerN <- i
    while innerN>0 and array[i]>array[innerN]   // ascending order
      swap(array[i], array[innerN])
      descrease innerN by 1
    end while
  end for
end function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.