CSC207H1 (Summer 2016): Software Design

Final - Thursday, Aug 11 19:00-22:00 at EX100

Various exercises

Midterm - Thursday, June 23 19:00-21:00

Last Name Test Room
A-Lin BA2145
Liu-W BA2155
X-Z BA2159

Some practice exercises.

  1. Write another implementation of UnboundedStackInterface using arrays rather than Node class. That is,complete the following code:
    public class ArrayStack<T> implements UnboundedStackInterface<T> {
    protected int top;
    protected T[] container;
    protected int capacity;

    public ArrayStack(int capacity) {
    //your implementation of the constructor goes here

    }

    // etc - implement the rest of the methods

    }

    In addition, write a simple test program that instantiates an ArrayStack<String> variable, pushes and pops a number of strings in it.
  2. Consider the following code:
    public class JavaChicken {
       public void chicken() {
         egg();
       }
       public void egg() {
         chicken();
       }
    }
    public class WhyDidChickenCrossTheRoad {
      public static void main(String[] args) {
         JavaChicken jc = new JavaChicken();
         jc.chicken();
       }
    }
    Identify the block suspectible to excpetions and use try/catch to actually catch and unwind the exception. What type of exception are you experiencing?
  3. Consider the following classes: Customer, Address and TestImmutables. The result of TestImmutables is shown below:
    1 Ilir
    40 St George St
    Toronto
    ON
    M9B5W3

    1 Ilir
    123 Main st
    Toronto
    ON
    M9B5W3
    Please note all attributes of class Customer are private and the class does not have setters. However we managed to change the customer object as you can see from the results above. Please fix the code so the customer object becomes immutable.
  4. Write te code for a class Invoice that has the following variables:
    int serialNum
    String customer
    double amount
    The serialNum should start from 10, progress by 5, and once we generate the invoice with serial number 100, we need to reset the serialNum back to 10. Implement the required logic in the constructor. Create a test class to try your code.
  5. Create a Java interface called Merchandise that contains a single method called totalValue. This method takes no arguments and returns a double. Write two implementations:
    Book that contains the following instance variables: title (String), price (double), quantity (int).
    Food that contains the following instance variables: description (String), pricePerUnit (double), unit (String), quantity (double). Create a class Store that has a single instance variable inventory of type to be determined by you, capable of holding both kinds of merchandises (books and food items). Create a test program that processes the store inventory and computes the total value of the merchandise owned by the store.

Some past tests to practice: