15,998,003 members
1.00/5 (1 vote)
See more:
Question=

You are required to analyze the performance for Principles of Computer Programming subject
containing 135 students. Your program will prompt for final marks of each student, accumulate
the total and calculate the average. Display the average mark and the grade obtained
`<pre lang="text">`
Design a pseudocode and write a full java program to provide
the solution.

Table 2: Grade Category based on Average Mark
Average mark range // Grade Category
Below 50 // Low
50 to 79 // Good
80 and above // Excellent

What I have tried:

Java
```import java.util.*;
public class Mark {
public Mark () {
}

public static void main(String args[]) {
Scanner input = new Scanner (System.in);
int avgMark;

avgMark = input.nextInt();

if(avgMark >= 80)
{
}

else if (avgMark >= 50 && avgMark <= 79) {
}

else if (avgMark <= 50) {
}
}
}```
`<pre lang="java"><pre lang="java">`
Posted
Updated 2-Nov-20 20:36pm
v2

## Solution 1

Yes, your if clause is correct, but contains redundant checks. Igt can be replaced by the following code
Java
```if(avgMark >= 80)
{
}
else if (avgMark >= 50 )
{
}
else
{
}
```

tomatomoa 3-Nov-20 4:26am
thanks, but just now my friends said that it included loop and we must calculate and display the avgMark but I'm confuse right now. do you have any idea?

## Solution 2

In addition to what CPallini has said, I'd change it a little to use a function to return the grade, and print that:
Java
```public static String getGrade(int score) {
if(score >= 80) {
return "Excellent";
}
else if (score >= 50 ) {
return "Good";
}
return "Low");
}```

And then use that to print the result:
Java
`System.out.println("Grade: " + getGrade(studentScore));`
It's then a lot easier to move on the the second part of your task and repeat the scoring for the remaining 134 students, knowing that the "grading" part of the task is done and working.

tomatomoa 3-Nov-20 4:28am
thanks, the last part is useful, my friend said we must calculate and display the avgMark but I'm confused by it right now. do you have any idea?
OriginalGriff 3-Nov-20 5:00am
Well, you know how to calculate an average:

avg = Sum(marks) / NumberOf(marks)

e.g.:

avg = (1 + 5 + 7) / 3

So what part is giving you difficulties?
Where are you stuck?
What have you tried?
What help do you need?
tomatomoa 3-Nov-20 5:41am
I couldn't catch up thus fast. So based on my Rubik Question, is this like this?

avgMark = studentMark / 100

I'm sorry,

OriginalGriff 3-Nov-20 6:03am
No, think about it: you need to add up all the entered marks and count them. Then when you have the total of all marks, you can divide that by the count.

So start with a variable to hold the total, and add to it each time you go round the loop entering new values. Count it as well, then after that loop is finished you can work out the average.

Think about it - that's how you would do it manually: you'd get a calculator, and add each value to it one by one, then divide the total afterwards.
tomatomoa 3-Nov-20 8:46am
i tried but idk anymore,, this is my final answer of the question, there are many mistake right ; - ;

import java.util.*;
public class Mark {
public Mark () {
}

public static void main(String args[]) {
for(int i = 135; i < n; i++)

int avgMark;
int finalMark;

Scanner input = new Scanner (System.in);

avgMark = finalMark / 135

System.out.println(" pls enter your final mark: ");
finalMark = input.nextInt();

if(avgMark >= 80)
{
}

else if (avgMark >= 50 && avgMark <= 79) {
}

else if (avgMark <= 50) {
}

}
}