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:
- A field called numSlices.
- A field called meatChoice that uses a new enum (that you create). This new enum must have at least 3 options.
- A field called vegChoice that uses a new enum (that you create). This new enum must have at least 5 options.
The Pizza class should have the following methods:
- A default constructor that randomly determines the pizza.
- All other methods in your Pizza class required for good class design. We will discuss this during lecture. ** Note: pay attention, this is important!
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:
- Create Classes using Java coding standards and Object Oriented Programming basics.
- Create enums.
- Create a custom exception.
- Analyze requirements, design, code and test small Java programs.
Understanding requirements
- We will discuss this in class.
Design
- We will discuss this more in class.
- What "getters" make sense? Write them!
- What other constructors make sense? - Write them!
- What other methods make sense? - Write them!
Parking Ticket Simulator
Learning objectives
- Analyze requirements, design, code and test Java programs.
- 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:
-
To know the car's make, model, color, license number and number of minutes the car has been parked. Create getter and setter methods for all the fields.
The ParkingMeter Class only responsibility is as follows:
-
To know the number of minutes of parking time that has been purchased.
The ParkingTicket Class has the following responsibilities:
-
Report the make, model, color and license number of an illegally parked car.
-
Report the fine - which is $25.00 for first hour plus $10.00 for each additional hour
-
Report the name and badge number of the police officer issuing the ticket.
The PoliceOfficer Class has the following responsibilities:
-
To know the Officer's 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.
Write a Simulator called TestParkingTicket that uses separate test classes that test your ParkingTicket classes. including testing situations for at least these test cases:
-
The ParkedCar is within the parking time purchased.
- The ParkedCar is over the parking time purchased.
- The ParkedCar is just barely within the parking time purchased.
- The ParkedCar is just barely over the parking time purchased.
- The ParkedCar is exactly at the parking time purchased.
-
The ParkedCar is ticketed for being less than 1 hour over the time purchased.
- The ParkedCar is ticketed for being more than 1 hour over the time purchased.
- The ParkedCar is ticketed for being exactly 1 hour over the time purchased.
Topics to Learn
---------------
- Basic Object Oriented Programming and class design
- Weak and Strong association in design
- Random class and methods
- Enumerations
- Custom Exceptions
- Testing, including boundary conditions
- 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
-------
- Check each part of your submission against the following grading criteria.
- 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.
- Following Java Coding Conventions
- Code Readability (as discussed in class)
- Uses packages as directed (the default package does not count)
- Code compiles and executes
- Adequately tested (with at least 3 unique test cases covering boundary conditions)
- Make sure your test program has all your testing code in it - do not erase your individual test cases.
- Submission
Please create a separate folder for each part in this project and submit:
- All project files, including the source code and any input files.
- Your build.xml file(s):
- Select Export
- Under General, select Ant Buildfiles
- Select the project
- Unselect the option to create the Target using Eclipse
- Output from all test runs - put this output in files called PizzaTest.txt and ParkingTest.txt. Make sure your test output is properly labelled.
- Final class diagram for each class (can be generated). (Note: this is different than
the required UML design review.)
- 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.