How to Get Ready for P2!

Overview

One of the challenges of becoming a proficient programmer is the fact that many programming concepts are cumulative in nature. The Program Design and Development 2 (P2) course is, of course, built to followed the P1 course. If, however, there are concepts from the first course that are not solid for you it will make this course difficult.

I have put together several resources for the purpose of helping to ensure you have everything you need to be successful in P2:

  1. A command sheet for P1. For information about command sheets and why we use them visit http://josephus.hsutx.edu/classes/all/commandsheets/.
  2. A command sheet for P2.
  3. A series of practice exercises outlined below. The theory is that if you are able to independently complete these exercises using the techniques described then you should be ready to do well in P2.

Technique Matters

As you work these problems be sure to use this technique:
  1. Start with a bare-bones, but working program (e.g., a "hello world" program).

  2. As much as possible rely on your memory, the command sheet, the official Java documentation, and previous exercises. If you find yourself needing other resources then you likely need to spend more time working on the concept at hand or on previous concepts.

  3. Write only one or two lines of code and then compile and test. Before running the program you should always have in mind a prediction of what the program will do. Be observant.

  4. If you are stuck and need to get help, limit your questions to this type of question: "I thought these lines of code should to X, but instead they are doing Y. Explain what that is the case." REMEMBER: The goal is not to finish these exercises. Instead the goal is to learn what the exercises are trying to teach you.

Exercises

If any of the exercises refers to files at the course website you will be able to find those files at: http://josephus.hsutx.edu/classes/p1/source/. Also, you can ignore the instructions that specify how you turn things in. Remember, these exercises are not required ... they are simply for the purpose of helping you verify you are ready for P2.

  1. http://josephus.hsutx.edu/classes/p1/homework/node2.php. Concepts: Simple input and output.

  2. http://josephus.hsutx.edu/classes/p1/homework/node3.php. Concepts: Floating point arithmetic. NOTE: If you are going to use the weights in our syllabus you'd modify the program to input 3 exam scores, a homework score, and a lab day score.

  3. http://josephus.hsutx.edu/classes/p1/homework/node4.php. Concepts: Integer arithmetic, modulus/remainder. HINT: If the user enters 64 cents then you can do 64/25 (which is 2) to determine the number of quarters and then 64%25 (which is 14) to tell you how much is left after taking out all of the quarters. Etc.

  4. http://josephus.hsutx.edu/classes/p1/homework/node5.php. Concepts: If statements. NOTE: Pay attention to < vs <= to make sure you cover the ranges properly. Also, there are a variety of ways to do this. Consider nesting if statements in else blocks to simplify your solution.

  5. http://josephus.hsutx.edu/classes/p1/homework/node6.php. Concepts: Calculations and if-statements. There are lots of ways to get the formulas wrong so be sure you can solve the problem by hand correctly. Have a friend or teacher check your work.

  6. http://josephus.hsutx.edu/classes/p1/homework/node7.php. Concepts: Boolean expressions.

  7. http://josephus.hsutx.edu/classes/p1/homework/node8.php. Concepts: Loop for user validation. NOTE: The calculations and output should not be inside of the loop. The loop's only job is to obtain valid input. Once the input is obtained you should exit the loop and proceed to the next part of the program.

  8. http://josephus.hsutx.edu/classes/p1/homework/node9.php. Concepts: Loop a fixed number of times.

  9. http://josephus.hsutx.edu/classes/p1/homework/node10.php. Concepts: Nested loops. NOTE: This program has lots of small places you might get off the rails. This might be a good time to review the suggested technique and make sure you are following it.

  10. http://josephus.hsutx.edu/classes/p1/homework/node11.php. Concepts: More loop practice including a loop that uses as sentinel value as a marker at the end of a series of inputs.

  11. http://josephus.hsutx.edu/classes/p1/homework/node12.php. Concepts: How Scanner works.

  12. http://josephus.hsutx.edu/classes/p1/homework/node13.php. Concepts: Methods and parameters.

  13. http://josephus.hsutx.edu/classes/p1/homework/node14.php. Concepts: Practice with methods. This is a rewrite of an earlier exercise but organizes the solution into methods.

  14. http://josephus.hsutx.edu/classes/p1/homework/node15.php. Concepts: Practice with methods. This is yet another rewrite of an earlier exercise (but organizes the solution into methods). It also asks you to use try-catch to allow entering a number without crashing the program. So, you'll want to write a method called getNumber that takes three parameters as follows:
    public static double getNumber(String prompt, double low, double high)
    {
       Scanner kb= new Scanner(System.in);
       double val= 0.0;
       try {
          System.out.println(prompt);
          val= kb.nextDouble();
          System.out.println("You entered "+val);
       }
       catch (Exception e) {
          System.out.println("Wrong number");
       }
       return val;
    }
    
    Your completed method will do quite a bit more than this, but this provides a starting point.

  15. http://josephus.hsutx.edu/classes/p1/homework/node16.php. Concepts: Arrays.

  16. http://josephus.hsutx.edu/classes/p1/homework/node17.php. Concepts: Working with arrays (and methods).

  17. http://josephus.hsutx.edu/classes/p1/homework/node18.php. Concepts: Top-down design and pseudocode. If you haven't written pseudocode before think of it a a simple programming language that doesn't concern itself with picky syntax rules.

Advanced Exercises

The remaining exercises are quite a bit more difficult and provide multiple approaches to the same basic dice game:
  1. http://josephus.hsutx.edu/classes/p1/homework/node19.php. Concepts: Using arrays, loops, if statements, input/output, etc.
  2. http://josephus.hsutx.edu/classes/p1/homework/node20.php. Concepts: Extending a game from 2-player to multi-player.
  3. http://josephus.hsutx.edu/classes/p1/homework/node21.php. Concepts: Using simple, non-OOP classes.

tsergeant@hsutx.edu

Quick Links