This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
**Unformatted text preview: **ASSIGNMENT 2 Conditionals and Loops COMP-202B, Winter 2010, All Sections Due: Sunday, February 7, 2010 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all the general instructions and regulations for assignments. Graders have the discretion to deduct up to 10% of the value of this assignment for deviations from the general instructions and regulations. Part 1, Question 1: 0 points Part 1, Question 2: 0 points Part 2, Question 1: 15 points Part 2, Question 2: 25 points Part 2, Question 3: 25 points Part 2, Question 4: 35 points 100 points total Part 1 (0 points): Warm-up Do NOT submit this part, as it will not be graded. However, doing these exercises might help you to do the second part of the assignment, which will be graded. If you have difficulties with the questions of Part 1, then we suggest that you consult the TAs during their office hours; they can help you and work with you through the warm-up questions. Warm-up Question 1 (0 points) PS Books is a bookstore which not only sells books to individuals, but also sells school textbooks to the local school board. PS Books offers the following discount on orders which consist of multiple copies of the same textbook: • Less than 10 copies: Full price • Between 10 and 49 copies (inclusive): The price of each copy is reduced by 10% • 50 copies or more: The price of each copy is reduced by 20% Write a program which consists of a single class called TextbookCostCalculator . This class defines a main() method which asks the user to enter the unit cost of the textbook, as well as the number of copies being ordered. The program then calculates the total cost of the order, taking any applicable discounts into consideration. Once the program has calculated the total cost of the order, it displays this value to the screen along with an explanatory message. Your program MAY assume that the values entered by the user are of the correct type and that they are in the proper range; in other words, your program does not have to handle the cases where a value entered by the user is invalid (such as a negative number of textbook copies, or a negative textbook unit cost). Use an integer variable to store the number of copies being ordered, but a floating point variable ( float or, preferably, double ) to store the unit cost of the textbook. 1 Sample session: Enter the unit cost of the textbook: 33.50 Enter the number of textbooks you are buying: 25 The total cost of your textbook order is: $753.75 Warm-up Question 2 (0 points) Write a program which consists of a single class called PerfectNumberChecker . This class defines a main() method that asks the user to enter a positive integer n , and reads this number from the keyboard. The program then displays all integers which are factors of n (that is, all numbers which divide n without remainder). The program also reports whether n is a perfect number; a perfect number is an integer which is equal to the sum of all its factors, excluding itself). For example, 6 is a perfectis an integer which is equal to the sum of all its factors, excluding itself)....

View
Full Document