I cant seem to get the coding on Chapters 22 23 in the Lian

I can\'t seem to get the coding on......

Chapters 22 & 23 in the Liang text

Know this inheritance hierarchy – these are interfaces (not classes).

It is possible for an interface to extend an interface. This allows the designers to define methods that are in common to all of the sub-interfaces.

parent interface is Collection,

sub-interfaces Set, List, Queue,Deque. Set has a sub-interface Sorted Set.  

The Map interface has a sub-interface SortedMap.

Programming Exercises:

Part 1.

1. Describe auto-boxing, including why it is useful. (Google for this one) Write a few lines of code that auto-box an int into an Integer, and un-box an Integer to an int.

2. Declare an ArrayList of Strings. Add 5 names to the collection. “Bob” “Susan” … Output the Strings onto the console using the enhanced for loop.

3. Sort the list using the method Collections.sort. Output the sorted List. Shuffle the list, and output the shuffled list. Note that Collections (with an s) is a class, while Collection is an interface. The Collections class has many useful static methods for processing interfaces, including the sort method.

4. Search for the name “Susan” in the list. What location was it found? Search for a names that is not in the list. What location is reported?

5. Describe why an equals method and a compareTo method are required to achieve searching and sorting of the elements of a list.

6. Convert the list above to an array using toArray. Output the elements of the array. Convert the array back into a list using asList. Output the elements of the list.

7. Describe the differences between a HashSet, TreeSet, and a LinkedHashSet. When might you choose each one of these?

8.   Describe the differences between a HashMap, TreeMap, and LinkedHashMap. Describe the situation when might you use each of these?

Part 2.

Going back to the GUI assignment. You can modify this to use JavaFX if you want to.

            Create an application that has a button that has “Enter your info.” When clicked it will present a JDialog that has labels and text boxes that allow the user to enter their name, email, and phone number. The JDialog will have buttons OK and Cancel.

When the user clicks Cancel, the dialog will go away without doing anything else.

When the user clicks OK, the user’s information will be extracted from the dialog, and dumped out on the console.

Notice that you only are listening for Click events.

We will add to that spec.

Define a class to hold the info for a single person. Declare an ArrayList of this type. When the user clicks OK, extract the info from the dialog. This time, pass the info to the constructor method of your class that will hold the info. Add this newly created object to your array list.

Using an enhanced for loop, dump the ArrayList onto the console.

Add several user info\'s to the ArrayList, each time, dumping the entire list to the console.

Sort the ArrayList. Dump the ArrayList onto the connsole.

Deliverables.

Make a copy of this document. In part 1, when it says “describe…” or calls for some explanation, add your answers to this document, after the question you are answering. Highlight your answers if you want to make the reader of your work happy.

For Part 1, the code, and the output on the console from running the code. Add comments in the code, and in the output to help me find what you’re doing.

// Part 1 a

System.out.println(“Part 1 a”);

Solution

1.Auto Boxing and Auto Unboxing :-

By using this concept we can avoid using primitive variables for storing data, instead we can use objects directly. But still primitive variables support is also available to providee backward compatibility.

Using auto boxing and unboxing we can perform calculation as shown below :-

Integer io1 = 10 ;

Integer io2 = 20 ;

Integer io3 = io1+io2 ;

System.out.println(\"Result:\"+io3) ;

2. ArrayList of Strings.:-

import java.util.*;
public class Example
{
public static void main(String[ ] args)
{

ArrayList a=new ArrayList();

a.add(\"Bob\");

a.add(\"Susan\");

a.add(\"Raja\");

a.add(\"Jony\");

  a.add(\"Java\");

for( Object obj : a ) //The enhanced for loop

{

System.out.println(obj) ;
}

}

I can\'t seem to get the coding on...... Chapters 22 & 23 in the Liang text Know this inheritance hierarchy – these are interfaces (not classes). It is poss
I can\'t seem to get the coding on...... Chapters 22 & 23 in the Liang text Know this inheritance hierarchy – these are interfaces (not classes). It is poss

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site