Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

OCP Java SE6 Programmer Practice Exams

 
Ranch Hand
Posts: 173
  • 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
 
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: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi saloni jhanwar

Noted. Thanks!

regards
John
 
John Paterson
Ranch Hand
Posts: 173
  • 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.



 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • 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: 173
    • 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: 173
    • 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: 173
    • 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: 173
    • 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.
     
    Don't get me started about those stupid light bulbs.
      Bookmark Topic Watch Topic
    • New Topic