my code for this part work fine and is import java.io.BufferedReader; import jav
ID: 3656823 • Letter: M
Question
my code for this part work fine and is
import java.io.BufferedReader;
import java.io.IOException;
import java.io.*;
import java.io.InputStreamReader;
import java.util.*;
public class q4w
{
public static void main(String[] args) throws IOException
{
String filename,buffer,parts[];
double grade;
Scanner input=new Scanner (System.in);
System.out.print("Enter name of input file:");
filename=input.nextLine();
Scanner scan=new Scanner(new File(filename));
System.out.print("Enter name of 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.");
} // main close
public static String getGrade(double mark)
{
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
}
Need help to do this part below.
input file contains:
Steve Jobs:102
Bill Gates:12
Dennis Ritchie:B
Ken Thompson:-9
Linus Torvalds:55
Mark Zuckerberg:62
Explanation / Answer
Dennis Ritchie:B score for Dennis Ritchie is not double value, so we iwll get numberformatexception. change to double vlaue or modify the program to prompt for the correct score. Java class: **************** 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
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.