CSE 214 – Homework I solved

$25.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

This homework document consists of 5 pages. Carefully read the entire document before you start coding. This homework is intended to be a revision of concepts taught in CSE 114. It combines several topics and skills that a student of CSE 214 is already expected to have mastered, including arrays, basic OOP concepts in Java such as extending existing classes and exception handling, and File I/O. 1 Overview The “big picture” of this assignment is to have three parallel arrays that provide information about a list of students. These arrays contain their names, their GPAs, and their student IDs. All the data is provided in a single tab-separated file with each line formatted as follows: namegpastudent id Your submitted assignment should be able to read such a file and fill the three arrays with the appropriate data, print out all the data, and filter out students whose GPA is below a certain user-provided threshold. The outline of the code is already given to you. Your task is to write additional code that conforms to this outline. You must add your own code wherever indicated. Three (incomplete) classes and one small sample input data file are provided: • Main • InputDataHandler • input.txt Keep in mind that you are not allowed to modify the given code (including .java file names). Your homework submission will be tested assuming that the given code structure is unchanged, so any unwarranted change may lead to test cases failing to run properly. 2 Tasks 2.1 The “main” class The main class that runs the whole code is “Main.java”. This class is responsible for reading the input file, creating the object that maintains the three arrays, and then uses this object to print information and filter students based on GPA. The path to the input file must be provided as the value of the constant INPUT FILE PATH first. The code for Main.java is incomplete, and your first task is complete it. After reading the data from the input file, the program asks the user to provide a GPA value as a cutoff for enrollment. Completing this is a part of your assignment. This is VERY important, because without this, the next part of the program cannot be tested! The incomplete Main.java is shown next. 1 CSE 214 Homework I Submission Deadline: Feb 5, 2017 Main.java import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; /** @author Ritwik Banerjee */ public class Main { private static final String INPUT_FILE_PATH = “/path/to/input/file”; public static void main(String[] args) throws URISyntaxException, IOException, InputFileFormatException { File inFile = new File(INPUT_FILE_PATH); InputDataHandler handler = new InputDataHandler(inFile); handler.printAllDetails(); System.out.print(“Enter the GPA cutoff for the course: “); // TODO: add your code to read user input handler.filter(cutoff); handler.printAllDetails(); } } Task Goals • The cutoff GPA provided by the user should be deemed invalid if it is lower than 1.0 or higher than 4.0. It should, of course, be deemed invalid if it anything other than a double. • If the user enters an invalid cutoff GPA value, your code should print a meaningful error message and ask for the user input again. 2.2 Processing input data and the “InputDataHandler” class This is where all the data handling and processing happens. Your job here is to write • the constructor for this class, • the printAllDetails() method, • the deleteStudent(int) method, and • a Java documentation in the same style as shown in the provided code to explain what could go wrong in the filter(double) method (i.e., why it may fail to remove students whose GPA is below the cutoff provided by the user). All three tasks must adhere to the documentation provided in the code. InputDataHandler.java import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; /** @author Ritwik Banerjee */ class InputDataHandler { CSE 214 Homework I Submission Deadline: Feb 5, 2017 private String[] nameArray; private Double[] gpaArray; private Integer[] idArray; // TODO: write Javadoc explaining why this approach of filtering may fail void filter(double cutoff) { for (int i = 0; i < gpaArray.length; i++) { if (gpaArray[i] < cutoff) deleteStudent(i); } } /** * The only constructor for this class. It takes an input file as its argument, * and populates the three arrays such that the n’th line’s data is stored in * the (n-1)’th index of all three arrays. It throws an IOException * if the inputFile is not a file (e.g., it’s a directory, symbolic link, * etc.). It also throws an InputFileFormatException if the input file * contains lines that are not properly formatted or if it contains a line with * an invalid value for the GPA. * * @param inputFile the input file with 3 columns of tab-separated data in each line. * @throws IOException if there is any problem reading the input file. * @throws InputFileFormatException if there is any formatting problem in the * input file. */ InputDataHandler(File inputFile) throws IOException, InputFileFormatException { // TODO: add your code } /** * Prints out the details of all the students in this class. * This must be in the following format: *
* Name : name of student
* GPA : GPA of student
* Student ID: ID of student
* There must also be a one-line gap between two students. */ void printAllDetails() { // TODO: add your code } /** * This method removes all the information about a student whose information * is stored at the specified index (in all three arrays). It also ensures * that after the removal, all three arrays in the InputDataHandler * class have their size reduced by one, and subsequent student information CSE 214 Homework I Submission Deadline: Feb 5, 2017 * is shifted to the left by one. * * @param index the specified index where data is removed. private void deleteStudent(int index) { // TODO: add your code } } 2.3 Writing your own exception The InputFileFormatException class is something you will have to write yourself. It must be a direct subclass of java.lang.Exception, and have a constructor that allows an error message to be taken as its argument. 3 Sample Input File “input.txt” John Doe 3.3 123123123 Jane Doe 3.42 908761254 Boaty McBoatface 2.94 987654102 Note: Copy-pasting from a PDF may destroy the tab-spacing. If you paste this into a plain-text file from the PDF, make sure you verify the whitespaces are tabs! 4 Grading Scheme Accepting user input in Main.java (with all validity checks) (12 points) Constructor for InputDataHandler (12 points) Writing printAllDetails() (3 points) Writing deleteStudent(int) (10 points) Writing InputFileFormatException (6 points) Javadoc explaining problem with filter(double) (7 points) TOTAL 50 points 5 Additional Information and Notes Can I change the given code? • You may not modify any code provided, and that includes visibility, signature, and method names. • You may add your own methods to what is already given. As long as the final output adheres to the documentation given to you, there are no restrictions in these methods. Can I use array deletion methods already given in Java or in some other library? • NO. You must write your own code for everything in this assignment. If you have a doubt about whether or not some readily available method can be used, ask on Piazza so that a TA can respond to such questions. CSE 214 Homework I Submission Deadline: Feb 5, 2017 What should I submit? A single .zip consisting of only three files: • Main.java, • InputDataHandler.java, and • InputFileFormatException.java How do I know if my Javadoc is correct? The logic of what you write is your actual answer, and that is a part of the assignment. The visual appearance of your documentation can be previewed by associating a key shortcut to “Quick Documentation”. You can find this in your IntelliJ IDEA by opening ‘Preferences’, clicking on ‘Keymap’, and then searching for “Quick Documentation”. You can then assign any shortcut you want! This will help you throughout your programming life since almost every IDE has some similar feature for any programming language it supports. • Please pay attention to the use of HTML tags in the Javadoc. These details will help you write your own Java documentation. I submitted something wrong by mistake . . . what should I do now? You are allowed up to 4 attempts until the deadline (at which point, submissions will no longer be accepted). If you have made a mistake, you must resubmit ALL files again (i.e., create your .zip file again). Partial resubmissions are not possible on Blackboard. What expressions will the code be tested with? Test cases cannot be disclosed ahead of time! You can, of course, create your own example input files to test your code, in addition to the sample input.txt already provided. My code compiles on my laptop but . . . Then you have changed some code that you were not supposed to change, or submitted something that is not in line with the guidelines provided, or used a different non-standard Java compiler (issue already discussed in class). If your code does not compile, it will not be graded. I submitted the class files by mistake. Class files are not code. It cannot be graded. Multiple (up to 4) attempts are allowed on Blackboard such that everyone has several chances to correct such mistakes. I missed the deadline by 2 minutes . . . Do NOT continue coding until the last minute! Verifying the code, properly creating the .zip file, etc. . . . these things take some time, and you are responsible for managing all this within the deadline. Late submissions will not be accepted under any circumstances. • If too many students are trying to submit at, say, 11:58 pm one minute before the deadline, Blackboard server may become very slow and you may end up missing the submission deadline! To be safe, always, ALWAYS, prepare to submit ahead of time, not exactly AT last moment!