1 answer

Program for computing grades

Question:

Professor Nutty, who lectures encephalopathy (Med 7010), at the Cajun
Medical School gave three equally weighted exams to his students during the
course (preliminary, middle, and terminal exams). The students’ scores are
kept in a text file. Each row of the text file consists of the student’s ID#
followed by his/her test scores. At the end of the course, Professor Nutty
needs a C++ program that computes average test scores and letter grades
for each student. Professor Nutty wants a report consisting of each student’s
best two scores, the average of the best two scores, and the letter grade
corresponding to the average. In other words, Professor Nutty will drop the
lowest exam score. The exam scores are not sorted in the input file.
Your program will prompt the user for the name of the input file and
read the data from it. Your program will generate a report showing the
ID#, the best two scores, the average of the best two scores and letter grade
corresponding to the average. The report will be stored in an output text
file whose name the user will be prompted to enter.

Your program should prompt the user for the name of the input and out-put files. Be sure to perform error-check on both files to determine whetherthe input file issuccessfully opened and whether the output file is successfullycreated. Your program should then generate a report following the formatbelow. Ensure that numericvalues in the report are formatted so that theyhave the same number of decimal places as shown in the sample output be-low. Once the data from the input file havebeen processed, close the file.Also, close the output file before the program terminates.

For a sample input file, ence7010f11.grd, with the data below:

2008-EN-00195 80 100

2009-NE-09560 98 97.5

2011-PA-158 80 70 50

A typical program interaction would be:

Enter the name of the data file> ence7010f11.grd

Enter the name of the output file> ence7010f11.rpt

Here is the contents of the sample output file (ence7010f11.rpt):

Encephalopathy (Med-7010)

Final Course Report

Fall 2011

================================================

ID# Score Average Grade

2008-EN-001 95.00% 97.500% A

2009-NE-095 97.50% 97.750% A

2011-PA-158 70.00% 75.000% C

------------------------------------------------

*** END OF REPORT ***

================================================

I will rate lifesaver for any help that can be given! Thank you for looking!


Answers

Package filegrades;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class FileGrades
{
public static void main(String[] args) throws IOException
{
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(inp);
System.out.println("Enter the name of the data file> ");
String strInputFile = "c:\" +input.readLine();
System.out.println("Enter the name of the output file> ");
String strOutputFile = "c:\" + input.readLine();

StringBuilder sbOutput =new StringBuilder();
sbOutput.append(" Encephalopathy (Med-7010)").append(System.getProperty("line.separator"))
.append(" Final Course Report").append(System.getProperty("line.separator"))
.append(" Fall 2011").append(System.getProperty("line.separator"))
.append("================================================ ").append(System.getProperty("line.separator"))
.append("ID# Score Average Grade")
.append(System.getProperty("line.separator"));
BufferedWriter outputData = null;
BufferedReader inputData=null;
try
{
inputData = new BufferedReader(new FileReader(strInputFile));
if(inputData != null)
{
String line = null;
while (( line = inputData.readLine()) != null)
{
String[] str = line.split(" ");
String stuName = "";
double[] scores;
if(str!=null &&str.length > 1)
{
scores = new double[str.length-1];
stuName = str[0];
for(int i=1;i<str.length;i++)
{
scores[i-1] = Double.parseDouble(str[i]);
}
Arrays.sort(scores);
double AvgScore = (scores[scores.length-1]+scores[scores.length-2])/2;
String Grade="";
if(AvgScore >= 90)
{
Grade = "A";
}
else if(AvgScore >= 80 &&AvgScore < 90)
{
Grade = "B";
}
else if(AvgScore >= 70 &&AvgScore < 80)
{
Grade = "C";
}
else
{
Grade = "D";
}

sbOutput.append(stuName).append(" ")
.append(String.format("%3.2f%s", scores[scores.length-1],"%")).append(" ")
.append(String.format("%3.2f%s", scores[scores.length-2],"%")).append(" ")
.append(String.format("%3.3f%s", AvgScore,"%")).append(" ")
.append(Grade).append(System.getProperty("line.separator"));
}
}
}
else
{
System.out.println("Unable to open input file : " + input);
System.exit(0);
}
}
catch(Exception exp)
{
System.out.println("Unable to read/process input file : " + input);
System.exit(0);
}
finally
{
sbOutput.append(" -------------------------------- ").append(System.getProperty("line.separator"))
.append(" *** END OF REPORT ***").append(System.getProperty("line.separator"))
.append("================================================ ");
if(inputData != null)
{
inputData.close();
}
}
try
{
outputData= new BufferedWriter(new FileWriter(strOutputFile));
outputData.write( sbOutput.toString() );
}
catch(Exception exp)
{
System.out.println("Unable to open output file : " + input);
System.exit(0);
}
finally
{
if(outputData != null)
{
outputData.close();
}
}
}
}

