Question

i have the text file to pull info off of. This is for JAVA. Must use...

i have the text file to pull info off of. This is for JAVA. Must use arrays, JOptionPane, methods, and be able to pull and count from the file that is provided to me by my instructor. The file is a txt file that has over 1000 test scores on it without commas. Spaces are used. Please help.

Standardized Test Scores

          A local high school is giving a standardized test to all of its students. There are 50 questions on the test and the school would like you to gather some statistics on how the students performed. Scores can range anywhere from 0 to 50. All the scores are stored in a file (scores.txt) that you will need to download.

Input the data from the file and store the data into an array. To do this, you will have to have your program open the data file, count the number of elements in the file, close the file, initialize your array, reopen the file and load the data into the array.

          Next, display to the screen the number of students who got a perfect 50 score.

Your program should be written using methods and should be well documented internally and externally. Your output should be displayed using Message boxes.

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

/**********************************Program.java****************************/

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

import javax.swing.JOptionPane;

public class Program {

   public static void main(String[] args) {

       String fileName = JOptionPane.showInputDialog("Please enter file name");
       int numberOfScores = getNumberOfScores(fileName);

       int[] scores = getScores(fileName, numberOfScores);

       int perfectScorer = countNumberOfStudents(scores);

       JOptionPane.showMessageDialog(null, perfectScorer + " Students get the Perfect 50 score!");
   }

   public static int[] getScores(String fileName, int numberOfScores) {

       int[] scores = new int[numberOfScores];
       int i = 0;
       try {
           Scanner scan = new Scanner(new File(fileName));
           while (scan.hasNext()) {

               scores[i] = scan.nextInt();
               i++;
           }
           scan.close();
       } catch (FileNotFoundException e) {

           System.err.println(e);
       }
       return scores;
   }

   public static int getNumberOfScores(String fileName) {

       int numberOfScores = 0;
       try {
           Scanner scan = new Scanner(new File(fileName));
           while (scan.hasNext()) {
               scan.nextInt();
               numberOfScores++;
           }
           scan.close();
       } catch (FileNotFoundException e) {

           System.err.println(e);
       }

       return numberOfScores;
   }

   public static int countNumberOfStudents(int[] scores) {

       int count = 0;

       for (int i = 0; i < scores.length; i++) {

           if (scores[i] == 50) {

               count++;
           }
       }

       return count;
   }
}
/*******************scores.txt**********************/

12 50
34
50
45
46
34
24 50 34 43 23 42
45
23
42
50

/**********************output*****************/

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
i have the text file to pull info off of. This is for JAVA. Must use...
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
  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

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

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

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • Registration Language Java Step 1: Design a class called Student. The Student class should contain the...

    Registration Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration”...

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

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • In JAVA Create a program with an array with the following data: 50 12 31 76...

    In JAVA Create a program with an array with the following data: 50 12 31 76 5 23 15 Use a text file (.txt created in notepad) to read the data into the array. Write a sort method (your choice of sorting algorithm) to sort the array values values - highest to lowest. Write a method to determine the minimum value. Your program should call the sort and minimum methods. Output the sorted array and minimum value.  

  • Create a JAVA program with an array with the following data: 50 12 31 76 5...

    Create a JAVA program with an array with the following data: 50 12 31 76 5 23 15 Use a text file (.txt created in notepad) to read the data into the array. Write a sort method (your choice of sorting algorithm) to sort the array values values - FROM HIGHEST TO LOWEST. Write a method to determine the minimum value. Your program should call the sort and minimum methods. Output the sorted array and minimum value.

  • in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a...

    in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a program that asks the user for an input file name, open, read ar number of students is not known. For each student there is a name and and display a letter grade for each student and the average test score fc • openFile: This method open and test the file, if file is not found and exit. Otherwise, return the opened file to the...

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