Back
Back
Back
Back
Back
Back
Back
Call Back Call Back
logo

24x7 Support Available

To Get the Best Price Chat With Our Experts

chat now

In A Hurry? Get A Callback

logo

shopping cart 0

Subject Solutions Code Description Price Delete

Amount Payable : $0

continue shopping proceed to checkout

World's Leading Assignment Library

Question A1 a) The object factory design pattern is an alternative to constructors for the controlled instantiation of objects. i) Give an example of the application of the object factory design pat

Question Preview:

Question A1 a) The object factory design pattern is an alternative to constructors for the controlled instantiation of objects. i) Give an example of the application of the object factory design pattern in the standard Java libraries. ii) List three advantages of an object factory compared with the use of constructors for object instantiation. b) Consider the following Name class. public final class Name { private final String firstName; private final String lastName; public Name(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } ...

View Complete Question >>

Question Preview:

Question A1 a) The object factory design pattern is an alternative to constructors for the controlled instantiation of objects. i) Give an example of the application of the object factory design pattern in the standard Java libraries. ii) List three advantages of an object factory compared with the use of constructors for object instantiation. b) Consider the following Name class. public final class Name { private final String firstName; private final String lastName; public Name(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } } i) Explain why it is not necessary to define a separate interface for the Name class? ii) There are no constraints on the values of firstName and lastName passed to the constructor of the Name class. Suggest appropriate checks to perform on the parameters and the exception(s) to throw if the parameters do not comply. iii) Convert the Name class into a factory for Name objects. The factory must guarantee that, from the point of view of its clients, each unique combination of firstName and lastName is represented by a single instance of the Name class (there can be no two Name instances with the same firstName and lastName). For example, the factory will only ever provide a single Name object with first name “Mark” and last name “Smith”. Show your complete implementation of the Name class as a factory. Note: it is not necessary to define any new classes iv) Do you need to override the Object equals method in your modified class? Briefly explain your answer. Question A2 a) A hash table data structure can be used to implement a set or a map. i) With the aid of a diagram, describe the structure of a hash table that is used to implement a set. Explain how the structure enforces the no duplicate elements invariant of sets. ii) Under normal conditions, a hash table provides fast access to its elements (e.g. add and remove are O(1) operations). Explain why this is and under what conditions (and how) performance of a hash table degrades. iii) Explain why the inconsistent implementation of Object equals and hashCode methods can undermine the integrity of Java hash table data structures. What constraint must be placed on the computation of an object’s hashCode? b) Provide an implementation of the compareTo method for the following Name class that orders instances of Name by lastName then firstName. public final class Name implements Comparable { private final String firstName; private final String lastName; public Name(String firstName, String lastName){ this.firstName = firstName; this.lastName = lastName; } } public String getFirstName(){return firstName;} public String getLastName(){return lastName;} public int compareTo(Name name){ // provide implementation of this method } } c) Provide a Comparator that orders instances of Name by firstName then lastNamae A SortedSet uses a binary tree to maintain its elements in their sorted order. Draw the state of the tree after execution of the following sequence of code: SortedSet names = new TreeSet(); names.add(new Name("Mark", "Smith")); names.add(new Name("Elena", "Poulou")); names.add(new Name("Stephen", "Hanley")); names.add(new Name("Paul", "Hanley")); names.add(new Name("Marc", "Riley")); names.add(new Name("Craig", "Scanlon")); names.add(new Name("Jim", "Watts")); Use circles labelled with full names to illustrate each node of the tree. You may show intermediate states. d) Two possible implementations of the List data structure are a linked list and a resizable array. For each of the following scenarios, state which of these two implementations would be the most efficient to use and why. i) A queue of people at a cinema ticket office. ii) The names in a mobile phone address book. e) A Set would be a more suitable data structure than a List for the names in a mobile phone address book, the scenario from d) ii) above. State the reason for this and also which of the Java set implementations (HashSet or TreeSet) you would use if you were to implement this and why. Question A3 a) Describe and illustrate with a diagram the structure of a doubly linked list. b) It is possible to use a resizeable array or a doubly linked list to implement a list. Preferably using the Big ‘O’ notation, compare and contrast the performance of the two data structures for the following list operations: i) get or set an element at an arbitrary position in the list, ii) add or remove an element at the head of the list, and iii) insert or remove an element at an arbitrary position in the list (other than the head or tail). In each case, explain any difference between worst-case performance for a resizeable array and a linked list. c) Explain whether the worst-case performance of the following method is better for a collection implemented using a resizable array or a linked list. void removeBelowLimit(Collection vals, int lim) { for (Iterator i = vals.iterator(); i.hasNext(); ) { if (i.next() < lim) { i.remove(); } } } Question B1 a) Describe and illustrate with a diagram the life cycle of a thread from being created to termination. List the ways by which a thread can be blocked and unblocked. [10 marks] b) Write a program that creates two threads, one to print out “Hip, hip!”, and the other to print out “Hooray!” (both in finite counting loops). After creating the two threads, the main program should terminate. [10 marks] c) Modify your program so that the thread printing out “Hip, hip!” would run first, and the thread printing out “Hooray!” be allowed to run only after the “Hip, hip!” thread has finished. Question B2 a) What are the distinguishing characteristics of an event driven program as opposed to a conventional program? Provide an overview of the basic architecture of an event driven program, including a description of the event processing mechanism. What is the difference between an event handler and an event dispatcher? b) Describe briefly the basic steps that a Java programmer needs to take in order to set up event handlers and deal with events. c) You have been asked to implement a simple length conversion program as an event-driven program with a graphical user interface. The user is able to enter a length in miles into a text box. On pressing a button, the length entered is converted into kilometres and displayed in another text box (1 mile = 1.609 kilometre). Explain how you would construct such a program, by identifying the basic Java Swing components you would use, and specifying how events are handled. Provide outline code for the relevant parts of the application.

View Less >>

Solution Preview

The application of the requirement to create multiple currency e.g. INR, SGD, USD and code should be extensible to accommodate new Currency as well. Here we have made Currency as interface and all currency would be concrete implementation of Currency interface. Factory Class will create Currency

question Get solution

$25

Orginal Price : $32.50

Pay Now

Upload Assignments

250 words

side

Get Your Assignment

Don’t delay more, place your order now. Quick assignment help will be offered to you.

Order Now

CUSTOMER REVIEWS

Excellent

logo

Based on 702 reviews See all reviews here

One of the Best Service

I trust LiveWebTutors for my assignments because of their ability to deliver the perfect assignments time and again. Only a few of my assignments required minor revisions. The rest assured it is the best assignment writing service in the market.

Elizabeth
Sydney

Great Service and on time

I felt so exhausted and burdened with the large number of assignments I had to write and desperately needed someone to help me with all the writing and there was LiveWebTutors company on the internet. They finished my assignments before the due date and also offered me a first-timer discount.

Christina
Perth

One of the Best Assignment Provider

I ordered my Mathematics and Marketing assignments from them last month. I received the content on the set date. Most importantly, the assignments were well-written and plagiarism free. I scored a top grade for the assignment written by them. They are a reliable company.

Oli
Brisbane

Very Helpful Customer Service

I was quite unsure about getting my assignment written online but after coming across LiveWebTutors.com, all my worries have vanished. The quality of the assignments written by their writers is just invincible. Their customer support is very polite and helpful. You should try their service at least once

Kabir
Adelaide