How to Get Ready for P2!
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:
- A command sheet for
P1. For
information about command sheets and why we use them visit
https://josephus.hsutx.edu/classes/all/commandsheets/.
- A command sheet for P2.
- 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.
As you work these problems be sure to use this technique:
- Start with a bare-bones, but working program (e.g., a "hello world"
program).
- 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.
- 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.
- 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.
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.
- https://josephus.hsutx.edu/classes/p1/homework/hw02.
Concepts: Simple input and output.
- 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.
- 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.
- 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.
- 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.
- https://josephus.hsutx.edu/classes/p1/homework/hw07.
Concepts: Boolean expressions.
- 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.
- https://josephus.hsutx.edu/classes/p1/homework/hw09.
Concepts: Loop a fixed number of times.
- 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.
- 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.
- https://josephus.hsutx.edu/classes/p1/homework/hw12.
Concepts: How Scanner works.
- https://josephus.hsutx.edu/classes/p1/homework/hw13.
Concepts: Methods and parameters.
- 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.
- 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.
- https://josephus.hsutx.edu/classes/p1/homework/hw16.
Concepts: Arrays.
- https://josephus.hsutx.edu/classes/p1/homework/hw17.
Concepts: Working with arrays (and methods).
- 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.
The remaining exercises are quite a bit more difficult and provide multiple
approaches to the same basic dice game:
- https://josephus.hsutx.edu/classes/p1/homework/hw19.
Concepts: Using arrays, loops, if statements, input/output, etc.
- https://josephus.hsutx.edu/classes/p1/homework/hw20.
Concepts: Extending a game from 2-player to multi-player.
- https://josephus.hsutx.edu/classes/p1/homework/hw21.
Concepts: Using simple, non-OOP classes.
tsergeant@hsutx.edu