Need to help to modify this code below to do what question above is asking; impo
ID: 3656798 • Letter: N
Question
Need to help to modify this code below to do what question above is asking;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.*;
import java.io.InputStreamReader;
import java.util.*;
public class question4a
{
public static void main(String[] args) throws IOException //Main method
{
String filename,buffer,parts[];
double grade;
Scanner input=new Scanner (System.in);
System.out.print("Enter name of input file:"); // promts user to enter input file.
filename=input.nextLine();
Scanner scan=new Scanner(new File(filename));
System.out.print("Enter name of output file: "); // promts user to enter output file.
filename=input.next();
PrintStream output=new PrintStream(new File(filename));
output.println("name Grade");
while(scan.hasNext())
{
buffer=scan.nextLine();
parts=buffer.split(":");
grade=Double.parseDouble(parts[1]);
output.println(parts[0]+" "+getGrade(grade));
}
System.out.println("Processing complete."); //Promts user that the process has completed.
} // main close
public static String getGrade(double mark) // This method returns proper letter grades for the number grades processed.
{
if(mark < 50) // Less then 50 "F"
{
return "F";
} else if (mark >= 50 && mark <= 59) // 50 -59 "D"
{
return "D";
} else if(mark >= 60 && mark <= 69) // 60-69 "C"
{
return "C";
} else if(mark >= 70 && mark <= 79) // 70-79 "B"
{
return "B";
} else if(mark >= 80 && mark <= 89) // 80-89 "A"
{
return "A";
} else
{
return "A+"; // 90 - 100 "A+"
}
} // getGrade close
}
badgrades input file contians;
mark L:100
Steve Jobs:102
Bill Gates:12
Dennis Ritchie:B
Ken Thompson:-9
Linus Torvalds:55
Mark Zuckerberg:62
Explanation / Answer
Please change the mark for Dennis Ritchie:B. Otherwise it will throw NumberFormatException. or else modify the java class to catch the exception. import java.io.BufferedReader; import java.io.IOException; import java.io.*; import java.io.InputStreamReader; import java.util.*; public class question4a { public static void main(String[] args) throws IOException // Main method { String filename, buffer, parts[]; double grade = 0; Scanner input = new Scanner(System.in); System.out.print("Enter name of input file:"); // promts user to enter // input file. filename = input.nextLine(); Scanner scan = new Scanner(new File(filename)); System.out.print("Enter name of output file: "); // promts user to enter // output file. filename = input.next(); PrintStream output = new PrintStream(new File(filename)); output.println("name Grade"); while (scan.hasNext()) { buffer = scan.nextLine(); parts = buffer.split(":"); try { grade = Double.parseDouble(parts[1]); } catch (NumberFormatException e) { //e.printStackTrace(); System.out.println("Please entet proper marks for "+ parts[0]); } output.println(parts[0] + " " + getGrade(grade)); } System.out.println("Processing complete."); // Promts user that the // process has completed. } // main close public static String getGrade(double mark) // This method returns proper // letter grades for the number // grades processed. { if (mark < 50) // Less then 50 "F" { return "F"; } else if (mark >= 50 && mark = 60 && mark = 70 && mark = 80 && markRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.