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.
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...
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...
Q FC ATC AVC MC P MR 50 1000 40.00 20 20 92 39 51 1000...
Q FC ATC AVC MC P MR 50 1000 40.00 20 20 92 39 51 1000 39.65 20.04 22 91 41 52 1000 39.35 20.12 24 90 39 53 1000 39.09 20.23 26 89 37 54 1000 38.89 20.37 28 88 35 55 1000 38.73 20.55 30 87 33 56 1000 38.61 20.75 32 86 31 57 1000 38.53 20.98 34 85 29 58 1000 38.48 21.24 36 84 27 59 1000 38.47 21.53 38 83 25 60 1000 38.50...
Many standard statistical methods that you will study in Part II of this book are intended...
Many standard statistical methods that you will study in Part II of this book are intended for use with distributions that are symmetric and have no outliers. These methods start with the mean and standard deviation, x and s. For example, standard methods would typically be used for the IQ and GPA data here data215.dat. (a) Find x and s for the IQ data. (Round your answers to two decimal places.) s= Here are the numbers obs gpa iq gender...