Assignment 1: Designing complex data
Goals: Practice designing the representation of complex data.
1.1 Instructions
the names of classes,
the names and types of the fields within classes,
the names, types and order of the arguments to the constructor, or
filenames,
You will submit this assignment by the deadlines using the course handin server. Follow A Complete Guide to the Handin Server for information on how to use the handin server. You may submit as many times as you wish. Be aware of the fact that close to the deadline the server may slow down to handle many submissions, so try to finish early. There will be a separate submission for each problem - it makes it easier to grade each problem, and to provide you with the feedback for each problem you work on.
Due Date: Thursday, January 19th, 9:00 pm
Practice Problems
Work out these problems from How to Design Classes on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.
Problem 2.4 on page 17
Problem 3.1 on page 25
Problem 4.4 on page 34
Problem 5.3 on page 43
Problem 10.6 on page 102
Problem 11.2 on page 113
Problem 14.7 on page 140
Everywhere in this assignment that you see italic, fixed-width text, it is intended to be the name of a field, identifier, class name or interface name you must define...but you likely must modify that name a bit to conform to our Java naming conventions: hyphenated-names are written in camelCase, and interface names begin with an uppercase I.
Everywhere that you see fixed-width text, it is exactly the name you must use.
Problem 1: Real Estate Listings
We are designing a data representation for a real estate listing. For each listing we need to collect the following information:
singleFamily: whether the property is a single family home or a condo, to be represented as a boolean
year: the year the property was built represented as an int
squareFootage: represents the area of the property as an int
price: the price in dollars represented as an int
city: represents the name of the city that the listing is in as a String
Design the class RealEstateListing that represents the information about a listing.
Make at least three examples of instances of this class, in the class ExamplesListings. Two of the examples should be objects named bostonCondo and beachHouse and should represent the following two listings:
a 700 square foot condo in Boston built in 2010 that is selling for $350,000.
a 2000 square foot single family home in Yarmouth built in 1995 that is selling for $699,999.
What to submit
You should submit your data definitions and examples in a file named Listing.java
Remember to check the feedback in handins for Style and Checker Tests in handins!
Problem 2: Organizing Apps
A smart phone model allows users to organize their apps in sets related to the apps’ purposes.
Here is a data definition to represent an app set in DrRacket:
;; An AppSet is one of: ;; -- Folder ;; -- Apps ;; A Folder is a (make-folder String) (define-struct folder [title]) ;; Apps is a (make-apps String AppSet) (define-struct apps [app-name others])
Draw the class diagram that represents this data definition. You may draw this as ASCII-art and include it in your submission, if you wish. Or you can just draw it on paper and not submit it. Regardless, we think it will help you in visualizing how the data is organized.
Convert this data definition into Java. Make sure you use the same names for data types and for the fields, as are used in the DrRacket data definitions, converted into Java style conventions. Make sure that the constructor arguments are given in the same order as shown.
Include in your examples the following sets:
– a "Travel" set with "Uber" and "mTicket" and "Moovit" and "Orbitz"
– a "Food" set with "Grubhub" and "B. Good" and "Gong Cha"
Make sure the two sample sets given above are named travelApps and foodApps.
Note: the descriptions above are listed in the order that you would add the apps to a folder in real life. Think carefully how this should be represented as data.
Name the class that holds the examples of your group data ExamplesSets.
What to submit
You should submit your data definitions and examples in a file named AppSets.java
Remember to check the feedback in handins for Style and Checker Tests in handins!
Problem 3: Sims
We’ve been asked to help build an expansion pack for Sims 5: University Life. We’re trying to figure out the gameplay mechanics, so we’re starting with representations for Sims students, behaviors and places they can visit around the game world.
Study
Socialize
Exercise
Study has a subject and whether it is examReview or not.
Socialize has a description and a count of friends to socialize with.
Exercise has a name and whether it is aerobic or not.
Classroom
Gym
StudentCenter
A Classroom has a name, room-capacity and the current occupant-count. The occupant count must be less than the room’s capacity.
A Gym has a name, a count of exercise-machines, the current count of its patrons as well as whether it is open or not. The number of patrons must be less than the number of exercise machines or zero if the gym is closed.
A StudentCenter has a name and whether it is open or not.
A sim-student has a name, mode and a location that is their current place, as well as a gpa and a major.
A student’s location must be Classroom if their gpa is less than 3.0. If their mode is Study then their location must be Classroom or StudentCenter. Similarly, if their mode is Exercise, their location must be Gym.
- Define 6 examples of place, including:
shillman105: named "Shillman 105", capacity 115, occupants 86
marino: Named "Marino Recreation Center", with 78 machines and 47 patrons. The gym is open.
curry: Named "Curry Student Center" and is closed.
The others can be whatever you wish. Define four Sim students that represent students in each mode and place.
Name your examples student1, student2 etc., and your examples class ExamplesSims.
We’re placing a lot of restrictions on the data, such as the population of classes and gyms being less than capacity, possible places, etc. However we aren’t (yet) actually enforcing these in the code. The ways to enforce these constraints will be further explored later in the semester. For now, you are expected to create examples that conform to these constraints.
What to submit
You should submit your data definitions and examples in a file named Sims.java
Remember to check the feedback in handins for Style and Checker Tests in handins!