Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Programming Assignment FAQ     Programming Assignment FAQ For course policies regarding submission, lateness, grading, and collaboration, see the Assignments page. Expand All Collapse All Submission Can I submit an assignment via email, hardcopy, or Snapchat? No, you must submit all assignments via TigerFile. How do I successfully submit an assignment? Here is a short list of things to do: Include the appropriate header at the beginning of every file that you submit. Remove any extraneous debugging statements from your code. Upload all of the required files. Filenames are case-sensitive. Be sure to submit the most up-to-date version of your code. After testing on your computer, click the Check Submitted Files button to receive feedback from the autograder. How do I submit an assignment after the deadline? You must mark the checkbox in TigerFile that indicates that your work is incomplete. (Otherwise we will grade whatever is there at the time of grading.) When you are ready to have the assignment graded, unmark the checkbox. There is no need to mark (and unmark) the checkbox if you are submitting before the deadline. On assignments that allow partnering, how do I submit? First, you must form a group by clicking the green Create Group button in TigerFile. You must do this even if you are working alone—a group of one. If you are working with a partner, add your partner as a group member. Your partner will receive an email with a link to confirm the partnership. Once you have created a group, any group member may submit. Can I fix my code and resubmit? Yes. There is no penalty for resubmitting files prior to the deadline. There is, however, a limit on the number of times you can receive autograder feedback using the Check Submitted Files button. Check Submitted Files What exactly does the Check Submitted Files button in TigerFile do? It compiles your code and checks that it conforms to the assignment specifications by running a battery of correctness tests. On some assignments, it also performs memory and timing tests. It also runs three static code analysis tools—Spotbugs, PMD, and Checkstyle—that automatically identify common bug patterns and style issues. When I submit, TigerFile tells me that I have only 2 checks remaining. Why? In COS 226, there is a limit on the number of times that you may click the Check Submitted Files to receive feedback. This policy is intended to enable timely and constructive feedback on your work while you are programming (but discourage you from relying on the autograder as your exclusive debugging tool). Please review the submission policy. Must I submit all of the required files to receive feedback? No. The autograder will give feedback on whichever files you submit, provided that they compile. For example, you need not submit PercolationStats.java to receive feedback on Percolation.java, but you must submit Percolation.java to receive feedback on PercolationStats.java. What should the output look like, if there are no errors or warnings? Here is an example. If you don’t understand an error message, ask on Ed. I receive various compiler errors and warnings. What does this mean? Your programs should compile cleanly, with no errors or warnings. There is one exception to this rule (on Assignment 2), where a “generic-array creation” warning is permitted. I receive various “FAILED” messages in the correctness, timing, or memory tests. What does this mean? Your program does not meet the assignment specifications on the tested inputs. Failing any of these tests will likely lead to a deduction. (Passing all of these tests is a good sign, but does not guarantee that your program is 100% correct; we run additional tests when grading.) I receive various Spotbugs, PMD, or Checkstyle warnings. What does this mean? Spotbugs is a program that looks for common bug patterns in your code. You should treat anything it reports as an error (though, occasionally there are false positives). The autograder uses Spotbugs 3.1.3 and the configuration file spotbugs.xml. It also uses the fb-contrib plugin, which detects additional bug patterns. PMD is a program that looks for common bug patterns in your code. The autograder uses PMD 6.3.0 and the configuration file pmd.xml. Checkstyle is a program that looks for common style issues in your program. The appearance of a warning message does not necessarily lead to a deduction (and, in some cases, it does not even indicate an error). You should pay particular attention to the custom checks, which are specialized to each program. The autograder uses Checkstyle 8.11, the configuration file checkstyle-cos226.xml, and the suppressions file checkstyle-suppressions.xml. When I submit, the autograder reports the error “Process took too long and was killed (output may be truncated).” What could cause this? Please report on Ed. This usually means that the autograder could not complete in the allocated amount of time. The most common cause is a serious performance bug. Another possibility is that your program produces an enormous amount of output, perhaps because you left in a debugging statement. It counts against your limit of 10 checks. When I click the Check Submitted Files button, I receive a { failed to fetch, NetworkError when attempting to fetch resources } message. How can I fix that? This is your browser’s way of telling you that you are not connected to the Internet. I clicked the Check Submitted Files button but { my browser crashed, my computer dropped the network connection, I closed the browser tab containing the results, ... } Can I get the check back? No. However, if you were charged a check, you should be able to access the results by clicking the Latest Check Submitted Files link. This feature does not currently work on Safari. Testing Do I have to test my code? Yes. For some assignments, you will be given very clear instructions on how to implement the test client. In others, you will be asked to implement your own test client that tests the methods you have implemented. Although the autograder tests your code, you are expected to test your code before you use the autograder. For grading purposes, your test client will satisfy the requirements if it calls every public method in your code at least once in a meaningful way (by printing the return value, for example). For genuinely testing your code, you will often need to do more than that. What should my program do if the user specifies an invalid input? In general, professional programmers must write code to carefully check and validate any user input. In this course, however, you may assume that user specifies valid input. For example, you may assume that the command-line arguments to PercolationStats are two integers (and not, say, a string and a double). Style How should I compose my code? Here are some recommended style guidelines. Below are some that are particularly important (and for which you risk losing points if you ignore). Use meaningful variable names. Use straightforward logic and control flow. Declare variables to minimize scope. For example, don’t declare a variable to be an instance variable if it is used only as a local variable in one method. All instance variables must be private. Avoid unexplained magic numbers, especially ones that are used more than once. Avoid repetitive code. How do I avoid repetitive code? Whenever you see yourself repeating code, take it as a red flag and consider refactoring. The following are two examples: Example 1: if (isTrue) doA(); doB(); doC(); doD(); } else { doB(); doC(); doD(); } This code can be written as: if (isTrue) doA(); doB(); doC(); doB(); Example 2: doA(); doB(); doC(); doD(); while (isTrue) { doA(); doB(); doC(); doD(); } This code can be written as: do { doA(); doB(); doC(); doD(); } while (isTrue); You can also declare a function doAll() (for e.g.) that calls doA(), doB(), doC() and use it as follows: doAll(); while (isTrue) doAll(); Always consider using functions to encapsulate repeated code. Avoiding repeated code using functions enhances readability, simplifies debugging and localizes future changes to a single place. How should I format and comment my code? Below are some that are particularly important (and for which you risk losing points if you ignore). Fill in the header at the beginning of each Java file with your name, NetID, precept, and a description of the program. Include a comment describing every method and class (whether public or private). Include a comment describing every instance variable (including those for nested classes). Use whitespace to make your program easier to read. For example, indent consistently, using 3 or 4 spaces for each indentation level. Configure your editor to use spaces, not tabs. Do not exceed 80 characters per line. As a guide, the last line in the header is exactly 80 characters. This rule also applies to the readme.txt file. Does the absence of Spotbugs, PMD, and Checkstyle errors guarantee that I will not lose points for style? Fixing Spotbugs, PMD, and Checkstyle errors is necessary but not sufficient. The following are examples of important style or design issues that are not flagged by any of these tools: Repetitive code. Meaningless variable names. Inconsistently indented code. Convoluted logic or flow control. Excessive code that is commented out. Insufficient commenting, including complicated algorithms that are not explained clearly by their comments. Header What is the format of the header for Java files? /* ***************************************************************************** * Name: Alan Turing * NetID: aturing * Precept: P00 * * Partner Name: N/A * Partner NetID: N/A * Partner Precept: N/A * * Description: Model an n-by-n percolation system using the union-find * data structure. **************************************************************************** */ This header must appear at the very beginning of each Java file and follow the formatting above (e.g., the first line consists of the forward slash character, followed by an asterisk, then a space, then 77 asterisks). Note the space on the first line; this makes it a block comment, not a Javadoc comment. You may add additional information after the description section of the header (such as instructions for compiling, executing, and listing any dependencies). What is the format of the header for the readme.txt file? /* ***************************************************************************** * Name: Alan Turing * NetID: aturing * Precept: P00 * * Partner Name: Ada Lovelace * Partner NetID: alovelace * Partner Precept: P00 **************************************************************************** */ It is identical to the header for Java files, except that no description is required. May I use non-ASCII characters in the header? Yes, provided you use Unicode and UTF-8 encoding. Java I haven’t programmed in Java in a while. How much Java do I need to remember? For a review of our Java programming model (including our input and output libraries), read Sections 1.1 and 1.2 of Algorithms, 4th Edition. Which Java programming environment should I use? We recommend our customized IntelliJ programming environment, for Mac OS X, Windows, and Linux. If you followed our instructions, then everything should be configured and ready to go. If you prefer to use another environment (such as Eclipse or Sublime), that’s fine—be sure that you can use command-line arguments; read from standard input, redirect standard input and output; and add algs4.jar to your Java classpath. Can I use various Java libraries in this assignment, such as Arrays.sort(), java.util.LinkedList, java.util.ArrayList, java.util.TreeMap, and java.util.HashMap? In general, do not use any Java library until we have implemented equivalent versions in lecture. Once we have introduced them in lecture, you are free to use either the Java library version or our equivalent. You are permitted to use common functions in java.lang such as Math.sqrt() and Integer.parseInt(). Memory Analysis What’s the difference between tilde notation and big Theta notation? Both tilde notation and big Theta notation discard lower-order terms. Tilde notation includes the coefficient of the leading term; big Theta notation discards the coefficient of the leading term. You risk losing points for including lower-order terms, failing to include the leading coefficient with tilde notation, and including the leading coefficient with big Theta notation. How do I calculate the memory used by an object? Use the memory model described in the textbook, lecture slides, and booksite. If an object references other objects, should I count the memory of the referenced objects? Unless instructed to do otherwise, you should count all memory allocated by the data type itself but not memory allocated by the client of the data type. For example, if a queue is declared as Queue and is implemented as a linked list of nodes, you should count the memory of the node objects (including references to the String objects) but not the memory of the String objects themselves. The string objects in the queue are allocated by the client of the queue, whereas the node objects are allocated by the queue itself. Timing Analysis When I’m told to find a formula using tilde notation for the running time, can I assume that the running time obeys a power law (e.g. a nb)? Yes. If you really want to go above and beyond, you can try to use fancier fitting techniques, but please explain your methodology, as it’s very easy to make mistakes when trying to fit functions like n log n. I get an exponent of 2.1, but I’m expecting it to be 2. What should I put down as an answer? You should report the value as 2.1. Feel free to explain why you think it should be 2. Different data points are giving me different exponents! What do I do? It’s mostly correct to say that you should use the largest data point you can. Answers given with large data points will be considered correct. How many data points do I need to analyze the running time of my program? At a minimum, you should use 5. You risk losing points if you use fewer than 5 or if the data points that you use are too small (e.g., take only a fraction of a second). How do I make the data collection process less tedious? We recommend writing a program. For example, see DoublingRatio.java. Feel free to copy, paste, and modify this code. When I'm asked to give the running time of my program in seconds using tilde notation, can I derive the formula solely through mathematical analysis? No. You must perform computational experiments because the leading coefficient in the tilde notation depends on your machine. It’s good practice to also develop a mathematical model and check that the theoretical order of growth matches the one you observe in practice. Can I lose points for performance even if I pass all of the provided timing tests? Yes. The autograder in TigerFile reveals only some of the timing tests that we perform when grading your assignment.