need help with java project
hi. this is an assignment for java.
what im required to do is write a program to tabulate marks for trainees
what is required is more or less already done.
im only stuck with this part where it requires more than 1 trainee to enter the marks, then say if 2 trainees entered their marks, it should print out after they told the program to print.
heres what i've done so far:
Code:
// section 1 - code below imports packages from both utilities package and math package
import java.util.*;
import java.math.*;
class MarksTabulation
{ public static void main ( String [] args)
{ Scanner in = new Scanner(System.in);
//section 2 - variable declarations
char enterAnother = 'Y';
int [] traineeNo = new int [20];
// note for self - allow 20 trainees
int keyedNumberOfQuiz = 0;
double [] noOfQuiz;
double [] modTestMark = new double [20];
double [] averageMark = new double [20];
double [] overallMark = new double [20];
String [] familyName = new String [20];
String [] firstName = new String [20];
String [] moduleName = new String [20];
repeat:
for (int noOfTrainees = 0; noOfTrainees < 20; noOfTrainees ++)
{ //section 3 - prints prompts for user to key in input
System.out.print("Trainee Number: ");
traineeNo [noOfTrainees] = in.nextInt();
//traineeNo limiter
while (traineeNo [noOfTrainees] < 1000 || traineeNo [noOfTrainees] > 9999)
{ System.out.print("Invalid Trainee Number. Please key in a valid Trainee number: ");
traineeNo [noOfTrainees] = in.nextInt();
}
//continuation of section 3
System.out.print("Family Name: ");
familyName [noOfTrainees] = in.next();
System.out.print("First Name: ");
firstName [noOfTrainees] = in.next();
System.out.print("Instruction Module: \n 1. Forward Scanning Radar Display Repair\n 2. IR Beacon Maintenance\n 3. SAM Detection System Replacement\nEnter Module No.: ");
int module = in.nextInt();
while (module > 3 || module < 1)
{ System.out.print("Invalid module number. Please key in a valid module number: ");
module = in.nextInt();
}
switch (module)
{ case 1: moduleName [noOfTrainees] = "Forward Scanning Radar Display Repair"; break;
case 2: moduleName [noOfTrainees] = "IR Beacon Maintenance"; break;
case 3: moduleName [noOfTrainees] = "SAM Detection System Replacement"; break;
}
System.out.print("How many quizes shall I calculate?: ");
keyedNumberOfQuiz = in.nextInt();
//"number of quizzes" limiter
while (keyedNumberOfQuiz < 1 || keyedNumberOfQuiz > 8)
{ System.out.print("Invalid number of quizes. Please key in a valid number: ");
keyedNumberOfQuiz = in.nextInt();
}
//section 4 - create an array
noOfQuiz = new double [keyedNumberOfQuiz];
averageMark [noOfTrainees] = tabulateModuleMarks(noOfQuiz);
System.out.print("Final Module Test mark: ");
modTestMark [noOfTrainees] = in.nextDouble();
while (modTestMark [noOfTrainees] < 0 || modTestMark [noOfTrainees] > 100)
{ System.out.print("Invalid Final Module score. Please key in a valid score: ");
modTestMark [noOfTrainees] = in.nextDouble();
}
overallMark [noOfTrainees] = getOverallMark(averageMark [noOfTrainees],modTestMark [noOfTrainees]);
System.out.println("\n");
averageMark [noOfTrainees] = roundingOff1Decimal(averageMark [noOfTrainees]);
overallMark [noOfTrainees] = roundingOff1Decimal(overallMark [noOfTrainees]);
System.out.print("Another [Y/N]: ");
enterAnother = in.next().charAt(0);
if (enterAnother == 'N')
{ break repeat;
}
}
//section 5 - print results
for (int noOfTrainees = 0; noOfTrainees < 20; noOfTrainees ++)
{ printResults(traineeNo [noOfTrainees] ,firstName [noOfTrainees],familyName [noOfTrainees],moduleName [noOfTrainees],averageMark [noOfTrainees],modTestMark [noOfTrainees],overallMark [noOfTrainees]);
}
}
//section 6 - my own methods and their purposes
static void printResults (int traineeNo, String familyName, String firstName, String moduleName, double averageMark, double modTestMark, double overallMark)
{ System.out.println("Results for " + familyName + " " + firstName);
System.out.println("Trainee Number" + " " + traineeNo);
System.out.println("Module: " + moduleName);
System.out.print("Average Module Quiz: " + averageMark + " ");
System.out.print("Final Module Test: " + modTestMark + " ");
System.out.println("Overall mark: " + overallMark + " ");
if ( overallMark >= 70 )
{ System.out.println("Letter Grade: A");
}
else if (overallMark >= 60 && overallMark < 70)
{ System.out.println("Letter Grade: B");
}
else if (overallMark >= 50 && overallMark < 60)
{ System.out.println("Letter Grade: C");
}
else if (overallMark >= 40 && overallMark < 50)
{ System.out.println("Letter Grade: D");
}
else if (overallMark >= 35 && overallMark < 40)
{ System.out.println("Letter Grade: E");
}
}
static double tabulateModuleMarks (double [] noOfQuiz)
{ Scanner in = new Scanner(System.in);
double sum = 0;
for (int x = 0; x < noOfQuiz.length; x++)
{ System.out.print("Module "+(x+1)+" Quiz Mark: ");
noOfQuiz [x] = in.nextDouble();
while (noOfQuiz [x] < 0 || noOfQuiz [x] > 100)
{ System.out.print("Invalid module " + (x+1) + " score. Please key in a valid score(1-100): ");
noOfQuiz [x] = in.nextDouble();
}
sum = sum + noOfQuiz [x];
}
return sum/(noOfQuiz.length);
}
static double getOverallMark (double averageMark, double modTestMark)
{ double modQuizWeighting;
double modTestWeighting;
double overallMark;
modQuizWeighting = averageMark/100 *20;
modTestWeighting = modTestMark/100 *80;
return (modQuizWeighting + modTestWeighting);
}
static double roundingOff1Decimal (double decimal)
{ decimal = decimal * 10;
return Math.rint(decimal) / 10;
}
}
what is troubling me is when i try to print out the results, it shows null for string fields like names, and 0 for integer or double fields.
hope im posting it right. if not pls let me know how. and thanks for any kind help provided.