60 likes | 73 Views
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”.
E N D
CS1101X: Programming Methodologyhttp://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.
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 methodsolve(int, int) .
labPT1: Candles.java • Examples: • Enter n and k: 5 3No. of candles burned = 7 • Enter n and k: 100 10No. of candles burned = 111 • Enter n and k: 15 10No. of candles burned = 16
New New labPT1: Candles.java Sample run: Enter n and k: 5 3 Number of candles burned = 7
labPT2: Factors.java • Given a non-zero integer value, find its prime factor products. • Examples: • Enter value: 123123 = 1 * 3 * 41 • Enter value: 198198 = 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) .