Programming Assignment 10
Due: Week of Nov. 14 in lab
Using inheritance, write a basic social network. Your network will resemble
some elements of Facebook. There should be an Account
super
class. Two types will extend Account
, Person
and
Page
. There should be a Relationship
super class.
Two types will extend Relationship
, Friend
and
Follow
. You should also have a client program for the social
network that defines the main.
Name the files Account.java
, Person.java
,
Page.java
, Relationship.java
,
Friend.java
, Follow.java
, and
SocialNetwork.java
.
Other details:
Account
- at a minimum- Should have at a minimum a name.
- Should provide an accessor for the name variable.
- Should override the
toString
function appropriately.
Person
- at a minimum- Should have an array of at most 100
Friend
(note, that Java arrays can storenull
). - Should have an array of at most 10
Follow
. - The constructor does NOT take an array of
Friend
or an array ofFollow
- A function
addFriend(Person p)
will create aFriend
relationship between two people. Essentially it will call a helper function ofthis
andp
that searches for an empty (null) location in the friend array to insert a newFriend
object. If no such location exists, report failure. - A function
like(Page p)
will search the following array for an empty location to insert a newFollow
object. This function should also increment the number of followers (through a function) ofp
. If no location exists, report failure. - Should override the
toString
function appropriately. This function should callAccount
'stoString
function to increase code reuse (throughsuper
). Ensure that you output a list of friends and a list of follows (one line per friend/follow). - It is recommended to keep track of the number of friends and the number of followers as well. It might make error checking and implementation easier.
- Should have an array of at most 100
Page
- at a minimum- Should have an
int
for the number of followers. - The constructor does NOT take an integer for the number of followers. It should start at 0.
- Should hava a function to increase the number of followers.
- Should override the
toString
function appropriately. This function should callAccount
'stoString
function to increase code reuse. Ensure that you output the number of followers.
- Should have an
Relationship
- at a minimum- Should have a
Date
for the creation of the relationship (lookupjava.util.Date
). - Should override the
toString
function appropriately.
- Should have a
Friend
- at a minimum- Should contain a reference of a
Person
(recall a reference is a pointer). this means theFriend
object points to an existingPerson
object. Do not usenew
when sending aPerson
in the constructor. - Should override the
toString
function appropriately. this function should callRelationship
'stoString
function to increase code reuse. Only output the name of thePerson
instead of callingtoString
.
- Should contain a reference of a
Follow
- at a minimum- Should contain a reference of a
Page
. This means theFollow
object points to an existingPage
object. Do not usenew
when sending aPage
in the constructor. Also increment the number of follows on that page here. - Should override the
toString
function appropriately. this function should callRelationship
'stoString
function to increase code reuse. Only output the name of thePage
instead of callingtoString
.
- Should contain a reference of a
SocialNetwork
- at a minimum- Should create two
Person
objects and onePage
object. Have both people befriend each other and also follow the page.
- Should create two
Example output of SocialNetwork
's test:
Person
Account name: Jory Denny
Number of friends: 1
Number of follows: 1
Friends
Friend. Relationship created Mon Nov 14 10:15:13 EST 2016. With Zachary Pollock.
Follows
Follow. Relationship created Mon Nov 14 10:15:13 EST 2016. Following Zen-Do-Kai Karate.
Person
Account name: Zachary Pollock
Number of friends: 1
Number of follows: 1
Friends
Friend. Relationship created Mon Nov 14 10:15:13 EST 2016. With Jory Denny.
Follows
Follow. Relationship created Mon Nov 14 10:15:13 EST 2016. Following Zen-Do-Kai Karate.
Page
Account name: Zen-Do-Kai Karate
Number of followers: 2
Bonus. Provide an example of polymorphism in your
product, either with relationships or accounts. Other extensions: provide a feed
and post mechanism for accounts using String
s.
Grading
Each assignment is graded out of 100% based on a combination of the criteria listed in the assignment description and programming style (e.g., good comments and naming) -- following instructions is extremely important in computer science, train yourself to think like the computer; programming style is important to be able to communicate your solutions to another programmer; both of which you are graded upon.
Specific instructions. Failure to do these steps will result in a loss of points.
- Name each file and program as listed in the instructions.
- Name all variables descriptively.
- Indent all programs appropriately.
- Use comments to help explain the steps and logic of your program.
- The top of your program should have a comment block where the first line
is your name, second line is your section, and third line is a description
of your java program.
//Name: Jory Denny
//Section: 00
//This program debates Batman vs Superman!
Turn in instructions. Each programming assignment is to be turned in before your lab section. You will turn in a soft copy of the assignment (.java or .zip for multiple java files) through blackboard. You will also turn in a hard copy of the assignment in your lab section with a signed coverpage (each program should start a new page of the hard copy).
If there are any discrepencies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).