Pledged lab quiz
- This quiz is timed - you have 90 minutes to complete it.
- The only "good programming practice" that is required for
this lab is to include your name and e-mail ID in the header
comments. You are welcome to include more, but make sure you
get the programs working first, as the quiz is timed.
- The quiz is open textbook. You may NOT use previous assignments.
- The activities of this week are not to be
discussed outside of lab. You are to produce two programs, as described
below. Templates for the files are
available:
- Multiplication.java (right click on the
link, select "save as...", then save the file to your home directory)
- OrderedPair.java (right click on the
link, select "save as...", then save the file to your home directory)
Advice
- Remember neither the lab assistants nor other students may
help you design, write, or debug the programs. If you are
having a problem getting JCreator to work right (which does NOT
mean a compilation error), or an error with the submissions,
then you may ask a TA.
- To maximize your points, make sure your programs compile
successfully.
- If towards the end things are not going as well as you
would want (i.e., the program does not compile), it might be
best to try commenting out errant statements (i.e., put a
// in front of them)
- Focus on getting the first program to work properly before moving onto
the second. Both programs are worth equal credit, and the first one is
easier.
- If you run out of time, submit what you have -- there will be partial
credit for this quiz. Also remember that you can submit a file as many
times as you want -- only the most recent submission is graded. So
once you have it working, submit what you have.
Program 1: Multiplication
- Complete and
submit program
Multiplication.java (right click on the
link, select "save as...", then save the file to your home directory) that
does the following:
- Prompts the user for an integer number n
- The program will then repeat the following:
- Multiply n by itself, and print out the result. Thus, each
time the loop iterates, n will become the square of what it was
previously.
- Prompt the user to see if the program should continue executing the loop
- If the user enters 2 for n, the program will print out 4, 16,
256, 65536, etc.
- The program should use a do-while loop. You should use a long
for
n -- you can assume that we will not run your program long enough for
n to go beyond the limit for a long.
- For the user prompts, you can just use the nextBoolean() method from the
Scanner class. The user should enter true or false if s/he wants the
loop to continue or not.
Program 2: Ordered Pairs
- Complete and
submit program
OrderedPair.java (right click on the
link, select "save as...", then save the file to your home directory) that
does the following:
- Prompts the user for an integer number n
- Prints out all ordered pairs in the range from (1,1) to (n,n)
where the second number is evenly divisible by the first number.
However, you should not print out ordered pairs where both numbers are the
same (i.e. (1,1), (3,3), etc.). For example, if n is 4, then
the program would print out (1,2), (1,3), (1,4), (2,4). We are only
dealing with ints for the parts of the ordered pair.
Submission
Submit Multiplication.java and OrderedPair.java
here.