Results 1 to 3 of 3

Thread: help on grade calculator tool(GPA)

  1. #1
    Join Date
    Apr 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help on grade calculator tool(GPA)

    Hey! Help me
    I'm totally stuck on this project, in which a user is supposed to enter number of students in a class, and number of exams taken. Then they enter each student's name, and then the exam scores for that student on a single line separated by blank spaces.
    Here website I want clone tool: https://gpahub.net/
    Any advice would be really appreciated, thanks a lot.

    Code:
    public class proj2 {
    
     public static void main(String[] args) {
     Scanner s = new Scanner(System.in);
    
      System.out.println("Welcome to Gradecalculator!");
    
      System.out.println("Please enter the number of students:");
      int students = s.nextInt();
    
      System.out.println("Please enter the number of exams:");
      int exams = s.nextInt();
    
      int i = 0;
      int studentnumber = 1;
    
      int sum = 0;  
      while (i < students) {
    
        double average = sum/exams;
    
        System.out.println("Enter student " + studentnumber++ + "'s name :");
        String studentname = s.next();
    
        System.out.println("Enter exam scores :");
    
        for (; i < exams; i++) {    
         int n = s.nextInt();
         sum+=n;
    
         if (n < 0) {
         System.out.println("Invalid exam scores, reenter: ");      
         }
      }
      if (average <= 100 && average >= 90) {
           System.out.println("Letter grade: A");
           System.out.println(studentname + " gets 4 stars! ****");
          } if (average <= 89 && average >= 80) {
           System.out.println("Letter grade: B");
           System.out.println(studentname + " gets 3 stars! ***");
          } if (average <= 79 && average >= 70) {
           System.out.println("Letter grade: C");
           System.out.println(studentname + " gets 2 stars! **");
          } if (average <= 69 && average >= 60) {
           System.out.println("Letter grade: D");
           System.out.println(studentname + " gets 1 star! *");
          } if (average <= 59) {
           System.out.println("Letter grade: F");
           System.out.println(studentname + " gets 0 stars!");
          }
    }
     }
     }
    Last edited by jscheuer1; 04-13-2017 at 06:20 PM.

  2. #2
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    A few things I noticed, sleep so I can be wrong, and I haven't played with java in awhile
    Also, not sure if we are suppose to help with homework... but still

    Your if statements are weird (unless they are just copied wrong).
    Shouldn't student number start at 0 and not 1. Shouldn't you be comparing student number to students. studentnumber < student.
    Variable i should just be located inside the for loop.
    The n < 0 needs to before you add it to the sum (you dont want to add a negative number to the sum) and you will need to do i--;

    That is a quick glance. (Ignore spelling and grammar mistakes on my part)
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  3. #3
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    Java, JavaScript, PHP or C++, the language is irrelevant as the methods are all the same. You need to think seriously about the implications of using the same variable in these two lines in your code:

    Code:
    while (i < students) {
    .
    .
     for (; i < exams; i++) {

Similar Threads

  1. Screen capture tool / cropper tool
    By theremotedr in forum Looking for such a script or service
    Replies: 3
    Last Post: 09-23-2016, 09:01 AM
  2. Age calculator using php
    By riancast in forum PHP
    Replies: 2
    Last Post: 03-09-2013, 09:30 AM
  3. Grade My Site
    By Johnnymushio in forum The lounge
    Replies: 18
    Last Post: 05-03-2011, 01:19 AM
  4. JS Calculator
    By iF15 in forum JavaScript
    Replies: 1
    Last Post: 11-29-2007, 05:27 AM
  5. java beginner, help on grade calculator
    By bokononist in forum Java
    Replies: 0
    Last Post: 04-09-2007, 02:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •