CS1101X: Programming Methodology

Download Report

Transcript CS1101X: Programming Methodology

CS1101X: Programming Methodology
http://www.comp.nus.edu.sg/~cs1101x/
CS1101X: Practical tests



The following practical tests are for your own practice.
They will not be graded.
On the CourseMarker, look for “labPT1” and “labPT2”.
For each problem, aim to spend at most 45 minutes to
complete the program:





Algorithm (15 minutes)
Codeing (10 minutes)
Testing (20 minutes)
Submit through CourseMarker and your leader may
discuss the problem with you in class.
Deadline for submission is 28 September 2007, Friday,
2359hr.
2
labPT1: Candles.java





Peter has n candles. He burns them one at a
time and carefully collects all unburnt residual
wax. Out of the residual wax of exactly k > 1
candles, he can roll out a new candle.
How many candles can Peter burn?
The input contains two integers giving the
values of n and k.
The output should consist of just one integer
giving the maximum number of candles that
Peter can burn.
Write a modular program. There should be a
method solve(int, int) .
3
labPT1: Candles.java

Examples:
 Enter
n and k: 5 3
No. of candles burned = 7
 Enter
n and k: 100 10
No. of candles burned = 111
 Enter
n and k: 15 10
No. of candles burned = 16
4
labPT1: Candles.java
Sample run:
Enter n and k: 5 3
Number of candles burned = 7
New
New
5
labPT2: Factors.java
 Given a non-zero integer value, find its
prime factor products.


Examples:

Enter value: 123
123 = 1 * 3 * 41

Enter value: 198
198 = 1 * 2 * 3 * 3 * 11

Enter value: -60
-60 = -1 * 2 * 2 * 3 * 5
Write a modular program. There should be a
method factorise(int) .
6