Question

DESCRIPTION Complete the program using Java to read in values from a text file. The values...

DESCRIPTION

Complete the program using Java to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number of assignments (number of columns), respectively.

For example, if the file contains:

3
4
9 6 10 5
2 2 0 0
10 10 9 10

then it represents the scores for 3 students on 4 assignments as follows:

Assignment 1

Assignment 2

Assignment 3

Assignment 4

Student 1

9

6

10

5

Student 2

2

2

0

0

Student 3

10

10

9

10

The program should:

1) Read in the first two values to get the number of students and number of assignments. Create a two-dimensional array of integers to store all the scores using these dimensions.

2) Read in all the scores into the 2-D array.

3) Print the whole array, row by row on separate lines, using Arrays.toString() on each row of the array

3) Print the average of the scores on each assignment. For example, if the data is given in the above example, the output would be:

Array of scores:
[9, 6, 10, 5]
[2, 2, 0, 0]
[10, 10, 9, 10]


Average score of each assignment:
Assignment #1 Average = 7.0
Assignment #2 Average = 6.0
Assignment #3 Average = 6.333333333333333
Assignment #4 Average = 5.0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import java.util.*;
import java.io.*;
class ya{
   public static void main(String args[]) throws FileNotFoundException{
       Scanner s=new Scanner(new File("input.txt")); //file name or location
       int a,b;
       a=s.nextInt();
       b=s.nextInt();
       int c[][]=new int[a][b];
       int i,j;
       for(i=0;i<a;i++){
           for(j=0;j<b;j++){
               c[i][j]=s.nextInt();
           }
       }
       System.out.println("Array of scores:");
       for(i=0;i<a;i++){
           System.out.println(Arrays.toString(c[i]));
       }
       System.out.println("\n\nAverage score of each assignment:");
       for(i=0;i<b;i++){
           double sum=0;
           for(j=0;j<a;j++){
               sum=c[j][i]+sum;
           }
           System.out.println("Assignment #"+(i+1)+" Average ="+(sum/a));
       }
   }
}

input.txt:

input.txt - Noter File Edit Format 9 6 10 5 2 200 10 10 9 10

Output:

Array of scores: [9, 6, 10, 5] [2, 2, 0, 0] [10, 10, 9, 10] Average score of each assignment: Assignment #1 Average =7.0 Assi

Add a comment
Know the answer?
Add Answer to:
DESCRIPTION Complete the program using Java to read in values from a text file. The values...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • Exercise 03: Write a program in java that read as input the scores of 3 quizzes...

    Exercise 03: Write a program in java that read as input the scores of 3 quizzes of each student (out of 10 as follows) into a 2-D array: Enter the number of students> 4 Enter quiz scores for student 1> 10.0 2.04.0 Enter quiz scores for student 2> 5.5 6.0 6.0 Enter quiz scores for student 3» 8.259.04.0 Enter quiz scores for student 4> 9.5 8.5 2.0 The program then calculates the average of each quiz score for all the...

  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

  • Python DESCRIPTION Write a program that will read an array of integers from a file and...

    Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • C++ programming language Write a program that asks the user for a file name. The file...

    C++ programming language Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in...

  • Create a program (Lab9_Act1_Write.py) that will read in data from the keyboard and store it in...

    Create a program (Lab9_Act1_Write.py) that will read in data from the keyboard and store it in a file. Your program should prompt the user for the name of the file to use and then request values be entered until the user is done. This data should be written to two files: a text file, user_file_name.txt and a comma separated value file, user_file_name.csv. To help you with decision making, we suggest that you ask the user to input data representing students’...

  • Write a Java program that reads a file until the end of the file is encountered....

    Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...

  • C++ please make it sifferent and unique Description Write a program that will read data from...

    C++ please make it sifferent and unique Description Write a program that will read data from the file "p6.dat". The file (that you will create) always contains 15 test scores (whole numbers between O and 100). The test scores are scores for 5 students taking 3 tests, and are arranged, in the file, by the student - that is the first 3 numbers are the test scores for test 1, 2, and 3 for the first student, etc. The program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT