Homework Assignments

We will use the CS submit system for homework turn-in. Please follow the directions on homework requirements and the procedures on how to submit your homework electronically.

General Requirements for Homework Assignments

We will have about 10 homework assignments. Most homework will be programming assignments - writing small to medium-size Java programs to solve specific problems. Your submission should have the following general format:

  1. You should provide a README text file describe your submission files: your README should describe what problems you solve for the homework, what are the files in your submission; how to run your programs, what are the command lines, what are the input, what output will be generated; list any of your testing input and input files, and the sample results; describe your testing procedures and results;
  2. In your README file, it should have a section called "Report" written in plain English prose style. In the Report section, you should describe briefly what you have done in your homework, descriptions of your algorithms, any design and implementation work, and a summary of what you have learned.
  3. You should have the following honor pledge section written at the beginning of your README:
    ``On my honor, I abide by the University Honor Code and the submitted project is my own work.''
    Homework without the above honor pledge will not be graded.
  4. You should submit your README on your Wiki page. You may refer to the example README as template. Your README file will account for 10% of your grading.
  5. For programming assignments, you should submit your source code with proper comments. You should generate Javadoc documentation for your Java classes and submit the Javadoc files with your source code. You should develop proper testing cases for your program to test your code. Submit any of your test code and running results. You should describe how to run your code and related files in your README.  The directions to submit your programming assignments are:

DIRECTIONS FOR ONLINE HOMEWORK SUBMISSION

To submit your homework, do the following step by step:

1. login to your account on mercury.cs.uml.edu and create a new directory, say "myhw1":
mkdir myhw1

2. upload all your homework files in to the directory you created in Step 1, say "myhw1"

3. change directory to the higher level directory above your directory, for example:
cd myhw1
cd ..

4. type "submit cs204 hw1 myhw1", here: cs204 is the course account, "hw1" is the submission code for hw#1, use "hw2" for hw#2, etc).

5. now, submit command should report success or failure

6. send email to cs204 to confirm you have submitted your homework

If you have problems with submit, please email cs204 for help *before* the due date.

HW#1, DUE: Tuesday 2/12, 11:59PM

  • OOSDUJ 4.1, 4.4, 4.5, 5.1 Part (a) only

HW#2, DUE: Thursday 2/21, 11:59PM

  • MediaBook 3.11, 3.12, 3.19, 3.20, 11.22.
  • For the above problems, DO NOT modify Turtle.java class, instead, write your own subclass to implement the required features.
  • Draw UML class diagrams of your classes, including fields, methods.
  • Generate JavaDoc for your class, field and method definition.

HW#3, DUE: Thursday 2/28, 11:59PM

  • Modify the OO List code (AList, EmptyList, NEList) to add the following operations on list objects:
    1. Add the toString method to print list elements in order, for example, (3, 5, 55). The empty list should print as ().
    2. Add the method public AList copy() to return a copy of the list.
    3. Add the method public int getMax() to return the max number on the list.
    4. Add the method public int getNth (int n) to return the n-th elements of the list. Here n>=0, and 0 corresponds to the first element.
    5. Add the method public int lastElement() to return the last element of the list.
    6. Add the method public AList reverse() to return AList containing the same elements in reverse order. Your solution should be as efficient as possible in terms of memory consumption for the operation.
  • You should use the Singleton and other patterns as discussed in class. For the NEList methods, you should use delegation and define appropriate helper methods.
  • Write client class to test your methods. You should test both empty and non-empty cases.
  • For the above problems, you should draw UML class diagrams for your class and generate JavaDoc for your class, field and method definitions.
  • Write your documentation on Wiki page and discuss how the methods work in the report section.

HW#4 - OOList Visitor, DUE: Thursday 3/6, 11:59PM

  • Using visitor pattern to reimplement OOList operations required in HW#3 as visitor classes. The OOList code using visitor pattern can be found on the class wiki page.
  • You should not change either the List classes or the IListVisitor interface.
  • Your visitor classes should be singleton.
  • Write client class to test your classes.
  • Draw UML class diagrams and generate JavaDoc documentation.

HW#5 - Eclipse and JUnit, DUE: Thursday 4/3, 11:59PM

In this assignment, you will use Eclipse and JUnit to perform the following:

  • Create a new Eclipse project called OOList. Convert your HW#4 OOList visitor code (or you can start with the sample OO List code on Wiki Common: Week 5) to package oolist, ie., you should have oolist.AList, oolist.EmptyList, oolist.IListVisitor, etc.
  • In your oolist package, implement a new visitor class - Filter, which will take input integer n and return AList of integers that are smaller than n.
  • Write JUnit test class to test your Filter visitor. You should test all public filter methods. You need to decide and implement how to test equality of list objects. Describe your solution in your Wiki report.
  • Generate UML diagram and JavaDoc for your code
  • To submit your homework, you should make a zip file of your COMPLETE OOList project workspace - you can use the File->Export->Archive File menu command in Eclipse to export your project as zip file, then upload the zip file to mercury, and submit the zip file. Grading will be done by importing and running your complete project in Eclipse.

HW#6 - Exploring Scribbler, DUE: Tuesday 4/15, 11:59PM

In this assignment, you will study the Scribbler manual and Parallax documentation to experiment with the Scribbler robot, and investigate Scribbler programming model and tools. The findings of your investigation should be documented in your Wiki page. You need to do the following:

  • Read the Scribbler Start-Up Guide v1.0.pdf, BASIC Stamp Manual v2.1.pdf, What's a Microcontroller v2.2.pdf, to understand Scribbler hardware, PBASIC commands, and StampEditor IDE. The reference PDF files can be found on the Scribbler CD, which is also posted online - read the GoogleGroup message for URL link to online copy of Scribbler CD.
  • Find and describe Scribbler pin assignments for sensors, motors, etc, (total 16 pins) on your Wiki report.
  • Find and describe the programming model - what language and what compiler tools, to program Scribbler. Write simple example - source code and the steps to run the code on Scribbler.
  • Find and describe PBASIC commands for using the following:
    • Use variables, debugging with PC
    • Use LED
    • Use light sensor
    • Use speaker sound
    • Use motor

    your description for the above should include small sample code and proper pin assignements.

  • You should refer to the Wiki Scribbler page and PDF references. You should also read sample .BS2 programs in the Resources/Hacker's Code of Scribbler CD. In particular, read the default Demo code to find out Scribbler pin assignments!
  • Write a flash_and_tune.BS2 program to control your robot to do the following: toggle the 3 LEDs on and off every 2 seconds; when the LEDs are on, call a subroutine "tune" to play music tunes on the speaker. You can use the Scribbler GUI maker to generate the frequency data.
  • Submit your flash_and_tune.BS2 code using submit and the README and report on Wiki.

HW#7- Expression Evaluation and PBASIC Code Generation, DUE: Thursday 4/24, 11:59PM

In this assignment, you will extend the sample expression evaluation code to support use of variables, and also generate PBASIC BS2 file so the evaluation can run on Scribbler. You need to do the following:

  • Part I: Expression Eval
    • Implment variable class, so variables can be used in expression evaluation.
    • Variable values are stored in an environment. Implement Env class as environment. Your Env class should include public methods to add variable name-value pair to Env, and look up variable value by name. You should use the Java collection classes (java.util) to implement the variable table. Decide which class to use and justify your decision in your Wiki report.
    • Your Env class should read variable name-value data from input text file. Add the public method void readFromFile(String file_name) to Env class which will initialize the variable name-value table by reading the input text file with the specified file_name. The file format is: on each line, it will have the form var=val, eg:
      x=3
      y=100
    • Modify the given expression code, so the eval method will take the extra Env object for evaluation.
    • Write both JUnit and client class to test the eval method of your classes, eg, evaluate x+y*10. You should design at least 5 more expressions and use them to test all operations.
  • Part II: PBASIC code generation
  • In Part II, instead of evaluation, you should generate PBASIC BS2 file which contains PBASIC command to compute the value of the expression and print the value to the console using DEBUG command. You need to:

    • Modify your Env and expression classes and add public String genCode() method, which will generate PBASIC commands in string form.
    • Write a test client which will initialize Env using input file, then generate PBASIC code for both Env and expressions as string, and store the string text to an output BS2 file.
    • Test your generated PBASIC BS2 file on Scribbler, use the DEBUG command to print out the value. Your test should generate code for the test expressions you use in Part I.
  • Draw UML class diagrams and generate JavaDoc documentation.

HW#8- The Chirp-Scribbler Project, Part I, DUE: Thursday 5/8, 11:59PM

In the next two homework assignments, we will build the Chirp-Scribbler compiler targeting the Scribbler robot devices. To help you get started, we have provided a basic compiler framework which can compile a subset of Chirp-Scribbler, called CSLite. In this HW, you will study the CSLite sample compiler and modify it to build the first part the Chirp-Scribbler compiler - the lexer and parser, aka the front-end. You will do the following:

  • Read the CSLite sample compiler tutorial, and download the CSLite.zip file and run CSLite in Eclipse using the Test classes. You should also read the Chirp-Scribbler language specification and understand the Chirp-Scribbler language.
  • Study the given code of CSLite sample compiler and write Wiki report to answer the following questions:
    1. What is compiler front-end? Use the CSLite csc compiler source code as example to describe how the csc front-end is implemented: what files implement the front-end, how are the lexer and parser generated, describe ANTLR rules in the .g files - what does each of the rules specify?
    2. What is compiler back-end? Use csc as example to describe how the csc back-end is implemented: what classes implement the back-end, how do they generate PBASIC code.
    3. Rewrite your variable expression test code in HW#7 as CSLite program and run TestLexer, TestParser, TestCodeGen on your program. What output do you get and explain the results.
  • Modify the CSLite compiler to implement the following Chirp-Scribbler statements:
    1. unconditional loop
    2. for loop
    3. break
    You should modify the .g files to generate lexer and parser to support the above new statements. You do not need to generate code - you will do that in the next HW. Write test input program using these statements and show the generated XML AST tree by your parser.
  • You may earn up to 10% extra credit if you implement the following features:
    1. function definition. CSLite program can be defined as collection of functions instead of statements.
    2. while loop and until loop.
    3. relational expression.
    4. array variable.
  • Submit your complete Eclipse project zip file including ANTLR .g files, java source code.

HW#9- The Chirp-Scribbler Project, Part II, DUE: Thursday 5/15, 11:59PM

In Part II of the Chirp-Scribbler project, you will extend the CSLite front-end you build in Part I and implement the back-end code generator to generate PBASIC code which can then run on Scribbler robot. You will do the following:

  • Study the code generation module of CSLite sample compiler and draw UML class diagrams for the codegen classes.
  • Implement code generation classes for the following Chirp-Scribbler statements from Part I:
    1. unconditional loop
    2. for loop
    3. break
  • Implement code generation for the following System functions - refer to the Chirp-Scribbler language specification for function prototypes:
    1. System.wait
    2. System.sound
    3. Scribbler.senseStall
    4. Scribbler.senseLight
  • Write test cases to test your code generator and run output code on Scribbler. Describe your test results on Wiki.
  • You may earn up to 10% extra credit if you implement code generation for the following features:
    1. function definition and user function call.
    2. while loop and until loop.
    3. relational expression.
    4. array variable.
    5. Other System and Scribbler functions - see the Chirp-Scribbler spec.
  • Submit both UML class diagrams for codegen classes and your complete Eclipse project zip file including ANTLR .g files, java source code.

Acknowledgements

The teaching materials on OO List and Design Patterns are based on the teaching materials developed by Dr. Dung Nguyen, Dr. Stephen Wong, Prof. Alan Cox and Prof. Robert Cartwright at the Department of Computer Science, Rice University. All rights reserved.