CS 146 (Sections 3 and 4): Data Structures and Algorithms, Spring 2008

Programming Assignment Due 5/13 by classtime.

Consider the 3n + 1 problem as posted at the programming challenges website. This is an easy problem to program a correct answer to, it is fitting that we only have one week for it.

All input is to be taken from System.in. If you need, you may use the "How to submit in JAVA" template from the programming challenges website.

Note: both the input and output format are precisely specified for the problem. If you assume a different input format, your program may or may not work correctly. If you give a different output, your solution will be rejected.

You should try to make your program run as fast as possible. If anybody has a program which runs no more than twice as slow as my program, they will get extra credit.

Note, the Programming Challenges website incorrectly grades this problem! So, if you want to check if your answer is correct or not, you cannot do so on this website, which will incorrectly grade correct Java submissions for this problem as incorrect (and incorrectly grade some incorrect C submissions as correct!). (If you want, you can get a proper grader for the problem at the UVa judge, linked to at the Programming Challenges home page.)

  1. I will run javadoc on your program, so it should be fully documented, including documentation for private methods.
  2. I will also run the style checker on your program, so follow department style guidelines.
  3. You should compile using the Java 5 option. If you use any of the new Java 6 stuff, I will not be able to compile your code. (Sorry.)
  4. Your package name should be edu.sjsu.cs.cs146.
  5. Your file should be named threeNPlus1.java. Your class should be named threeNPlus1, and it should have a main method which will run as requested in the assignment. All other methods are up to you, but should be documented (including documentation of private methods).
  6. Do not assume any other input, or give any other output, other than what is specified above. My automated tester is not very forgiving.
  7. Email your file to me, with the following subject line, replacing the name fields: CS146Spring08: Program 5 Lastname Firstname
  8. The email should empty, other than an attached file of source code, in a single text file named threeNPlus1.java.