Write a Java program which calculates final grades.

Your program must read lines (from standard input) which give the names, marks and number of cheating instances for people in a course. Your program must then compute the grade following the rules outlined (see below). Then output the person’s name, their numeric grade, and the corresponding letter grade.

More specifically, the fields in the input are separated by the “|” character. The second field is the final exam mark, the third field is the midterm mark, the fourth field is the number of bonus points and the fifth field is the number of times the person was caught cheating. To reduce tedium, we will pretend that there are only seven assignments that count. The exam and midterm mark are percentages. The assignments are out of 60, except for the first one, which is marked out of 20. (Note that a person may obtain bonus points on a given assignment, taking their mark above 100% (i.e., above 20 or above 60) for that particular assignment.)

For example, if your program reads the following input
Igotte Busted|100|97.5|3|2|17|58|60|63|-60|-60|42
John Q. Woodcutter|75|82|2|0|15|57|55|56|10|25|48

then your program should create the following output:
Igotte Busted                F    0
John Q. Woodcutter      A- 80

Use floating point numbers to do the calculations of the numeric grade, and then round that result to the nearest integer (round a number with a fractional part of 0.5 up to the next integer).
The output must have the name starting at the left margin. If the name has less than 30 characters, the letter grade starts in column 31. If the name has more than 29 characters, the entire name is printed, followed by one space, and the letter grade and numeric grade must follow. In either case, the letter grade is left-justified in a two-column field, this field is followed by one space, and that space is followed by the numeric grade right-justified in a three-column field.

Your program must perform the calculations and output the results for all input lines until either (a) EOF, or (b) it finds a line which does not match the given input format. In the latter case, your program must output an informative error message and stop.
Invent your own input data to thoroughly test your program. Make sure you include enough tests in your script file to convince the marker that your program works. Also, if you aren’t sure what the complicated part of the formula means, then put in enough test cases (which use that part of the formula) so that you can figure out what is going on.

You may need to install Java on your Linux system, if you have not done so already. If you wish, you may also install a Java IDE. However, for the run where you create the script file to be handed in, you must compile your program with the command line javac and execute your program with the command line java marks (of course, this assumes that you named your Java program

If you wish to store your data in a file (say, testmarks.dat) so that you do not have to re-type it every time you run your program, you can “send” this data to your Java program by typing the command line “java marks < testmarks.dat”.

Final grades are based on the following scheme. Let E be your exam grade, M be 
your midterm grade, A be your assignment grade, B be your class participation bonus grade, and F be your final grade, all except B expressed as percentages. Finally, Jb is normally 0 but can be 3 for any student who can provide convincing proof that he or she was primarily or completely responsible for having a Microsoft employee laughed off the stage at any national or international conference. F is computed as follows:
F=0.5*E + 0.1*M + 0.1*A + B + Jb
if E < 40
F += 0.3 * E                  
if E > 50
F+=0.2*max(E,M) + 0.1*max(E,A)
F+=0.02*((E-40)*max(E,M) + (50-E)*E) +0.01*((E-40)*max(E,A) + (50-E)*E)   
if M < 40
F = min(F, M)
if A < 50
F = min(F, A)
Finally, this grade is adjusted as described below for anyone caught cheating.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.text.DecimalFormat;
import java.util.Scanner;

public class mark {

    private static boolean calculation(String line){
       String [] split = line.split("\\|");
       if (split.length != 12) {
            return false;
       String name = split[0];      
       double finalMark;
       double middleTermMark;
       double bonusPointNum;
       double cheatingNum;
       double [] mark = new double[11];      
       try {
            for (int i = 0; i < 4; i++) {
                mark[i] = Double.parseDouble(split[i + 1]);
            mark[4] = Double.parseDouble(split[5]);
            mark[4] = mark[4] <= 20.0 ? mark[4] : 20.0 ;
            mark[4] = mark[4] / 20.0;...
$28.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats