Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Scoring Solution not correct

Posted on 2005-04-16
3
Medium Priority
?
210 Views
Last Modified: 2012-05-05
I need limaideal to review his solution.  The scores are not working out as US scores

100 - 90 = A
 89 - 80 = B
 79 - 70 = C
 69 - 60 = D
< 59    = F


Program:

import javax.swing.*;

public class StudentGrades
{
    public static void main(String args[])
    {
        //  Final Length of Array
        final int STUDARRAY_LENGTH = 6;
        final int STUDSCOREARRAY_LENGTH = 6;
        final char CHARSCORES[] =
            {
            'F', 'D', 'C', 'B', 'A', 'A'};
        //     array type
        String studentName[] = new String[STUDARRAY_LENGTH];
        int studentScores[] = new int[STUDSCOREARRAY_LENGTH];
        int total = 0;
        //  Produce 6 prompts for user to input 6 Student Names
        for (int count = 0; count < studentName.length; count++)
        {
            studentName[count] = JOptionPane.showInputDialog("Please enter the student's name: "
                + (count + 1));
        }
        for (int j = 0; j < studentScores.length; j++)
        {
            while (true)
            {
                try
                {
                    int score = Integer.parseInt(JOptionPane.showInputDialog(
                        "Please enter the student's Score :" + (j + 1)));
                    System.out.println("score:" + score);
                    if (score < 0 || score > 100)
                    {
                        continue;
                    }
                    total += score;

                    studentScores[j] = score;
                    break;

                }
                catch (NumberFormatException ex)
                {
                    continue;
                }
            }
        }

        System.out.println("The student's names and grades are: ");

        //column headings
        System.out.println("Name\tScore\tGrade");

        for (int count = 0; count < studentName.length; count++)
        {
            System.out.println("\n " + studentName[count] + " \t " + studentScores[count]
                               + "\t" + CHARSCORES[studentScores[count] / 20]);
        }

        System.out.println("Average score:" + total / 6);
    } //     end main( )

} //     end studentGrades

0
Comment
Question by:NikkitaKMiles
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13799610
String grade = null;
if (score>=90)
{
   grade = "A";
{
else if (score>=80)
{
   grade = "B";
}
etc.
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 13799616
if you wanted to stick with the approach in your code then change your scores array to:

       final char CHARSCORES[] = { 'D', 'C', 'B', 'A', 'A'};


and use the following in your loop:

        for (int count = 0; count < studentName.length; count++)
        {
            char grade = 'F';
            if (studentScores[count]>59)
            {
               grade = CHARSCORES[(studentScores[count]-60) / 10];
            }
            System.out.println("\n " + studentName[count] + " \t " + studentScores[count]
                               + "\t" + grade);
        }
0
 

Author Comment

by:NikkitaKMiles
ID: 13799630
Yes.  That fixed it.  Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question