Question

Java program The file enrollments.txt is a text file with each line containing a positive integer...

Java program

The file enrollments.txt is a text file with each line containing a positive integer that represents the enrollment in a section of CIS 103. The highest value is 36. Write a program to read the data from the file into an array, then calculate and display the number of sections, the average class size, the minimum class size, and the maximum class size.

enrollments.txt

36
36
36
34
35
25
34
31
29
19
35
33
36
32
34
25
36
36
36
32
34
31
30

please do in netbeans.

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

Code

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;

public class classEnrollment
{
   public static void main(String args[]) throws FileNotFoundException, IOException
   {
       BufferedReader br = new BufferedReader(new FileReader("enrollments.txt"));
      
       //if number of Sections has to be Increased just go to higher value in new int[ ]
       int arr[] = new int[24];
       int index = 0;
       int sum = 0;

       String line = br.readLine();
       while(line != null)
       {
           int j = Integer.parseInt(line);
           sum += j;
           arr[index] = j;
           index++;
           line = br.readLine();
       }

       int minimumvalue = arr[0], maximumvalue = arr[0];
       // Finding Minimum value and Maximum value of the class
       for(int i = 0; i < arr.length; i++)
       {
           //To find Minimum Class Size
           if(minimumvalue > arr[i])
           {
               minimumvalue = arr[i];
           }
           //To find Maximum Class Size
           if(maximumvalue < arr[i])
           {
               maximumvalue = arr[i];
           }
       }

       // Finding the average of Section 103
       float avg = sum/arr.length;
       System.out.println("\nSections of CSE 103 : " +Arrays.toString(arr));
       System.out.println("\nTotal number of Sections    : "+arr.length);
       System.out.println("Average Class Size        : "+avg);
       System.out.println("Section   which contains minimum Class Size or Students : "+minimumvalue);
       System.out.println("Section   which contains maximum Class Size or Students : "+maximumvalu

Add a comment
Know the answer?
Add Answer to:
Java program The file enrollments.txt is a text file with each line containing a positive integer...
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 program that reads a file containing an arbitrary number of text integers that are...

    Write a program that reads a file containing an arbitrary number of text integers that are in the range 0 to 99 and counts how many fall into each of eleven ranges. The ranges are 0-9, 10-19, 20-29,..., 90-99 and an eleventh range for "out of range." Each range will correspond to a cell of an array of ints. Find the correct cell for each input integer using integer division. After reading in the file and counting the integers, write...

  • Lab 10 Write a Java program that reads the integer numbers in a text file (numbers.txt)...

    Lab 10 Write a Java program that reads the integer numbers in a text file (numbers.txt) and stores the numbers to a binary file (binaryNumber.dat).The number.txt file contains the following numbers: 1 2 3 4 5 6 7 8 9 0

  • These are my instructions: Your data should have been read in from the data file and stored into ...

    These are my instructions: Your data should have been read in from the data file and stored into an array. Next you need to calculate the following and display in a single Message box: Average score Highest score Lowest score Mode of the scores Your program should be written using methods and should be well documented internally and externally. Your output should be displayed using Message boxes. This is the .text file to use with the instructions: 20 21 22...

  • In C++ Make a program that takes a positive integer 'n' and write an n x...

    In C++ Make a program that takes a positive integer 'n' and write an n x n matrix whose entries are listed as snail Example: (See picture) for n=6 Ej. Para n-6 2 2 2 20 21 22 23 24 7 19 32 33 34 258 18 31 36 35 26 9 17 30 29 28 27 10 16 15 14 13 12 11

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from...

    Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from a file named dota.txt that is to be found in the same directory as the running program. The program should ignore al tokens that cannot be read as an integer and read only the ones that can. After reading all of the integers, the program should print all the integers back to the screen, one per line, from the smalest to the largest. For...

  • Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array....

    Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...

  • Java Programming Reading from a Text File Write a Java program that will use an object...

    Java Programming Reading from a Text File Write a Java program that will use an object of the Scanner class to read employee payroll data from a text file The Text file payroll.dat has the following: 100 Washington Marx Jung Darwin George 40 200 300 400 Kar Car Charles 50 22.532 15 30 The order of the data and its types stored in the file are as follows: Data EmployeelD Last name FirstName HoursWorked double HourlyRate Data Tvpe String String...

  • 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)...

  • Therefore, for this program you will read the data in the file named weatherdata_2.txt into arrays...

    Therefore, for this program you will read the data in the file named weatherdata_2.txt into arrays for the wind speed and for the temperature. You will then use the stored data to calculate and output the average wind speed and the average temperature. Create a constant with a value of 30 and use that to declare and loop through your arrays and as a divisor to produce your averages. Here is the data file (below). 1. 14 25 2. 12...

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