Question
Implement a Java program that accepts command line arguments with appropriate error handling. Write code that reads input data from a CSV file to construct
- Implement a Java program that accepts command line arguments with appropriate error handling.
- Write code that reads input data from a CSV file to construct a multidimensional array with appropriate error handling.
- Demonstrate an understanding of functional decomposition by implementing separate methods for file I/O and array processing.
The starter code is provided for this project. You can download the file here - Project1.java Download Project1.java
You will implement the methods to provide the functionality described in this document and in the comments in the starter code.
All classes will be graded using a JUnit test suite, so the method headings for all methods need to match the test class exactly. Therefore, you are not to change any method headers or package statements.
Your source code file name should be Project1.java. It must be located in the cmsc256 package as indicated in the starter code file.
A sample input file is provided but your code should be flexible enough to run with a different data file. You can download the input file here - 500_Person_Age_Height_Weight.csv Download 500_Person_Age_Height_Weight.csv
The Project1 program is to:
- Read in the input file creating a 2-dimensional String array from the data contained in the lines of the file using the designated methods to provide the functionality
- Implement the functionality listed for each method
Make sure your program is well documented - including the comment block header at the top of all of the source code files with your name, the course number and name, the project name, the program purpose. Be sure to include appropriate comments throughout your code, choose meaningful identifiers, and use indentation as shown in your textbook and in class. import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /** * Project */ // place any import statements here public class Project1 { public static void main(String[] args) { // Test your program thoroughly before submitting. // For example, // Display appropriately labeled information for the following: // What is tallest height? // Which row has the lowest weight? // Calculate average height of 20-30 year age range in the data. }
/** * Gets the file name from command line argument; * If parameter is empty, call promptForFileName() method * * @param argv String array from command line argument * @return the name of the data file */ public String checkArgs(String[] argv) {
}
/** * Prompt user to enter a file name * * @return user entered file name */ public String promptForFileName() { }
/** * Retrieve file with the given file name. * Prompts user if file cannot be opened or does not exist. * * @param fileName The name of the data file * @return File object * @throws java.io.FileNotFoundException */ public File getFile(String fileName) throws FileNotFoundException { }
/** * Reads the comma delimited file to extract the number data elements * provided in the second argument. * * @param file The File object * @param numRecords The number of values to read from the input file * @return 2D array of data from the File * @throws IOException if any lines are missing data */ public String[][] readFile(File file, int numRecords) throws IOException { }
/** * Determines the tallest height in the data set * Height is the second field in each row * * @param db 2D array of data containing [age] [height] [weight] * @return Maximum height value */ public int findTallest(String[][] db) { }
/** * Returns the values in the record that have the lowest weight * * @param db 2D array of data containing [age] [height] [weight] * @return Smallest weight value */ public String[] findLightestRecord(String[][] db) { }
/** * Calculates the average height for all records with the given age range. * * @param db 2D array of data containing [age] [height] [weight] * @param lowerBound youngest age to include in the average * @param upperBound oldest age to include in the average * @return The average height for the given range or 0 if no * records match the filter criteria */ public double findAvgHeightByAgeRange(String[][] db, int lowerBound, int upperBound) {
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started