Final - Thursday, Aug 11 19:00-22:00 at EX100
- This final is worth 40% of your final mark. You should earn at least 40% of the final marks to pass the course.
- If you earn less than 40% on the final, your grade for the course will be set to 47%.
- Material: everything covered in class, from week 1 to week 12.
- The test cover page can be seen here.
Various exercises
- Regular Expressions
- Unit Testing
- Consider the WellFormed java class from our lectures. Write a Junit test class for it.
- Design Patterns
- Iterator Pattern: using our Node class, write an implementation of Binary Search Trees.
Using different traversal orders, write three different iterators for it. - Strategy pattern: consider a bunch of sales objects with the following structure:
Barcode -> a 13 digits string
For example, a sales object might look like this:
Description -> a product description string
Region -> a three alpha code (usually three first characters of postal codes)
Period -> 6 digit number, first 2 digits indicate month, last 4 digits indicate year
Amount -> amount of sales for the product identified by the barcode, for the indicated period and the indicated region.
1234567890123
This object indicates the sales of strawberries for the region M9B for tyhe month of July 2016 were 1234$
Strawberry
M9B
072016
1234
We would like to produce various sales reports, based on different selection criteria (say all straberry sales for first 6 months of 2016 for all Canadian regions M9B and M5A) and sorted using various sorting criteria (ex: sort by period) and use different sorting algorithms (bubble, merge, etc).
Solve the reporting problem using the strategy pattern.
Midterm - Thursday, June 23 19:00-21:00
- Special Office Hours : This Wednesday, June 22 10:00-12:00 BA3201
- This midterm test is worth 17% of your final mark.
- Test length: 110 min.
- Test type: written.
- Material: Everything covered from May 12 to Jun 16 (lectures, labs exercises).
- No aid of any kind allowed.
- The test cover page can be seen here.
- The test will take place Thursday, June 23 19:00-21:00.
- Please do write the test to the room assigned by the school (click here)
- For your convenience, same info has been reproduced below:
Last Name | Test Room |
---|---|
A-Lin | BA2145 |
Liu-W | BA2155 |
X-Z | BA2159 |
Some practice exercises.
- 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. -
Consider the following code:
public class JavaChicken {
Identify the block suspectible to excpetions and use try/catch to actually catch and unwind the exception. What type of exception are you experiencing?
public void chicken() {
egg();
}
public void egg() {
chicken();
}
}
public class WhyDidChickenCrossTheRoad {
public static void main(String[] args) {
JavaChicken jc = new JavaChicken();
jc.chicken();
}
}
-
Consider the following classes: Customer, Address and TestImmutables.
The result of
TestImmutables
is shown below:
1 Ilir
Please note all attributes of class
40 St George St
Toronto
ON
M9B5W3
1 Ilir
123 Main st
Toronto
ON
M9B5W3
Customer
areprivate
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. -
Write te code for a class
Invoice
that has the following variables:
int serialNum
The
String customer
double amount
serialNum
should start from 10, progress by 5, and once we generate the invoice with serial number 100, we need to reset theserialNum
back to 10. Implement the required logic in the constructor. Create a test class to try your code. -
Create a Java interface called
Merchandise
that contains a single method calledtotalValue
. This method takes no arguments and returns adouble
. 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 classStore
that has a single instance variableinventory
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.