| Author |
OCP Java SE6 Programmer Practice Exams
|
John Paterson
Ranch Hand
Joined: Mar 12, 2012
Posts: 81
|
|
Hi Folks,
Does anyone have any idea where I can get the solutions for the 'Coding Exercises' found in the book
OCP Java SE6 Programmer Practice Exams
by Bert Bates and Kathy Sierra?
Thanks.
regards
John
|
 |
saloni jhanwar
Ranch Hand
Joined: Feb 09, 2012
Posts: 583
|
|
John Paterson wrote:Hi Folks,
Does anyone have any idea where I can get the solutions for the 'Coding Exercises' found in the book
OCP Java SE6 Programmer Practice Exams
by Bert Bates and Kathy Sierra?
Thanks.
regards
John
You can post here particular exercise, if you find any doubt.Even in K&B study guide you wont find solution of exercise because that is an exercise not a mock question.
|
Tell the difficulties that i am difficult.
|
 |
John Paterson
Ranch Hand
Joined: Mar 12, 2012
Posts: 81
|
|
Hi saloni jhanwar
Noted. Thanks!
regards
John
|
 |
John Paterson
Ranch Hand
Joined: Mar 12, 2012
Posts: 81
|
|
Following is the question from a certain section and my attempts at one of it's sub-sections. I will post my solutions here. I hope someone can have a look and say if I am indeed answering the question in the correct way, not just compiler and run time error, but also the approach. Thanks everyone.
Section6: Collections/Generics
6.a Create an Items class that has a String name, and an int value. Note that you will use this class in several of this section's exercises, and you may need to enhance this class as you go along. For all of 6.a, use classes in java.util whenever possible
i) Write a class that makes a collection of Items that guarantees no duplicates.
My Solution:
ii) Write a class that makes a collection of Items that can be accessed in the order in which they were added to the collection.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26496
|
|
John Paterson wrote: Write a class that makes a collection of Items that guarantees no duplicates.
Two problems.
You have a collection of strings not ItemsIf you did create a set of Items it could contain duplicates. How does Java tell if two items in a set are duplicates? What does your Item class lack in that space?
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
John Paterson
Ranch Hand
Joined: Mar 12, 2012
Posts: 81
|
|
Hi Jeanne Boyarsky,
Thanks for the reply. I took note of what you mentioned. Working on it now, will post once done. Thanks.
regards
John
|
 |
John Paterson
Ranch Hand
Joined: Mar 12, 2012
Posts: 81
|
|
Hi all,
My corrected code for Question 6 a)
i) Write a class that makes a collection of Items that guarantees no duplicates.
Though not part of the question, I overrode the toString method to produce some redable output to verify the code. To confirm that the code is properly handling duplicates, I changed ...to and the output was [4,1,2]. If not the output will be [4, 1, 2, 3]. I feel that I may have answered the question correctly. Any comments from anyone will be much appreciated. Thanks.
regards
John
|
 |
John Paterson
Ranch Hand
Joined: Mar 12, 2012
Posts: 81
|
|
Hi all,
My corrected code for Question 6 a)
ii) The only change from question i) is the following block:
The output follows the same order as the above code block, so I guess that fulfills the requirement of 'can be accessed in the order in which they were added to the collection' part.
|
 |
John Paterson
Ranch Hand
Joined: Mar 12, 2012
Posts: 81
|
|
Hi all,
My corrected code for Question 6 a)
ii) The only change from question i) is the following block:
The output follows the same order as the above code block, so I guess that fulfills the requirement of 'can be accessed in the order in which they were added to the collection' part.
|
 |
 |
|
|
subject: OCP Java SE6 Programmer Practice Exams
|
|
|