CSE 142, Summer 2020: General Style Deductions

Students in CSE142 are expected to demonstrate good programming style in their homework solutions. Every homework assignment will describe specific style requirements and expectations that students should keep in mind when writing their solutions. This page lists general style issues that are likely to be relevant to multiple assignments. This list includes common style mistakes but does not list every possible style mistake.

TAs provide feedback on graded homework assignments and often give a "-0" warning to indicate a style issue that is not being penalized but might be in a future assignment. The list below indicates general style issues that will not be graded as "-0". Homework assignments are listed in reverse order because once a style issue is included for one homework, it is included for all future homeworks. The list is not meant to be exhaustive, although it includes the most common style issues. Students should as their TA to explain any of these style categories that are not clear.


  • Assignment 8: Critters
    • control structure issues:
      • bad use of if/else (e.g., empty branch, unnecessary tests, redundant branches that can be combined with logical or)
    • class design issues:
      • initializing non-final data fields outside of a constructor
      • non-private data fields
  • Assignment 7: Personality
    • method issues:
      • unnecessary return from a method
    • data structure issues:
      • extra data structures that aren't necessary
      • bad usage of arrays (e.g., funky/incorrect indexing/usage)
  • Assignment 6: YazInterpreter
    • no new style issues
  • Assignment 5: Guessing Game
    • control structure issues:
      • including code in a loop that should be executed once either before or after the loop
    • method issues:
      • trivial methods
    • miscellaneous issues:
      • unnecessarily inefficient code (e.g., constructing a new object on every iteration of a loop when it could have been constructed once before the loop or including an unnecessary test in a conditional)
      • using \t instead of individual spaces to align output
  • Assignment 4: Budgeter
    • commenting issues:
      • method header does not describe the action/behavior of the method
      • method header does not describe the purpose of each parameter or does not describe the meaning of the return value of a non-void method
    • readability issues:
      • lines over 100 characters
      • nondescriptive variable names
    • control structure issues:
      • using incorrect if/else structure
      • failing to factor out redundant code in if/else structures
    • method issues:
      • do-all methods (i.e. methods that contain most or all of the work that should be done in main)
    • miscellaneous issues:
      • incorrect use of type (e.g., double instead of int, int instead of boolean, String instead of char for a value known to be exactly one character)
      • using \n with print/println or to produce more than one line of output with a single printf
      • not combining print/print or print/println statements when possible
      • using print/println/printf with the empty string ("")
      • constructing more than one Scanner for console input
  • Assignment 3: Cafe Wall
    • readability errors:
      • not following Java naming conventions (e.g., not using camel case, not using uppercase letters and word-separating underscores for constants)
      • inconsistent or nonexistent spacing within expressions (we suggest one space on either side of an operator)
      • not including a blank line between methods
    • method errors:
      • unused parameters or passing a constant as a parameter
  • Assignment 2: Space Needle
    • readability errors:
      • method header missing or does not adequately describe what the method does
      • bad indentation
      • lines over 100 characters
    • control structure errors:
      • bad use of loops (e.g., 1 to 1 loops, including an unnecessary check before a loop that repeats the loop test)
    • method errors:
      • nondescriptive method names
    • class design errors:
      • incorrect constant declaration (e.g., not public, not final, not static)
  • Assignment 1: Song
    • commenting errors:
      • class header missing or doesn't describe both student and program
    • readability errors:
      • no indentation
    • miscellaneous errors:
      • use of advanced material or forbidden constructs (\n and System.out.print are not allowed for homework 1)

In general, once a class has been discussed, it is available for use by students. For example, once the String class is introduced, you may assume that you can call any of the available String methods in future homework assignments without asking permission. Student should realize, however, that saying that you are not forbidden from using a certain construct is not the same thing as saying that it is a good idea to use a certain construct. We don't give advice to students about which constructs to use. You have to use your best judgment to decide and you might lose style points if you make a poor choice. In addition, there are some constructs that you are not allowed to use, as described in the next paragraph.

Java has grown to be a complex language with many features. We don't have time to teach all of these features in CSE142. We have a general rule that students should not use "advanced" material that we have not covered in class. In addition, we have identified several Java features that we do not want students to use. It is not bad style to use these features, but we want to have a level playing field for all students. For any one of these features, we prefer that either everyone in the class knows about it and can use it or nobody is allowed to use it. The following features should not be used in CSE142 homework or exam solutions:

  • break, continue, return from a void method
  • try/catch, annotations
  • the var keyword
  • Java 8 features (e.g., lambdas, streams, method references)
  • toArray, clone
  • StringBuilder, StringBuffer, StringJoiner, StringTokenizer, and String methods toCharArray, join, matches
  • Arrays.asList, Arrays.copyOf, Arrays.copyOfRange, Arrays.sort
  • Collections.copy, Collections.sort
  • package declarations
  • System.console()

Many students find themselves wondering, "What is that feature you are describing?" If you don't recognize it, then you're unlikely to use it, so the best answer is, "Something that we have decided not to teach you in this class so that we will be able to focus on the really important concepts you need to learn."