The problem was loosely stated as follows:
The program would take in as input a "story" of a photography company's business processes. Namely, these processes consisted of:
- Hiring new photographers
- Taking in new assignments from clients
- Allocating photographers for each assignment
- Reviewing the portfolio of the company's work
Photographer Danny //hire a new photographer named "Danny"
Photographer Leslie
5 a parrot //top priority assignment to take a photo of a parrot
2 a waterfall
4 a mountain
3 Paris
GiveOutAssignments //assign each photographer with 1 assignment,
4 a pony //top priority first
GiveOutAssignments
GiveOutAssignments
1 the forest
2 a flower shop
GiveOutAssignments
3 a butterfly
4 a sprout in the rain
GiveOutAssignments //after the last line, review portfolio
Udacity gave some "cheat" code that read in the file, parsed, and provided the following information:
- For "hire new photographer" lines, the following code is executed:
- manager.hire(photographer)
- i.e. the "hire" method is called on an instance of the Manager Class passing the parameter "photographer" of type String
- For "new assignment" lines, the following code is executed:
- manager.newAssignment(priority, description)
- i.e. the "newAssignment" method is called on an instance of the Manager Class passing the parameters "priority" of type int and "description" of type String
- For "give out assignments" lines, the following code is executed:
- manager.giveOutAssignments()
- i.e. the "giveOutAssignments" method is called on an instance of the Manager Class
- When the end of the "story" file is reached, the following code is executed:
- manager.reviewPortfolio()
- i.e. the "reviewPortfolio" method is called on an instance of the Manager Class
My approach can be summarized as follows:
- Determine the tasks involved in the solution
- Flesh out the inner-workings of those tasks
- Determine other Classes that could assist in the solution
- Determine instance variables that would also be necessary
- Loosely consider the public methods that would be required to exchange information between classes
- Start writing methods for each task
- Write accessor methods to other Classes as if those methods already existed
- Keep a list of accessor methods required to implement in other Classes.
- Debug
- Test
1) Determine the tasks involved in the solution:
- hire photographer
- create assignments
- give out assignments
- display portfolio
- Photographer (would contain the photographer's name, "take pictures")
- Assignment (would contain the assignment's priority, along with description)
- Portfolio (would contain the pictures taken by all photographers)
Hire photographer:
- needs to create a new Photographer object (pass String "name" to Photographer's Constructor
- Manager Class would contain an ArrayList of Photographers, add() Photographer
- Photographer Class would have a Constructor that passes the "name" to the Photographer object
- needs to create a new Assignment object (pass int "priority" and String "description to Assignment's Constructor)
- Manager Class would contain an ArrayList of Assignments, add() Assignment
- Assignment Class would have a Constructor that passes the "priority" and "description" to the Assignment object
- In order to ease the "pain" of keeping track of where the highest priority Assignments are in the assignments ArrayList, each new Assignment will be added by descending priority
- For each Photographer, give out the next highest priority Assignment (first item in sorted ArrayList)
- Do this by calling Photographer's "take photo" method
- Pass photo to Portfolio, along with the photographer's name
- Call the portfolio's draw method
3. Start writing methods for each task:
As already included in the summary, I went about this by first constructing the various Constructors of my Manager and helper Classes, followed by fleshing out the methods of the Manager class. I kept my perspective completely locked on the Manager Class while writing Manager methods, assuming I had complete access to the other helper classes via methods that I assumed were already fully implemented.
After completing each Manager method, I would review the code to determine which public methods I needed to write for my various helper methods which I wrote on a piece of paper. After writing all of those down, I switched my focus over to the helper Classes and wrote the methods that the Manager Class would need for the Manager methods, fleshing out instance variables as needed along the way.
Rinse and repeat until I implemented all of the Manager Class methods, along with the corresponding helper Class methods. I made some anticipated syntax mistakes that threw the compiler for a loop, however I was very pleased when the test case passed on the first try! See my completed code here.
No comments:
Post a Comment