Note: I got confused with output format. Whether we need to display one of the best 2 scores or both scores we have to display. In this program i havedisplayed both. One more thing conditions for Grades. i have assumed that A grade(>=90%), B grade(>=80% and < 90%), C grade(>= 70% and <80%), else D grade..

Similar Solved Questions

1 answer
A regional grocery chain is deciding whether to store packaged goods at each of its 16...
A regional grocery chain is deciding whether to store packaged goods at each of its 16 stores or at a centralized warehouse. Weekly demand at each store is N(400, 100). The safety stock is set to twice the standard deviation of average weekly demand to ensure about a 98% fill rate. How much inventor...
1 answer
PRELAB QUESTIONS 1. Read the Background and Words You Should Know section carefully, and then, on...
PRELAB QUESTIONS 1. Read the Background and Words You Should Know section carefully, and then, on a separate sheet or sheets of paper, define, in your own words, the following terms: a. chemical reaction b. chemical change c. physical change d. change of state e. reactant f. product g. aqueous h. so...
1 answer
Suppose R is a principal ideal domain, and let S be a multiplicatively closed subset of...
Suppose R is a principal ideal domain, and let S be a multiplicatively closed subset of R not containing 0. Show that S-R is a principal ideal domain. Let I be an ideal of a principal ideal domain R. Show that R/I is a principal ideal domain if and only if I is prime....
1 answer
60. In the 2x2x2 Heckscher-Ohlin analysis, if an relatively labor-abundant country is opened to trade, then,...
60. In the 2x2x2 Heckscher-Ohlin analysis, if an relatively labor-abundant country is opened to trade, then, as the movement to trade takes place, the capital/labor ratio used in the country's export industry will _and the capital/labor ratio used in the country's import-competing industry a...
1 answer
A bond has $1,000 par value, 20 years to maturity, a 8% annual coupon and sells...
A bond has $1,000 par value, 20 years to maturity, a 8% annual coupon and sells for $925.00. What is the yield to maturity?...
1 answer
The total electric flux just beyond the surface of a spherical conductor is 951 TNm^2/C (teranewtons...
The total electric flux just beyond the surface of a spherical conductor is 951 TNm^2/C (teranewtons times meters squared per coulomb; tera means 1E12).  What is the total charge on the surface of the conductor (in coulombs)?...
1 answer
23. Two wires A and B with circular cross sections are made of the same metal...
23. Two wires A and B with circular cross sections are made of the same metal and have equal lengths, but the resistance of wire A is three times greater than that of wire B. What is the ratio of the cross- sectional area of A to that of B? a. 3 b. 13 c. 1 d. 1/13 e. 1/3 24. A potential difference o...
1 answer
A frog in a hemispherical pod finds that he floats without sinking into a sea of...
A frog in a hemispherical pod finds that he floats without sinking into a sea of blue- green ooze having a density of 1.30 g/cm3 If the pool has a radius of 7.00 cm and a negligible mass, what is the mass of the frog? 934 g 400 g 200 g 1868 g 3339...
1 answer
Constraint-based Clustering is an approach that cluster data while satisfying a requirement of the domain knowledge...
Constraint-based Clustering is an approach that cluster data while satisfying a requirement of the domain knowledge on the cluster assignment. The constraints are usually expressed as pairwise statements indicating that two items must, or cannot, be placed into the same cluster. 1. Explain the hard ...
1 answer
Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter...
Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter called dataFile (representing the path to a text file) and uses a Set of Strings to eliminate duplicate words from dataFile. The unique words should be stored in an instance variable called ...
1 answer
My Notes Ask Your Five students visiting the student health center for a free dental examination...
My Notes Ask Your Five students visiting the student health center for a free dental examination responses were as follows. dunng National Dental Hygiene ?rth-ere "ked how many months had passed siree ter last vait to. dentist. Their 6 15 12 24 28 Assuming that these five students can be conside...
1 answer
9. For each of the following, draw the structure of the product resulting from the reaction...
9. For each of the following, draw the structure of the product resulting from the reaction of the following aldehydes or ketones CH CH2 CH3 CH2 CH b. H2 CaHis0 CH2 Cl Ho C. CI CI 10, which of the the reactions in #9 could also be described as a. HYDRATION b. HYDROGENATION ? c. REDUCTION...
1 answer
Chapter 7, Section 7.3, Go Tutorial Problem 054 x Incorrect. A radioactive substance decays at a...
Chapter 7, Section 7.3, Go Tutorial Problem 054 x Incorrect. A radioactive substance decays at a constant percentage rate per year. Find the half-life if it decays at a rate of (i) 14% per year Half-life = -4.951 U years. Round the answer to 3 decimal places. (ii) 27% per year Half-life = -2.567 U y...
1 answer
Lawyers are moving to consolidate widespread litigation stemming from Volkswagen AG 's emissions-cheating scandal, drawing the German auto maker into a prolonged legal case expected to spur rafts...
Lawyers are moving to consolidate widespread litigation stemming from Volkswagen AG 's emissions-cheating scandal, drawing the German auto maker into a prolonged legal case expected to spur rafts of depositions and demands for billions of dollars in damages. Plaintiffs' lawyers filed more th...
1 answer
12) (6 points)(a) A Tanabe-Sugano energy level diagram for a d6 octahedral complex is shown below....
12) (6 points)(a) A Tanabe-Sugano energy level diagram for a d6 octahedral complex is shown below. Note that the x-axis is actually Δ/B/10 (ie, a value of 3 is actually 30-A/B.) Numbere arrows representing d-d transitions are drawn at appropriate values of Δ /B for Co F63-and Co(H2NCH2CH...
1 answer
Show steps Supply air for a building is heated from State 1 to State 2 by...
Show steps Supply air for a building is heated from State 1 to State 2 by an electric heater. Given the conditions below determine the following -Given Values- Dry Bulb: T1 (F) 42 Relative Humidity: Phi1(%)-50% Mass flow rate of air: ma1 (lbah) 2094 Dry Bulb: T2 (F) 73 a) Determine the specific volu...
1 answer
Need Help? Read It Talk to Tutor 4. + -12 points SerPSE8 7.P.033.WI. A 3.40-kg object...
Need Help? Read It Talk to Tutor 4. + -12 points SerPSE8 7.P.033.WI. A 3.40-kg object has a velocity (5.20 î - 2.20 )) m/s. (Note: From the definition of the dot product, v2 = 7.7.) (a) What is its kinetic energy at this moment? (b) Find the net work done on the object if its velocity changes ...
1 answer
A pension fund manager is considering three mutual funds. The first is a stock fund, the...
A pension fund manager is considering three mutual funds. The first is a stock fund, the second is a long-term government and corporate bond fund, and the third is a T-bill money market fund that yields a sure rate of 4.0%. The probability distributions of the risky funds are: Expected Return St...
1 answer
Sin 90+ Cos 90=
Sin 90+ Cos 90=...
1 answer
. A granite wall has a thickness of 0.50 m and a thermal conductivity of 2.1...
. A granite wall has a thickness of 0.50 m and a thermal conductivity of 2.1 W/(m · C°). The temperature on one face of the wall is 5.2 °C and 20.0 °C on the opposite face. How much heat is transferred in one hour through each square meter of the granite wall?...