• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OCP Java SE6 Programmer Practice Exams

 
John Paterson
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Paterson
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi saloni jhanwar

Noted. Thanks!

regards
John
 
John Paterson
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Items
  • If 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?
  •  
    John Paterson
    Ranch Hand
    Posts: 171
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 171
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 171
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 171
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic