Write a complete program in Java to get data from file name DATA.TXT one line at
ID: 3863536 • Letter: W
Question
Write a complete program in Java to get data from file name DATA.TXT one line at a time until there is no more data in that file. The following is one sample line in DATA.TXT ( have as many record as you wish in DATA.TXT)
Name SSN quiz mid assignments participation final
LISA 111-11-1111 100 100 100 100 100
Jack 222-22-2222 80 80 100 90 100
Note that the first line is no in DATA.txt. Your program should create a file name RESULT.txt that reports Name, SSN and a letter grade according to the following rules: Total= 15% quiz + 15 %mid +40% assignments + 10% Participation+ 20%final If total >= 90 then A else if total>=80 then B…. You can print same output to screen as well as RESULT.txt.
Explanation / Answer
Hi buddy, please find below java program (NOTE : Make sure that you only give a single space between strings)
PROGRAM :
package sample1;
import java.io.*;
public class Sample1 {
public static void main(String[] args) throws FileNotFoundException, IOException{
BufferedReader br = new BufferedReader(new FileReader(new File("P:/DATA.txt")));
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("P:/RESULT.txt")));
String str = br.readLine();
while((str=br.readLine())!=null){
String t[] = str.trim().split(" ");
String name = t[0];
String ssn = t[1];
double total = 0.15*Integer.parseInt(t[2].trim())+0.15*Integer.parseInt(t[3].trim())+0.40*Integer.parseInt(t[4].trim())+0.10*Integer.parseInt(t[5])+0.20*Integer.parseInt(t[6]);
String grade = "";
if(total>=90){
grade = "A";
}
else if(total>=80){
grade = "B";
}
else if(total>=70){
grade = "C";
}
else if(total>=60){
grade = "D";
}
else{
grade = "F";
}
System.out.println(name+" "+ssn+" "+grade);
bw.write(name+" "+ssn+" "+grade+" ");
}
bw.flush();
bw.close();
}
}
OUTPUT :
LISA 111-11-1111 A
Jack 222-22-2222 A
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.