CSC108 Tutorial Outline - Week 2
May 24, 2001

Week 2 Outline

Exercises

  1. Write a class that models a simple calculator. This calculator stores 2 integer numbers and performs various mathematical operations on them. It has operations to add, multiply, divide, and subtract the two numbers that are stored in the calculator. Include a constructor to initialize the two numbers. Also include methods to change the two numbers to different values.

  2. Write a class that manages a collection of CDs. The class should be able to keep track of the number of CDs in the collection, as well as the total cost of all CDs in the collection. It should have a constructor that initializes the number of CDs and the cost. It should have an 'addCds' method that adds a certain number of CDs that have a certain cost. It should also have a 'print' method that prints the number of CDs, total cost, and average cost per CD in the collection. This print method should call on a private 'average' method to calculate the average cost per CD in the collection.