Help modifying program.. - - An Overclocking Community
Forum Jump: 

Help modifying program..

Thread Tools
post #1 of 2 (permalink) Old 12-13-2009, 11:54 AM - Thread Starter
Join Date: Mar 2009
Location: Meticadpa's Bad List :P
Posts: 3,583
Hey guys, I need help modifying this Java program. I need to modify it to allow the user to enter the number of tests and amount of students. Must be restricted to 1 and 20 inclusive for the amount of students, and for the amount of Tests, 3 and 7 inclusive.

This is my code:

import java.util.*;
public class Grades {

public static void main(String[] args) {
Scanner Input = new Scanner(;
double average, grade = 0;
String Continue;
int total = 0, count = 0;
String[] Names = new String[20];
double[][] Grades = new double[20][3];
double[] Average = new double[20];
char[] Letter = new char[20];

for(int x = 0; x < Names.length; x++){{

System.out.print("Enter the Students Name: ");
Names[x] = Input.nextLine();
for(int y = 0; y < 3; y++){
System.out.print("Enter the Grade Value for Test" + (y + 1) + ": ");
Grades[x][y] = Input.nextDouble();

total += Grades[x][y];

Average[x] = (total/3);

if (Average[x] >= 89.5)
Letter[x] = 'A';
else if (Average[x] >= 79.5)
Letter[x] = 'B';
else if (Average[x] >= 69.5)
Letter[x] = 'C';
else if (Average[x] >= 59.5)
Letter[x] = 'D';
Letter[x] = 'F';

count = 0;
total = 0;

System.out.print("Would you like to continue? (Y/N)");
Continue = Input.nextLine();
if((Continue.charAt(0) == 'N')||( Continue.charAt(0) == 'n'))
System.out.println(" Name Test 1 Test 2 Test 3 Average Letter");
for(int x = 0; x < Names.length; x++){{
if(Names[x] != null){
System.out.print(Names[x] + " ");

for(int y = 0; y < 3; y++)
System.out.print(Average[x] + " ");


Help will be rewarded with rep.
[Teh Root] is offline  
Sponsored Links
post #2 of 2 (permalink) Old 12-13-2009, 06:34 PM
New to
usmcz's Avatar
Join Date: Mar 2009
Location: Colorado
Posts: 885
Rep: 54 (Unique: 47)
I'm not sure if I completely understand (and I'm rusty with java) but here goes...

String[] Names = new String[20];

Here is where you are setting the number of students or "names" at 20. (0-19 actually, i think).

You could do:

System.out.println("Enter the total number of students: ");
int numStudents = Input.nextInt();

before you create the array Names, and then change the creation of the array to:

String[] Names = new String[numStudents];

Just make sure you initialize your scanner before you call it, and that you set the variable before.

Average[x] = (total/3);

replace the 3 with a variable that you earlier set with the amount of tests:

System.out.println("Enter the total number of tests: ");
int numTest = Input.nextInt();

then Average[x] = (total/numtest);

I think that is right -- but I may have completely missed the point.. if so just let me know and I can try to help again

usmcz is offline  

Quick Reply

Register Now

In order to be able to post messages on the - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Please enter a password for your user account. Note that passwords are case-sensitive.
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off