Write a complete program to get data from file name DATA.TXT one line at a time
ID: 3644541 • Letter: W
Question
Write a complete program 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 +%40assignments + %10 Participation+ %final
If total >= 90 then A else if total>=80 then B
Explanation / Answer
import java.util.Scanner; import java.io.*; public class FileInput { public static void main (String[] args) { try { Scanner inFile = new Scanner(new FileInputStream("numbers.txt")); int sum = 0; int number = 0; while(inFile.hasNextLine()) { String oneline = inFile.nextLine(); number = Integer.parseInt(oneline); System.out.println(number); sum = sum + number; } inFile.close(); System.out.println("The sum of the numbers is " + sum); } catch(FileNotFoundException fnfe) { System.out.println("File not found!!"); } }//end of main }//end of class
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.