Click here to Skip to main content
14,974,887 members
Please Sign up or sign in to vote.
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;
      
      System.out.println(" Your Score: ");
      avgMark = input.nextInt();
      
      if(avgMark >= 80)
      {
          System.out.println("Grade: Excellent");
      }
      
      else if (avgMark >= 50 && avgMark <= 79) {
          System.out.println(" Grade: Good ");
      }
      
      else if (avgMark <= 50) {
          System.out.println(" Grade: Low ");
      }
    }
}
<pre lang="java"><pre lang="java">
Posted
Updated 2-Nov-20 20:36pm
v2

Yes, your if clause is correct, but contains redundant checks. Igt can be replaced by the following code
Java
if(avgMark >= 80)
     {
         System.out.println("Grade: Excellent");
     }
     else if (avgMark >= 50 )
     {
         System.out.println(" Grade: Good ");
     }
     else
     {
         System.out.println(" Grade: Low ");
     }
   
Comments
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?
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.
   
Comments
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++)

String grade;
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)
{
System.out.println("Grade: Excellent");
}

else if (avgMark >= 50 && avgMark <= 79) {
System.out.println(" Grade: Good ");
}

else if (avgMark <= 50) {
System.out.println(" Grade: Low ");
}


}
}
OriginalGriff 3-Nov-20 8:57am
   
So you've totally ignored everything we have told you so far?

No point in trying to help you further then, is there?
tomatomoa 3-Nov-20 9:01am
   
It's not like I ignored, but I just don't know how even after numerous explanations,, I just can't understand it. sorry if I sound dumb , yet tq
OriginalGriff 3-Nov-20 9:21am
   
If you haven't ignored what we said, where is the evidence of that in your code? Because the latest code fragment you show is almost identical to the original - it shows no input from us, and - to be honest - no real sign of thought in what has changed ... so where is the point in us spending our valuable time typing when you ignore what we tell you?
tomatomoa 3-Nov-20 9:26am
   
again, im truly sorry
OriginalGriff 3-Nov-20 9:38am
   
"Sorry don't cut bait."

So start by reading what we said, and using it. Show us you are paying attention and trying to do your homework yourself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900