We first review the Design Recipe and then show how we can express our programs in Java instead of Racket. We cover the basic syntax for classes, fields, and methods, as well as how to create new object instances.

We introduce a simple memory model for Java and walk through an example. We conclude the module with an introduction to Javadoc, Java's documentation tool, as well as testing with JUnit.

  1. List three Java primitive types.
  2. Write an example of a reference type.
  3. Given a list of Java values, mark the values that are reference types.
  4. Given a list of Java values, mark the values that are primitive types.
  5. Given a Java class use it to create one object instance.
  6. Use Javadoc in your comments to write purpose statements for Java methods.
  7. Given a set of Java classes with Javadoc annotations, build the html output.
  8. Given a data definition for a Racket Structure, write the corresponding Java class.
  9. Given a data definition of a one-level nested structure, write the corresponding Java class.
  10. Given a Java class, draw the corresponding UML class diagram.
  11. Given a UML class diagram, translate it into Java classes.
  12. Write the names of the two types of memory used by the JVM.
  13. Explain the difference between the equals method and == when used with reference types.
  14. Given a set of Java classes, add methods to define equality.
  15. Given a Java class with methods, write JUnit tests to verify the correctness of the methods.

  • DUE DATE: May 19th @ 12:00pm (NOON)

Resources

Here are some online resource that you might find usefull while tackling this assignment.

Submission Requirements

Your repository should contain the following files

  • One .java file per Java class
  • One .java file per Java test class
  • One pdf or image file for each UML Class Diagram that you create

You repository should not contain

  • Any .class files
  • Any .html files
  • Any IntelliJ specific files

Problem 1

A friend is trying to create a program to keep track runners that take part in a marathon. For each runner that takes part in the marathon we need to keep track of their name, their start time and their end time.

We keep track of time by recording the hour, minutes and second. A valid time is one where

  • the hours is between 0 and 23 inclusive
  • the minutes is between 0 and 59 inclusive
  • the seconds is between 0 and 59 inclusive

He has started designing the program and after a first iteration your friend has created the following UML class diagram.

Runner Class Diagram
  1. Your friend asked you to create the Java code based on his Class Diagram
  2. Add a method in class Runner with the following signature public Time getEndTime() that will return the runner's end time for the marathon. A runner's total time is calculated using the following formula startTime + duration. Note your method should return a valid Time.

Problem 2

You have been tasked to help with designing a program for a bank. The bank maintains deposit accounts. A deposit accounts consists of:

  • The account holder's name. An account holder is an individual with a first and last name.
  • The current account balance as an amount. An amount consist of:
    • An integer value for the dollar amount greater or equal to 0
    • An integer value for the cents amount, greater or equal to 0 and less than or equal to 99.
  1. Create a UML Class Diagram of your design for a bank account. Your diagram has to be either a pdf file or an image file.
  2. Create the Java code for your UML Class Diagram
  3. The bank would like to capture the event of a deposit to the account. Customers can deposit (add) money to their account. Design a method that will allow deposits on an account, the method should consume an amount and will return a new account such that the account balance has been increase by the amount deposited.
  4. The bank would like to capture the event of a withdrawal to the account. Customers can withdraw (take away) money from their account. Design a method that allow withdrawals on an account, the method should consume an amount and will return a new account such that the account balance has been decreased by the amount deposited. You may assume that the amount withdrawn is less than or equal to the current balance of the account.
  5. Provide your final UML Class Diagram that includes the methods for deposit and withdrawal

GRADING CRITERIA

  1. All code has proper Javadoc documentation for
    • Classes
    • Methods
  2. All Java code that you write has JUnit tests
  3. All reference types use equals() to check for equality. You are not allowed to use == for equality.
  4. The following are not allowed inside code that you write
    • primitive types
    • arrays
    • null

SUMMARY OF ASSIGNMENT

Item Points
Code builds with no errors 2
Tests run with no errors/failures 5
Javadoc builds with no errors/warnings 5
Problem 1 41
Problem 2 49
GRAND TOTAL: 102