Question
Summary Continue to develop your understanding of repetition control structures and file I/O by building a class averaging program (here class means a course, not
Summary
Continue to develop your understanding of repetition control structures and file I/O by building a class averaging program (here "class" means a course, not an element of the Java language). This software will read input data from a file describing specific classes and students, and will calculate weighted averages for each student (as well as a pass/fail mark).
Work Items
- Write the program described below. Submit the single Java file (i.e., ".java" text file) that contains your program:
- Please submit only a single Java file via Canvas. Do not email your instructor your work.
- Name your Java file HW_Loops_Files.java. You must name your file this way.
- Note that by requiring you name your Java file HW_Loops_Files.java, it means that the public class that is in that file has to be named HW_Loops_Files.
- There is a graded discussion where you will be doing peer-reviews of the code you wrote for this assignment. Thus, also post a copy of your Java source code only to the HW: Peer Evaluation of Code assignment.
Input Data File
Your program will read from an input file: courseData.txt.
courseData.txt as follows:
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 7777 90 90 90 8888 95 87 93 9999 75 77 73 0 263 2222 90 65 75 8989 60 40 60 9090 70 80 30 0
Note that when you click on the link to this file, Canvas will automatically put it into a window in the Canvas environment. You'll need to select the data and copy it to an open text file (such as open with NotePad or Word) and save it as plain text. Do not save it as Rich Text Format (rtf) or a Word format (.doc or .docx).
The above input file has a number of data items stored in the file in the following order:
- 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.
- 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).
- 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.
- Reaching a 0 indicates the end of input for a specific class, or the end of file if all class data has been consumed.
Note that the courseData.txt file terminates with a newline character after the final zero. This means that hasNextLine will test true even after that final zero is read.
Given this data file, your program should:
- 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!)
- Read in weights, IDs, course numbers, programs scores, midterm scores, and final scores per student from the sample input file provided (using Scanner or FileReader).
- Calculate statistics per student and per class and report the following:
- Output a weighted average per student.
- Output a Pass/Fail mark per student.
- Output an average per class.
- Your output should be compared against the sample output below for accuracy.
- There should be at least one method that you write that can be used to provide output for tracing variables:
- The method should be called test-something, e.g., testVariableValues.
- 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.
Description and Example of Program Execution
Your assignment is to write a class averaging program that outputs a summary of classes and students, given the above input data. For a high-level view, look at the sample program execution below. (The report goes to 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: ...
The ellipses refer to calculated values, not included in the above example but which your program should calculate.
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 students 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.
Example Code Skeleton
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 in a try/catch statement // ... 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 ... } }
Feel free to use something different. There are any number of solutions and this skeleton is merely one possible acceptable structure for this assignment. However, make sure whatever solution you use satisfies the possible grading criteria. (For instance, in the above skeleton method calls are left for you to fill in; this does not mean that your program should be one big main method with no other methods.)
Regarding the Grading Rubric
Most of the criteria listed on the rubric are self-explanatory. The Programming Style 13 criterion will be selected by the instructor from these criteria:
- Comments describe purpose and conditions for each method: These are done as Javadoc comments that are placed before each method header line. (Look up "Javadoc" in the textbook index if you're not sure what this is.)
- Comments document non-obvious code blocks.
- Each code file has a header block at the top of the file that describes the purpose and assumptions of the class or program.
- Appropriate blank lines are used between code blocks.
- Meaningful identifiers are used.
- Indentation is used appropriately to delineate code blocks.
Here is a final checklist of items to run through before you submit your work:
- You should be turning-in only one file.
- Compile and execute your code before turning in your .java file. If it doesn't work, something is wrong.
- Does your filename follow the correct convention?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started