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 https://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: https://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. https://josephus.hsutx.edu/classes/p1/homework/hw02. Concepts: Simple input and output.

  2. https://josephus.hsutx.edu/classes/p1/homework/hw03. 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. https://josephus.hsutx.edu/classes/p1/homework/hw04. 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. https://josephus.hsutx.edu/classes/p1/homework/hw05. 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. https://josephus.hsutx.edu/classes/p1/homework/hw06. 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. https://josephus.hsutx.edu/classes/p1/homework/hw07. Concepts: Boolean expressions.

  7. https://josephus.hsutx.edu/classes/p1/homework/hw08. 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. https://josephus.hsutx.edu/classes/p1/homework/hw09. Concepts: Loop a fixed number of times.

  9. https://josephus.hsutx.edu/classes/p1/homework/hw10. 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. https://josephus.hsutx.edu/classes/p1/homework/hw11. Concepts: More loop practice including a loop that uses as sentinel value as a marker at the end of a series of inputs.

  11. https://josephus.hsutx.edu/classes/p1/homework/hw12. Concepts: How Scanner works.

  12. https://josephus.hsutx.edu/classes/p1/homework/hw13. Concepts: Methods and parameters.

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

  14. https://josephus.hsutx.edu/classes/p1/homework/hw15. 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. https://josephus.hsutx.edu/classes/p1/homework/hw16. Concepts: Arrays.

  16. https://josephus.hsutx.edu/classes/p1/homework/hw17. Concepts: Working with arrays (and methods).

  17. https://josephus.hsutx.edu/classes/p1/homework/hw18. 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. https://josephus.hsutx.edu/classes/p1/homework/hw19. Concepts: Using arrays, loops, if statements, input/output, etc.
  2. https://josephus.hsutx.edu/classes/p1/homework/hw20. Concepts: Extending a game from 2-player to multi-player.
  3. https://josephus.hsutx.edu/classes/p1/homework/hw21. Concepts: Using simple, non-OOP classes.

tsergeant@hsutx.edu