/*
* Class to store grade book
*/
import java.io.FileWriter;
import java.util.Random;
import java.util.Scanner;
public class GradeBook {
// variables
int gradeBook[][];
int scores = 12;
Scanner in = new Scanner(System.in);
// main method
public static void main(String[] args) {
GradeBook g = new
GradeBook();
g.getGrades();
g.executeMenu();
}
// method to get grades
private void getGrades() {
System.out.print("How
many students in the class? ");
int n = getInt();
gradeBook = new
int[n][scores + 1];
// object to create
random number
Random rand = new
Random();
for (int i = 0; i <
n; i++) {
System.out.print("Enter studnet number: ");
int num = getInt();
gradeBook[i][0] = num;
for (int j = 1; j < 4; j++) {
// create random number between 55 and 95
num = rand.nextInt((95 - 55) + 1) + 55;
gradeBook[i][j] = num;
}
for (int j = 4; j < 8; j++) {
// create random number between 60 and 90
num = rand.nextInt((90 - 60) + 1) + 60;
gradeBook[i][j] = num;
}
for (int j = 8; j < 13; j++) {
// create random number between 58 and 100
num = rand.nextInt((100 - 58) + 1) + 58;
gradeBook[i][j] = num;
}
}
}
// method to get integer input
private int getInt() {
try {
int n = Integer.parseInt(in.nextLine());
return n;
} catch
(NumberFormatException e) {
System.out.println("Invalid entry.. integer expected");
return getInt();
}
}
// method to execute main menu
private void executeMenu() {
// loop
while (true) {
System.out.println("1. Display highest score of all grades");
System.out.println("2. Display lowest score of all grades");
System.out.println("3. Display entire grade book");
System.out.println("4. Go to individual student menu");
System.out.println("5. Export grade book as txt file");
System.out.println("6. Quit");
System.out.print("Enter your option: ");
int option = getInt();
switch (option) {
case 1:
displayHighest();
break;
case 2:
displayLowest();
break;
case 3:
displayGrades();
break;
case 4:
gotoStudentMenu();
break;
case 5:
exportGrade();
break;
case 6:
break;
default:
System.out.println("Invalid entry");
break;
}
// exit loop condition
if (option == 6) {
break;
}
}
}
// method to dispaly highest
private void displayHighest() {
int highest =
gradeBook[0][1];
for (int i = 0; i <
gradeBook.length; i++) {
for (int j = 1; j < gradeBook[i].length; j++) {
if (highest < gradeBook[i][j]) {
highest = gradeBook[i][j];
}
}
}
System.out.println("Highest grade: " + highest);
}
// method to display lowest
private void displayLowest() {
int lowest =
gradeBook[0][1];
for (int i = 0; i <
gradeBook.length; i++) {
for (int j = 1; j < gradeBook[i].length; j++) {
if (lowest > gradeBook[i][j]) {
lowest = gradeBook[i][j];
}
}
}
System.out.println("Lowest grade: " + lowest);
}
// method to dispaly all grades and
average
private void displayGrades() {
System.out.println("ID#\tLab1\tLab2\tLab3\tLec1\tLec2\tLec3\tLec4\t"
+ "HW1\tHW2\tHW3\tHW4\tHW5\tAvg");
for (int i = 0; i <
gradeBook.length; i++) {
int total = 0;
System.out.print(gradeBook[i][0] + "\t");
for (int j = 1; j < gradeBook[i].length; j++) {
System.out.print(gradeBook[i][j] + "\t");
total += gradeBook[i][j];
}
System.out.println(total / scores);
}
}
// student menu
private void gotoStudentMenu() {
System.out.print("Enter
student ID: ");
int id = getInt();
int row = -1;
for (int i = 0; i <
gradeBook.length; i++) {
if (gradeBook[i][0] == id) {
row = i;
break;
}
}
// if no students with
given id, return from method
if (row == -1) {
System.out.println("Student not found..");
return;
}
// loop
while (true) {
System.out.println("7. Display all the lab grades and average lab
score");
System.out.println("8. Display all the lecture grades and average
lecture score");
System.out.println("9. Display all the assignment grades and
average assignment score");
System.out.println("10. Display the letter grade");
System.out.println("11. Back to main menu");
System.out.print("Enter your option: ");
int option = getInt();
switch (option) {
case 7:
displayLabGrades(row);
break;
case 8:
displayLecGrades(row);
break;
case 9:
displayAssignmentGrades(row);
break;
case 10:
displayLetterGrade(row);
break;
case 11:
break;
default:
System.out.println("Invalid entry");
break;
}
// exit loop condition
if (option == 11) {
break;
}
}
}
// method to display lab grades and
average
private void displayLabGrades(int row) {
System.out.println("ID#\tLab1\tLab2\tLab3\tAvg");
int total = 0;
System.out.print(gradeBook[row][0] + "\t");
for (int j = 1; j <
4; j++) {
System.out.print(gradeBook[row][j] + "\t");
total += gradeBook[row][j];
}
System.out.println(total
/ 3);
}
// method to display Lecture grades and
average
private void displayLecGrades(int row) {
System.out.println("ID#\tLec1\tLec2\tLec3\tLec4\tAvg");
int total = 0;
System.out.print(gradeBook[row][0] + "\t");
for (int j = 4; j <
8; j++) {
System.out.print(gradeBook[row][j] + "\t");
total += gradeBook[row][j];
}
System.out.println(total
/ 4);
}
// method to display assignemt grades and
average
private void displayAssignmentGrades(int row)
{
System.out.println("ID\tHW1\tHW2\tHW3\tHW4\tHW5\tAvg");
int total = 0;
System.out.print(gradeBook[row][0] + "\t");
for (int j = 8; j <
13; j++) {
System.out.print(gradeBook[row][j] + "\t");
total += gradeBook[row][j];
}
System.out.println(total
/ 5);
}
// method to display letter grade
private void displayLetterGrade(int row) {
int total = 0;
for (int j = 1; j <
13; j++) {
total += gradeBook[row][j];
}
int average = total /
scores;
char grade;
if (average > 79)
{
grade = 'A';
} else if (average >
69) {
grade = 'B';
} else if (average >
59) {
grade = 'C';
} else if (average >
49) {
grade = 'D';
} else {
grade = 'F';
}
System.out.println("Letter grade: " + grade);
}
// method to export all grades to txt
file
private void exportGrade() {
try {
FileWriter fw = new FileWriter("gradebook.txt");
fw.write("ID#\tLab1\tLab2\tLab3\tLec1\tLec2\tLec3\tLec4\t"
+ "HW1\tHW2\tHW3\tHW4\tHW5\tAvg\n");
for (int i = 0; i < gradeBook.length; i++) {
int total = 0;
fw.write(gradeBook[i][0] + "\t");
for (int j = 1; j < gradeBook[i].length; j++) {
fw.write(gradeBook[i][j] + "\t");
total += gradeBook[i][j];
}
fw.write(total / scores + "\n");
}
fw.close();
} catch (Exception e)
{
System.out.println(e);
}
System.out.println("Success...");
}
}
Output
using java Program: Please read the complete prompt before going into coding. Write a program that...
In Java Main method Your main program will prompt the user for a test name and the number of scores the user will enter. After creating an arraylist to hold the scores, prompt the user for all the scores to hold in the arraylist. After all the scores are entered, then repeat back the score & letter grade. GradeBook Object Create an instance of a GradeBook object and pass the test name and arraylist to set the instance variables. At...
In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...
Write a program that performs the following: 1. Presents the user a menu where they choose between: a. Add a new student to the class i. Prompts for first name, last name ii. If assignments already exist, ask user for new student’s scores to assignments b. Assign grades for a new assignment i. If students already exist, prompt user with student name, ask them for score ii. Students created after assignment will need to...
Must be done in C# please! Thanks! In this assignment you will create a program named Test Scores that displays the average of all tests; average midterm score; average final score; and displays the midterm or final score of a particular student. Create a class level two dimensional integer array named Grades initialized with the following data: 897 242 301 987 116 450 865 128 992 109 88 75 94 70 90 87 81 79 97 79 78 80 92...
Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X 5...
Using Java, write a program that teachers can use to enter and calculate grades of individual students by utilizing an array, Scanner object, casting, and the print method. First, let the user choose the size for the integer array by using a Scanner object. The integer array will hold individual assignment grades of a fictional student. Next, use a loop to populate the integer array with individual grades. Make sure each individual grade entered by the user fills just one...
In C++, write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string. The program should prompt for the number of records to be entered and then receive user input on how many records are to...
Java This application will be menu driven. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow the user to edit student ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique ID. The user should be able to view/edit an existing course...
[JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...
The application should be in JAVA and allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow the user to edit student ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique ID. The user should be able to view/edit an existing course information. User is...