In: Computer Science
Exercise 2:
You are employed as a work study student on campus and have been asked by a professor to create a spreadsheet to help with final grade reporting. The professor would like to record final grades for 10 students. The first column should contain the student’s last name (input), the second column should contain the student’s first name (input), and the third column should contain the student’s final course percentage grade (input) -- enter as a whole number, not a percent…ie: 85 not .85 or 85%. The fourth column will be the output and will use a LOOKUP formula to calculate the letter grade earned in the course.
The professor’s grading scale is as follows:
A 90-100
B 80-89
C 70-79
D 60-69
F Below 60
Short Summary:
Implemented the program as per requirement in java (as coding
language is not mentioned in the question)
Attached source code and sample output
**************Please do upvote to appreciate our time.
Thank you!******************
Source Code:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
/** This class generates a spreadsheet with student data
**/
public class CSVOperations {
public static void main(String args[]) throws
IOException
{
//Initialize array with size
try
{
//Use Scanner to
get user data
Scanner in=new
Scanner(System.in);
//BufferedWriter
to write csv data
BufferedWriter
outputWriter = new BufferedWriter(new
FileWriter("C:\\Users\\asus\\GradeReport.csv"));
outputWriter.write("Last Name"+","+"First Name"+","+"Final
Score"+","+"Grade"+"\n");
//Iterate and
write to same csv file
for(int
i=0;i<10;i++)
{
System.out.print("Enter student last name:
");
String lname=in.nextLine();
System.out.print("Enter student first name:
");
String fname=in.nextLine();
System.out.print("Enter student's final
grade:(Enter as whole number 85,90 etc.,)");
int gradeScore=in.nextInt();
char grade='A';
if(gradeScore>=90 &&
gradeScore<=100)
grade='A';
else if(gradeScore>=80 &&
gradeScore<90)
grade='B';
else if(gradeScore>=70 &&
gradeScore<80)
grade='C';
else if(gradeScore>=60 &&
gradeScore<70)
grade='D';
else if(gradeScore<60)
grade='F';
in.nextLine();
outputWriter.write(lname+","+fname+","+gradeScore+","+grade);
outputWriter.newLine();
}
in.close();
outputWriter.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
Code Screenshot:
Output:
Have attached output for first 3 records:
CSV file:
**************Please do upvote to appreciate our time.
Thank you!******************