DPSD Program 1

Creating Objects

UML Diagrams and other Design Documents for all programs are due to your TA before the next lecture after the assignment is given. You must review it with your TA during their scheduled office hours (or make an appointment). This is worth 10% of your score for the assignment.

Part a - Pizza

Write a class called Pizza. The Pizza class should have the following fields:

The Pizza class should have the following methods:

Write a program called PizzaTester that demonstrates the Pizza class. The program should create an instance of the class and display the randomly-generated pizza. Then, it should use a loop to prompt the user for the meat and veg choice for N number of pizzas, where N is passed in on the command-line. Each time a pizza is ordered, display it.

Create a custom Exception for invalid data; your main() should throw and catch it when the user gives an invalid response for the meat or vegetable options.

Part b - Parking Ticket Simulator

Create a set of classes simulating a police officer issuing a parking ticket.

Class - ParkedCar has the following responsibilities: To know the car's make, model, color, license number and number of minutes the car has been parked.

Class - ParkingMeter. This class should simulate a parking meter. This class's only responsibility is to know the number of minutes of parking time that has been purchased.

Class - ParkingTicket has the following responsibilities: To report the make, model, color and license number of an illegally parked car; to report the fine - which is $25.00 for first hour plus $10.00 for each additional hour; to report the name and badge number of the police officer issuing the ticket.

Class - PoliceOfficer has the following responsibilities: To know the name and badge number; to examine a parked car and parking meter object and determine whether the car's time has expired; to issue a parking ticket if the car time has expired.

Plan of attack


Pizza


Learning objectives

After completing this assignment you will be able to:
  1. Create Classes using Java coding standards and Object Oriented Programming basics.
  2. Create enums.
  3. Create a custom exception.
  4. Analyze requirements, design, code and test small Java programs.

Understanding requirements

Design


Parking Ticket Simulator


Learning objectives

  1. Analyze requirements, design, code and test Java programs.
  2. Understand and apply the 5 basic object/class relationships discuss in class.

Understanding requirements

Design to simulate a system where a police officer issues a parking ticket.
You should design a set of classes that work together as a ParkingTicket Simulator.

Design

Let's decide what classes, methods and fields should be required.

Since the PoliceOfficer will make the decision on whether to issue ticket, the issueTicket() method belongs to PoliceOfficer. The ParkedCar, ParkingTicket and ParkingMeter objects are independent entities described below.

The ParkedCar Class has the following responsibilities:

The ParkingMeter Class only responsibility is as follows:

The ParkingTicket Class has the following responsibilities:

The PoliceOfficer Class has the following responsibilities:

Write a Simulator called TestParkingTicket that uses separate test classes that test your ParkingTicket classes. including testing situations for at least these test cases:

  1. The ParkedCar is within the parking time purchased.
  2. The ParkedCar is over the parking time purchased.
  3. The ParkedCar is just barely within the parking time purchased.
  4. The ParkedCar is just barely over the parking time purchased.
  5. The ParkedCar is exactly at the parking time purchased.
  6. The ParkedCar is ticketed for being less than 1 hour over the time purchased.
  7. The ParkedCar is ticketed for being more than 1 hour over the time purchased.
  8. The ParkedCar is ticketed for being exactly 1 hour over the time purchased.

Topics to Learn

---------------
  1. Basic Object Oriented Programming and class design
  2. Weak and Strong association in design
  3. Random class and methods
  4. Enumerations
  5. Custom Exceptions
  6. Testing, including boundary conditions
  7. UML Class diagrams

Testing

-------

These assignments will be graded by the respective TAs and feedback will be provided along with a score (maximum score out of 100).

Submitting your work

-------
  1. Check each part of your submission against the following grading criteria.
    1. Your design satisfies the criteria of using pass by reference in methods between objects. This means strong composition is not used when a weak association is the appropriate relationship.
    2. Following Java Coding Conventions
    3. Code Readability (as discussed in class)
    4. Uses packages as directed (the default package does not count)
    5. Code compiles and executes
    6. Adequately tested (with at least 3 unique test cases covering boundary conditions)
    7. Make sure your test program has all your testing code in it - do not erase your individual test cases.

  2. Submission
  3. Please create a separate folder for each part in this project and submit:

  1. All project files, including the source code and any input files.
  2. Your build.xml file(s):
  3. Output from all test runs - put this output in files called PizzaTest.txt and ParkingTest.txt. Make sure your test output is properly labelled.
  4. Final class diagram for each class (can be generated). (Note: this is different than the required UML design review.)
  5. Do NOT submit .class files - they will generated when we compile your code.

    Zip up the submission in a single file that mimics the package organization (starting from the package name - don't give us everything!). Note: only .zip fies will be accepted.

    Call the zip archive andrewid_hw1.zip. Follow the instructions provided by your TA(s) for submitting it.