Write a program that finds the course grades for several classes and write it in Java. Program
Question:
Write a program that finds the course grades for several classes and write it in Java.
Program Description
Your assignment is to write a class averaging program that outputs a summary of classes and students, given input data in a specific format (more on that in a bit). For a high-level view, look at the sample program execution below. Your program will read from an input file (courseData.txt) a number of data items, stored in the file in the following order:
(1) Global data is on the first line, as this applies to all classes. This first line holds the weights to use for all classes, in this order: program weight, midterm weight, and final exam weight.
(2) Every other line in the file is specific to a class, and so the next line starts with a course identifier (161, 162, or 263, and this is an int).
(3) After the course identifier ,a set of lines belonging to that course are listed, each with a student ID (four digits, such as 1234), an unweighted program score, an unweighted midterm score, and an unweighted final score.
(4) Reaching a 0 indicates the end of input for a specific class ,or the end of file if all class data has been consumed.
Given this data file, your program should:
(1) Be well-documented with comments! I’ve included a number of comments in the sample code below as examples. This is the first assignment where you’ll be graded on both correctness and code quality, with respect comments. (Read the grading rubric for a list of everything you’ll be graded on!)
(2) Read in weights, IDs, course numbers ,programs scores, midterm scores, and final scores per student from the sample input file provided (using Scanner or File Reader).
(3) Calculate statistics per student and per class and report the following:
a. Output a weighted average per student.
b.Output a Pass/Fail mark per student.
c. Output an average per class.
(4) Youroutputshouldbecomparedagainstthesampleoutputbelowforaccuracy.
(5) There should be at least one method that you write that can be used to provide output for tracing variables:
a.The method should be called test-something, e.g., test Statistics.
b.Somewhere in your program, there should be a call to that method. In the code you
submit, that call should be commented out, but I should be able to find it.
Sample Input
For example, the following data comes from the sample file you’ll use as input to test your software:
0.30 0.30 0.40
161
3333 70 60 50
4444 50 50 50
5555 80 90 80
0
162
1212 90 85 92
6666 60 80 90
...
...
...
0
Sample Output
This section outlines what your software is to calculate and ultimately report on the console. (If this assignment is too easy, for an added challenge, have the report be written in a GUI using JOptionPane.)
Grade Data For Class 161
ID Programs Midterm Final Weighted Average Programs grade
-- ------- ------- --- ---------------------- --------------
3333 70 60 50 59.00 Pass
4444 50 50 50 50.00 Fail
5555 80 90 80 83.00 Pass
Class Average: 64.00
Grade Data For Class 162
ID Programs Midterm Final Weighted Average Programs grade
-- ------- ------- --- ---------------------- --------------
1212 90 85 92 ... Pass
6666 60 80 90 ... Fail
7777 90 90 90 ... Pass
8888 95 87 93 ... Pass
9999 75 77 73 ... Pass
Class Average: ......
Grade Data For Class 263
ID Programs Midterm Final Weighted Average Programs grade
-- ------- ------- ----- ---------------------- --------------
2222 ...
8989 ...
9090 ...
Class Average: ...
Final Thoughts
Here is a skeleton code you could use as a starting point for your project:
import java.util.Scanner; import java.io.File;
import java.io.IOException;
// Authors: Fukuda, Zander (edited by Nash, minor edits by Lin)
public class Foo {
//... class constants go here ...
public static void main(String[] args) {
int courseNumber; // Number of the course
Scanner inputFile = null; // File containing data (p. 297
// in Savitch discusses null)
// ... code assigning inputFile
// ... code for any stuff you need to do one time ...
//Per class, print a table of ID numbers, grades, weighted average
// per student, and a Pass or Fail programs grade. The class
// average is also printed. for (...)
{
// Read class number, print class number title, headings. courseNumber = inputFile.nextInt();
... rest of the code goes here ...
// initialization
... code goes here ...
// Loop to handle one class:
// For each student in the class, get and print their
// information, compute their avg, and sum the avgs. while (...)
{
... code goes here ... }
// compute and print class average
... code goes here ... }
in a try/catch statement
}
However, feel free to use something different. There are any number of solutions, some using different kinds of nested loops, some using only one loop, and others making greater use of methods. This skeleton is merely one possible acceptable structure for this assignment.
The columns “Programs”, “Midterm”, and “Final” in the output above (i.e., from the file) are raw scores (not weighted). The only calculation that involves manipulation of weights and grades is the weighted average. The Weighted Average is calculated using the following sum of products:
(programsWeight*programsGrade) + (midtermWeight*midtermGrade) + ( finalWeight*finalGrade)
The Pass/Fail determination is made based only on the raw score of the students programs. If the student’s programs score is greater than or equal to 70, they pass. If less than 70, they fail.
Also, if your program has multiple loops (one per course, one per student, etc.), which you should ignore when initially tackling this problem. When solving this problem, it may be best to focus first on the innermost loop that deals with students. Deferring higher-level details in favor of fleshing out individual cases first can be thought of as an inside-out approach (commonly called Bottom-Up Design, related to Stepwise Refinement). This is similar to ignoring a forest and paying attention to just one tree. For example, you could start by focusing on just one class first and building the loop to process each student until a 0 is reached. Once this is working for one class, you can wrap this logic inside of a loop and extend its functionality to process multiple classes.
Finally, the real data may differ from the sample data with respect to actual scores used (and the number of students in a class and/or the number of classes), but will not vary with respect to file format. This simply means that your program should work with multiple files formatted in the same fashion, and not just with the values in the sample file.
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang