Question

Consider the following list contained in file named input.txt: using java program Khaled 65 78 56...

Consider the following list contained in file named input.txt: using java program

Khaled 65 78 56 89 -999
Kamal 37 55 44 22 18 56 26 -999
Ali 66 33 87 66 87 25 39 78 -999
Taher 12 67 -999
Write a program to read this information and Output the name and sum for each person.

Note: the number of rows may vary.
Assum -999 as sentenital value

Homework Answers

Answer #1

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

package c15;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class FileProcessing {

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       //loading name of file
       File file = new File("input.txt"); //reading data from this file
       Scanner reader;
       try {
           //read file using scanner
           reader = new Scanner(file);
          
           //read until file having more to reads
           while(reader.hasNext()){
              
               //get the name
               String name = reader.next();
              
               //to store numbers
               int num;
              
               //to store sum
               int sum=0;
              
               //now read file until there is integers in it
               while(reader.hasNextInt()) {
                  
                   //get next integers
                   num =reader.nextInt();
                  
                   //if curr number is -999 break
                   if(num==-999) {
                       break;
                   }else {
                       sum +=num;
                   }
               }
              
               //print name and sum
               System.out.print("Name : "+name);
               System.out.println("\t\tSum : "+sum);
           }
       } catch (FileNotFoundException e) {
           System.out.println("file not found");
       }
       sc.close();
   }


}

my input.txt is as below

Khaled 65 78 56 89 -999
Kamal 37 55 44 22 18 56 26 -999
Ali 66 33 87 66 87 25 39 78 -999
Taher 12 67 -999

output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the following list contained in file named input.txt: use (-999) to stop reading grades Khaled...
Consider the following list contained in file named input.txt: use (-999) to stop reading grades Khaled 65 78 56 89 -999 Kamal 37 55 44 22 18 56 26 -999 Ali 66 33 87 66 87 25 39 78 -999 Taher 12 67 -999 Write a program to read this information and Output the name and sum for each person. Note: the number of rows may vary.
have a java application need to create an application which is able to do some analysis...
have a java application need to create an application which is able to do some analysis on temperature data stored in a data file. You will be given the “temperatures.dat” data file which contains the data you must analyze. The analysis you’ll need to do is: Total number of data points Find coldest temperature Find warmest temperature Find average temperature Find the frequency of each temperature Find the most frequent temperature Find the least frequent temperature All classes must be...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
Consider the below vector x, which you can copy and paste directly into Matlab. The vector...
Consider the below vector x, which you can copy and paste directly into Matlab. The vector contains the final grades for each student in a large linear algebra course. x = [61 52 63 58 66 92 64 55 76 60 70 78 76 73 45 63 97 70 100 76 50 64 42 100 67 81 81 59 68 62 72 99 66 76 81 59 47 84 67 75 63 86 73 44 51 69 48 74 61...
Using If and LookUp Formulas Formatting Grades Input boxes in tan Output boxes in yellow Given...
Using If and LookUp Formulas Formatting Grades Input boxes in tan Output boxes in yellow Given data in blue Answers in red Professor Streterstein is a bit absentminded. His instructor’s grade book is a mess, and he would like your help cleaning it up and making it easier to use. In Professor Streterstein’s course, the maximum possible points a student can earn is 750. The following table displays the grade equivalent to total points for the course. Professor Streterstein's Course...
Student Grades Student Test Grade 1 76 62 2 84 90 3 79 68 4 88...
Student Grades Student Test Grade 1 76 62 2 84 90 3 79 68 4 88 84 5 76 58 6 66 79 7 75 73 8 94 93 9 66 65 10 92 86 11 80 53 12 87 83 13 86 49 14 63 72 15 92 87 16 75 89 17 69 81 18 92 94 19 79 78 20 60 71 21 68 84 22 71 74 23 61 74 24 68 54 25 76 97...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a text file data_in.txt with the following information (highlight the piece of text below with numbers and copy it to a text file): 54, 70, 75, 63, 17, 59, 87, 16, 93, 81, 60, 67, 90, 53, 88, 9, 61, 8, 96, 98, 12, 34, 66, 76, 38, 55, 58, 27, 92, 45, 41, 4, 20, 22, 69, 77, 86, 35, 19, 32, 49, 15,...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades and add a linear trendline. What is the​ model? If a student scores 7878 on the​ midterm, what would you predict her grade on the final exam to​ be? Student Midterm Final Exam 1 75 64 2 85 91 3 80 68 4 88 83 5 76 60 6 67 80 7 78 74 8 95 94 9 67 61 10 93 87 11...
This dataset contains consumer responses indicating the number of times they had to send their product...
This dataset contains consumer responses indicating the number of times they had to send their product for repair and their satisfaction with the repair process. Create a graph which can be used to visually demonstrate the relationship between the two columns of data. Ensure that the chart is professional with appropriate titles, axis labels, etc. Note any observations you see in your visualization (type these as sentences directly into an Excel cell(s)). Sample Satisfaction Rating Repair Requests 1 63% 13...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT