首页 > > 详细

讲解 COMP SCI 200: Programming I调试Java编程

COMP SCI 200: Programming I

12.10 ***zyLab: H12CustomApp (Required & Human Graded)

Objective: The goal of the H12CustomApp project is to expand your Java programming skills by creating a personalized application that interacts with a user and writes to and reads from text data files. This application is similar to H8 and H10 in that it is an interactive program with a modular design and a test bench. It is different from H10 in that there must be a method that writes to a data file and another method that reads from a data ¦le and the test bench has 2 test cases demonstrating that the read ¦le method works correctly and 2 test cases demonstrating that the write file method works correctly.

In this assignment, use only material through module/chapter 11, File Input and Output. For example, don't use instantiable classes or variables outside of methods other than static final variables (constants).

There are some different re§ection questions from previous human-graded assignments. Please download the template to see them.

Key Requirements:

Read File Method:

  This method should not use hardcoded file names or static fields. Instead, all required information, such as file paths, should be passed to it via parameters.

  The method must be capable of reading from a file provided through its parameters and return the contents appropriately.

   Determine a better name than readFile appropriate to your program.

   Make sure the method is more complex than simply returning all the data in the file as  a string. For example, select aspects of the contents to return specified by parameters. Don't reuse a method demonstrated in class materials or another assignment.

  The method header comment includes something about how errors are handled such as a file not being found.

   Don't use regular expressions other than a simple literal character such as a comma,  colon, semicolon, space, or tab, for example in the String split method. Use loops and branching statements to solve parsing problems.

   Must not interact with the user (don't use a Scanner reading from System.in within the method).

   Must use only the file input classes demonstrated in the course materials.

   Don't solely rely on the Java libraries when implementing methods, write the code!

  This method header comment has a summary and what happens on errors such as a file not being found. Examples are also helpful to include in the method header comments.

  When designing consider what the parameters should be:

 How does the main method tell the read ¦le method which ¦le to read? Will the

read ¦le method have a String parameter containing the ¦lename, a File object, or  an opened InputStream? Don't hardcode the name of the file to read from/write to within the method, pass it as a parameter.

 How do you tell the method which data to read? Is there a column of data to look at, such as the 2nd column, or a column with a speci¦c name? Are there speci¦c  lines to look for, such as having specific line numbers or containing specific values? (See example data ¦les RomeoAndJuliet.txt, 4Letter1SyllableWords.txt, exampleData1.tsv, exampleData2.tsv.)

 Are data structures (e.g., an array or ArrayList) passed in that will be ¦lled with the values? Or are values returned?

 Is there a throws clause or are any checked exceptions caught within the method?

 Is there a returned value that indicates an error (e.g., a string with the error message, an int with an error value, null for a reference type)?

Write File Method:

.  Similar to the read file method, this method should avoid hardcoded file names and static fields. All necessary data, including file paths and content to be written, must be supplied through parameters.

.  Determine a better name than writeFile appropriate to your program.

   Make sure the method is more complex than simply writing a single content string to the file. For example, pass a data structure and other parameters that have data and write them to the file. Don't reuse a method demonstrated in class materials or another assignment.

.  The method header comment includes something about how errors are handled such as a file not being able to be written.

.  Must not interact with the user (don't use a Scanner reading from System.in within the method).

.  Must use only the file output classes demonstrated in the course materials.

.  Don't solely rely on the Java libraries when implementing methods, write the code!

  This method header comment has a summary and what happens on errors such as a file not being found. Examples are also helpful to include in the method header comments.

  When designing consider what the parameters should be:

 How does the main method tell the write ¦le method which ¦le to write? Will the    write file method have a String parameter containing the filename, a File object, or an opened PrintWriter? Don't hardcode the name of the file to write to within the method, pass it as a parameter.

 How do you provide the method the data it will write? Are there multiple

parameters or data structures? Are there parameters that specify which part of the data structures to write to the ¦le?

 Is the file intended to be read by a program? For example are there just rows and columns of data? (See exampleData1.tsv, exampleData2.tsv).

 Is the file intended to be read by a human or through a browser such as having a title, summary, etc? (See ExampleTextReport.txt, ExampleHTMLReport.html)

 Is there a throws clause or are any checked exceptions caught within the method?

 Is there a returned value that indicates an error (e.g., a string with the error message, an int with an error value, null for a reference type)?

main method:

.  Must interact with the user or call methods that interact with the user.Safely reads in input using Scanner hasNextX methods before reading values using nextX methods or uses exception handling. Appropriate error messages should be printed out. The program should not crash on incorrect input.

.  Calls the read and write file methods.

.  Prompts the user before reading in values. For example, this may include the name of  the file to read from, which lines or fields to read, and what calculation to perform. This may include the name of the file to write to, whether a plain text file, a comma-separated values (CSV) file, an HTML file, or some other format.

.  There must always be something printed to System.out by the program.

.  Output values are appropriately described. For example, a number with a unit such as 42 degrees Celsius.

.  All methods must have a summary and it is typically useful to describe what happens on errors and provide examples.

.  When designing consider different choices:

 Are names of files already known (e.g., con¦guration ¦les such as myProg.dat that would be specified with a constant in main), or is the user prompted?

 Are specific parameters, specifying what to read, constants in the main method or provided by a user?

 For the read file method are data structures created empty in main or does the read method return the data structures?

 For the write file method are data structures filled with data from a user, from the read file method, or created?

Test Bench Implementation:

  You are required to create a separate Java file named TestH12CustomApp.java. This file must contain a method testH12CustomApp() that calls a minimum of four test cases:

  Two test cases for the Read File Method: A test case should involve creating a

temporary file with example data (see provided test cases and the createTestDataFile method), attempting to read this ¦le using the read file method, and validating the output against expected results.

  Two test cases for the Write File Method: A test case should write to a temporary file using the write file method and subsequently read the file (see provided test cases and the readTestDataFile method) to check if the contents match the expected data.


   Each test case must have an English summary specifying specifically what that test case is testing.

   Each test case demonstrates the method works as described in the method header comment.

   If a read ¦le method or write file method throws a FileNotFoundException, for example, it would be appropriate to catch that exception in a test case to verify that the method  is throwing it appropriately.

  Test Execution and Validation: The method should return true if all test cases pass (i.e.,  if the read and write operations produce the expected results in all instances),and false otherwise.

  Test cases should run without user interaction. Don't use System.in in test cases. Your code should not need to use Scanner in test cases.

   Integration with zyBooks: Your testH12CustomApp() method will be directly used by

the zyBooks platform. to evaluate the functionality and correctness of your ¦le handling methods.

   Ensure that your methods are robust and handle exceptions gracefully to avoid crashes during the testing phase on zyBooks. This meticulous testing ensures that your file

handling methods operate reliably under various conditions.

Set up the H12CustomApp project

Download H12CustomApp.java and TestH12CustomApp.java and make sure they compile    and run in your IDE (Eclipse or IntelliJ). Put all the non-Java ¦les in a "data" folder within the    project folder and not the source folder. The data files are provided as examples for you. You may choose to read from some files or create ¦les that have a similar structure. Don't expect to use the data files when submitting to zyBooks. Within your test cases, create your own

data files, examples of how to do this are provided in TestH12CustomApp.

Example Data Sources found through Google searches for free public data

  Tableau

  InterviewQuery

  Kaggle

  MRC Psycholinguistic Database

  Project Gutenberg

write ¦le Examples

 writeItemDataAsASimpleReport(String filename, String title, String[][] values, String total). Example ¦le contents:


Simple Report

Item Quantity Price Total

--------------------------------------

Item 1 3 $10.00 $30.00

Item 2 2 $15.00 $30.00

Item 3 1 $20.00 $20.00

Total:                $80.00

writeItemDataAsACSVFile(String filename, String[][] values).

Example file contents:

Item,Quantity,Price,Total

Item 1,3,$10.00,$30.00

Item 2,2,$15.00,$30.00

Item 3,1,$20.00,$20.00

writeItemDataAsAnHTMLReport(String filename, String title, String [] itemNames, int[] quantities, double []prices, double [] totals) See zyBooks 11.5.4.

or your own with a similar level of complexity.

Submission Guidelines:

Before submitting your work, ensure you remove the example methods and example test cases from your submission. These examples are provided solely for instructional purposes and should not be included in your final assignment.

Grading Criteria:

Your submission will be evaluated based on the main method and overall formatting requirements as previous human graded assignments and in addition:

The read and write method header comments include a summary comment, a description of error handling, and may include special cases and specifi c examples.

@param(s) and @return are present in the method header comments and have helpful descriptions. No additional @param or @return are included.

The read file and write file methods have reasonable names, typically a verb or verb phrase, that describe what the method does.

The read and write file method parameter(s) and local variables are clearly named, typically a noun or noun phrase.

The read and write file method are non-trivial.

a trivial read file method would read the entire file contents into a single string or ArrayList.

a trivial write file method would write a string parameter or two to the file.

There must be 4 test cases, 2 for testing the read file method and 2 for testing the write file method.

having an English description that indicates what the test case is doing and is different from the others

demonstrating the list method is working correctly by using predetermined outcomes and appropriate comparisons (e.g. didn't use != r == for double, or String)





联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!