Click here to Skip to main content
15,500,453 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 21: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 ");
     }
 
Share this answer
 
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.
 
Share this answer
 
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     CRLF
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     CRLF
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     CRLF
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     CRLF
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 "); } } }

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