Question

Write the method loadArray. The method will declare and open a file stream and connect it to the external file passed in. It looking for in Java
0 0
Add a comment Improve this question Transcribed image text
Answer #1
public static int loadArray(String filename, String[] patients, double[] temps, int numPatients) {
    File file = new File(filename);    // read a file and create a file.
    try {
        Scanner fin = new Scanner(file);    // create a scanner to read from file
        numPatients = 0;
        while (fin.hasNext() && numPatients < patients.length) { // read each line from file
            patients[numPatients] = fin.next();
            temps[numPatients] = fin.nextDouble();
            ++numPatients;
        }
        fin.close();    // close file.
    } catch (IOException e) {
        System.out.println("Error. " + file.getAbsolutePath() + " does not exists!");   // if file does not exist, report an error
    }
    return numPatients;
}
Add a comment
Know the answer?
Add Answer to:
looking for in Java Write the method loadArray. The method will declare and open a file...
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
  • In C++ First create the two text file given below. Then complete the main that is given. There ar...

    In C++ First create the two text file given below. Then complete the main that is given. There are comments to help you. An output is also given You can assume that the file has numbers in it Create this text file: data.txt (remember blank line at end) Mickey 90 Minnie 85 Goofy 70 Pluto 75 Daisy 63 Donald 80 Create this text file: data0.txt (remember blank line at end) PeterPan 18 Wendy 32 Michael 28 John 21 Nana 12...

  • JAVA PLEASE! Write a method called displayPets that takes an array of strings as input. The...

    JAVA PLEASE! Write a method called displayPets that takes an array of strings as input. The method should display the contents of the pets array on one line. Each name should be separated by a space. Use an enhanced for loop to iterate the array. Make sure to declare modifier, parameters and return values. Given an array String[] pets = {"Lucky", "Slinger", "Beast", "Trumpet", "Lulu", "Shadow", "Daisy"} A sample run when calling displayPets(pets) from main() would look like: Pets names:...

  • First create the two text file given below. Then complete the main that is given. There...

    First create the two text file given below. Then complete the main that is given. There are comments to help you. An output is also given You can assume that the file has numbers in it Create this text file: data.txt (remember blank line at end) Mickey 90 Minnie 85 Goofy 70 Pluto 75 Daisy 63 Donald 80 Create this text file: data0.txt (remember blank line at end) PeterPan 18 Wendy 32 Michael 28 John 21 Nana 12 Main #include...

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

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • part one : Review Exercises 1. Write method called raggedCount that takes an integer n as...

    part one : Review Exercises 1. Write method called raggedCount that takes an integer n as argument and returns a ragged array of n rows of lengths 1, 2, 3, 4, ... , n and the whole array has the integers 1, 2, 3, 4, ... , n(n+1) 2 in row order. For example, raggedCount(4) should return the array: 1 2 3 4 5 6 7 8 9 10 1 2. Write a method called arrayConcat that takes as argument...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

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
ADVERTISEMENT