Programming Assignment 01
Deadline: September 11, 2024 – Wednesday, 11:30pm
PA1-Gradenator
The goals for PA1 are to get started with Java and figure out how to calculate your current CSC 210 grade.
Your file name (and class) should be Gradenator.java
.
Input File
When your program starts it should prompt the user for an input file.
Each line of the input file should be in the following format:
<number> <number> ...; <string with no semicolons>; <number>%
Prompt the user by printing "File name?"
with a line break.
Specifically one or more numbers in the inclusive range 0 to 100 [0,100] separated by one or more spaces, a semicolon, a string with any characters except a semicolon, a semicolon, and a number in the inclusive range 0 to 100 [0,100] followed by a percent sign. The Java Scanner
class with its nextLine()
method can handle whatever line ending your file system uses.
Example input:
80; final; 20%
90 60 80; programming assignments; 25%
An overall grade will be calculated by averaging the grades listed at the beginning of each line (e.g. avg(90 60 80) ==> 76.67) and then computing a total grade based on the percentages indicated on each line (e.g. (0.20)80 + (0.25)76.67 ==> 35.17, where (0.20)80 is another way to write 0.20 times 80).
Note that if the input percentages do not add up 100%, then the total grade will not be out of 100%. In the example above the best possible grade would be 20% + 25% ==> 45%.
The output will be the average grade per line and a total line. Example output:
final; 20.0%; avg=80.0
programming assignments; 25.0%; avg=76.6
TOTAL = 35.1% out of 45.0%
Numbers representing discreet values should be stored as int
. Numbers representing continuous values should be stored as double
.
Values of type double
are printed with many digits after the decimal place by default but this does not look very good and causes grading problems due to round-off differences. Therefore, to print a smaller number of digits we will be using System.out.format
.
Example:
System.out.format("%.1f is pi", 3.141);
The above line will output the following:
3.1 is pi
You should use the exact syntax above to round all output to one digit after the decimal. If you want to print a percent sign in a System.out.format
statement you will need to escape it. You can escape it by writing two percentage signs in a row %%
.
Error checking: Your PA1 program can assume that all grading input follows the format described. Any input that does not follow the input format can result in undefined behavior.
Submitting your solution
Make sure your file has the correct package info at the top:
package com.gradescope.gradenator;
Submit your Gradenator.java
file to Gradescope
Testing your program
If your program cannot compile and run, then you should feel very uncomfortable. Experienced programmers write a little bit of new functionality and then quickly compile and run it. When you ask CSC 210 staff questions about your program, we will want to see that it compiles and runs. Comment out new stuff you have added until it compiles and runs. Show us what compiles and runs, and then add the one small piece that breaks it.
The CSC 210 staff can look at your code remotely on gradescope to help you with questions.
More than one revision
The first time we write a piece of a program, it is really a draft. We want to get the syntax right and figure out the functionality. After that, we need to fix our initial comments so they clarify what the code is doing. Help your future self and others who will be reading your code. Plan on rewriting pieces of your program multiple times to produce a professional and clear program.
Decomposition Ideas
Here are some Java classes and methods that might be helpful when working on this assignment. We recommend you lookup online examples of how to use these and what their parameters and return values are):
System.out.println()
System.out.print()
new File("inputFile1.txt")
new Scanner(System.in)
hasNextLine()
nextLine()
close()
String
substring()
indexOf()
trim()
split()
- Iterating over an array of strings, https://www.guru99.com/foreach-loop-java.html
Decomposition
Should just use
static
methods in the singleGradenator
class.Use a single file. This should be a small program (<200 lines).
Each
static
method should be less than 30 lines.Make things as simple as possible.
- Avoid nested loops.
- Avoid nesting conditionals.
- Avoid too many levels of user-defined methods calling other user-defined methods.
Code Clarity
YOU should be able to read, understand, and explain your own code a couple days after you wrote it.
The file header should include instructions on how someone would use this program.
Use meaningful variable names. Loop iterators can be simple (
i
for integers,s
for strings,n
for numbers, etc.). Otherwise you should avoid single letter variable names.
Write your own code. We will be using a tool that finds overly similar code. Do not look at other students’ code. Do not let other students look at your code or talk in detail about how to solve this programming project. Read the academy integrity page for more details on how we deal with violations in this course.