We are using Eclipse, my computer died and I got another one set it up, internet
ID: 3622256 • Letter: W
Question
We are using Eclipse, my computer died and I got another one set it up, internet went down, assignment was due 29 Nov. 2010. This is the assignment:
In this SLP assignment, your task is to use what we have learned, write a java application program to help determining students' grades. Your program should have the following functions:
Ask number of students
the number of exams we have this semester
based on students' score, determine the kind of letter grade they should get
display result.
You will also need to write a pseudo code for this assignment.
SLP Assignment expectations
Use your knowledge in arrays, repetitive statement, selection statement, and other fundamentals in java, write a grade calculator program.
The following items will be assessed in particular:
does the program have any bugs
whether the program has used arrays
whether the program allows users to input student number and the number of exams
whether the program contains super and sub class
This the code I have so far:
import java.util.Scanner;
/**
*
* @This program demonstrates how to use two dimensional array to store data and display data
*
*/
public class CalculateGradeTwoDimensionalArray
{
//main method calls AssignvalueToArray method, and AssignValueToArray method calls
DisplayvalueInArray method
public static void main (String[] args)
{
//create a Scanner object for input
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int studentNum = keyboard.nextInt();
System.out.println();
System.out.print("Enter the number of homework: ");
int studentHomeworkNo = keyboard.nextInt();
AssignValueToArray(studentNum, studentHomeworkNo);
}
//This method assigns students' scores to a two dimentional array
public static void AssignValueToArray(int studentNumber, int numberOfHomeWork)
{
int[][] studentScore = new int[studentNumber][numberOfHomeWork];
Scanner keyboardForArray = new Scanner(System.in);
int studCount = 1;
for (int index = 0; index < studentNumber; index++)
{
System.out.println ("Please type in student " + studCount + " 's grade: " );
for(int indexOfHomeWork=0; indexOfHomeWork < numberOfHomeWork; indexOfHomeWork++)
{
studentScore[index][indexOfHomeWork] = keyboardForArray.nextInt();
}
studCount++;
}
DisplayvalueInArray(studentScore);
}
//this method displays student score in the two dimensional array
public static void DisplayvalueInArray(int[][] studentScoreArray)
{
System.out.println ("The students' scores are: " + " ");
int studentCount = 1;
for (int index = 0; index < studentScoreArray.length; index++)
{
System.out.print("Grades for student " + studentCount +": ");
for (int indexOfHomeWork = 0; indexOfHomeWork < studentScoreArray[index].length;
indexOfHomeWork++)
{
System.out.print(studentScoreArray[index][indexOfHomeWork]+" ");
}
System.out.println();
studentCount++;
}
}
}//end of class
This code works to input number of students and number of scores and displays Student 1 98 95 and next line Student 2 96 97 however I cant get it to display letter grades. Please help.
PS is there a way to get this code to display correctly? If that helps at all.
Explanation / Answer
import java.util.Scanner;
/**
*
* @This program demonstrates how to use two dimensional array to store data and display data
*
*/
public class CalculateGradeTwoDimensionalArray
{
//main method calls AssignvalueToArray method, and AssignValueToArray method calls DisplayvalueInArray method
public static void main (String[] args)
{
//create a Scanner object for input
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int studentNum = keyboard.nextInt();
System.out.println();
System.out.print("Enter the number of homework: ");
int studentHomeworkNo = keyboard.nextInt();
AssignValueToArray(studentNum, studentHomeworkNo);
}
//This method assigns students' scores to a two dimentional array
public static void AssignValueToArray(int studentNumber, int numberOfHomeWork)
{
int[][] studentScore = new int[studentNumber][numberOfHomeWork];
Scanner keyboardForArray = new Scanner(System.in);
int studCount = 1;
for (int index = 0; index < studentNumber; index++)
{
System.out.print("Please enter student " + studCount + " 's grades: " );
for(int indexOfHomeWork=0; indexOfHomeWork < numberOfHomeWork; indexOfHomeWork++)
{
studentScore[index][indexOfHomeWork] = keyboardForArray.nextInt();
}
studCount++;
}
DisplayvalueInArray(studentScore);
}
//this method displays student score in the two dimensional array
public static void DisplayvalueInArray(int[][] studentScoreArray)
{
System.out.println ("The students' grades are: " + " ");
int studentCount = 1;
for (int index = 0; index < studentScoreArray.length; index++)
{
System.out.print("Grade for student " + studentCount +": ");
System.out.print(getLetterGrade(getAverage(studentScoreArray[index]))+" ");
System.out.println();
studentCount++;
}
}
/**
* Computes the average value of the array
*/
public static double getAverage(int[] grades)
{
// avoid divide by 0
if(grades.length == 0)
{
return 0.0;
}
double output = 0.0;
// sum up grades
for(int i : grades)
{
output += i;
}
// divide by number of grades
output /= grades.length;
return output;
}
/**
* @return the letter grade corresponding to the score
*/
public static char getLetterGrade(double score)
{
if(score >= 90.0)
{
return 'A';
}
else if(score >= 80.0)
{
return 'B';
}
else if(score >= 70.0)
{
return 'C';
}
else if(score >= 60.0)
{
return 'D';
}
else
{
return 'F';
}
}
}//end of class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.