Question

In: Computer Science

#3 A collection represents a group of objects, known as its elements. Some collections allow duplicate...

#3 A collection represents a group of objects, known as its elements. Some collections allow duplicate elements and others do not. Some are ordered and others unordered. Create an Interface MyCollection which is maximum general (abstract) collection possible. (java oop)-> laboratory work

Solutions

Expert Solution

Collection :

A collection is an interface which has certain methods to be implemented by some java classes. It is a group of methods which has be performed by it's implementation classes.

It just has the overview of the methods that are needs to be implemented.

The collection interface is extended by List and Set interfaces.

List Interface :

In list interface , we can have duplicate elements.

Since , it is an interface , we cannot create it's objects directly.

ArrayList and LinkedList are the examples of these kind of implementations which extends the List interface (Parent class)

Set Interface :

In Set Interface , we cannot have duplicate elements.

There is no order in inserting elements in a set. That is elements in a set are Un-ordered . We cannot guarantee that , order in which we are inserting the elements , cannot be same as the order it displays the elements.

HashSet , LinkedHashSet are the examples of these kind of implementations which extends the Set interface(Parent class).

code example :

//importing the main class here

import java.util.*

//our class implementation starts here

public class CollectionExample {

//our main method starts here

public static void main(String args[]){

//creating a list with string values allowed in it  

ArrayList<String> list= new ArrayList<String>();

//here we are adding the list elements here

list.add("Hi");

list.add("Hello");

list.add("How");

//Created a iterator to get loop through the elements

Iterator<T> itr = list.iterator();

//while loop for displaying the elements

while(itr.hasNext()) {

// displaying the elements

System.out.println(itr.next())

}

}

}

//In the same way we can create Set interface related class and display elements.


Related Solutions

3. For the following collection of statements, describe the sets of actions, objects, and subjects; and...
3. For the following collection of statements, describe the sets of actions, objects, and subjects; and draw an access control matrix to represent the scenario. 1 Mark Alice can climb trees and eat apples. Bob can climb fences, eat apples, and wave flags. Trees can hurt apples. Carol can jump waves and wave flags.
Discuss the bag collection framework, which consists of the following classes: Indentation in this group represents...
Discuss the bag collection framework, which consists of the following classes: Indentation in this group represents interface implementaion: BagInterface ....ArrayBag ....LinkedBag Indentation in this group represents inheritance: AbstractCollection ....AbstractBag ........ArrayBag ............ArraySortedBag ........LinkedBag Where are the more general (abstract) classes? Where are the more specific (concrete) classes? What are the benefits of this organization? Does it have any detriments?
How many ways to group 75 objects into 3 groups if any number of objects can...
How many ways to group 75 objects into 3 groups if any number of objects can be in the 3 groups if each group must have 25 objects?
Complete the C++ class Triple below so that it represents a vector with 3 elements: (a,...
Complete the C++ class Triple below so that it represents a vector with 3 elements: (a, b, c) Most of these function bodies can be written in only a few lines. Error checking is not required. Test your class using the test.h file. The triple.cpp file is the code unit tested on submission. main.cpp #include #include #include #include "triple.h" #include "test.h" using namespace std; int main() { myTest(); return 0; } triple.h #ifndef TRIPLE_H #define TRIPLE_H #include #include using namespace...
Chapter 3 discusses social behavior, and some of the variables that allow humans to be “ultrasocial”...
Chapter 3 discusses social behavior, and some of the variables that allow humans to be “ultrasocial” (existing in vary large cooperative societies). Philosophically, think about this chapter in terms of the Social Contract, and what seems to be necessary in order to maintain the Social Contract (and we’ll discuss that more fully in class). The main idea that Haidt puts forth in this context is that reciprocity is key to upholding the Social Contract, and living socially. So after reading...
Question 4: (Marks: 3) The following table represents the percentage of teenagers in some selected countries...
Question 4: (Marks: 3) The following table represents the percentage of teenagers in some selected countries who have used marijuana and the percentage who have used other drugs. Percentage Who Have Used Country Marijuana x Other Illegal Drugs y Czech Republic 22 4 Denmark 17 3 England 40 21 Finland 5 1 Ireland 37 16 Italy 19 8 Northern Ireland 23 14 Norway 6 3 Portugal 7 3 Scotland 53 31 United States 34 24 Determine the correlation coefficient, rounded...
If Columbia's leading narco-insurgent group, the Revolutionary Armed Forces of Columbia (known by its Spanish acronym,...
If Columbia's leading narco-insurgent group, the Revolutionary Armed Forces of Columbia (known by its Spanish acronym, the FARC) were planning to attack the US homeland, how would it go about it? What are the major factors that would influence the type of attack the FARC would launch? Who and what would be the most likely targets?
The well-known Danish toy company Lego Group reported its first loss in 1998 since the 1930s....
The well-known Danish toy company Lego Group reported its first loss in 1998 since the 1930s. While its bright plastic bricks are famous around the globe, Lego is rapidly losing its market share to the computer and video games. The company’s President said, “The Lego Group is not in critical condition, but action is needed. We need to acknowledge that growth and innovation are not enough. We also have to be a profitable business.” Discuss the meaning of profitability with...
compare between Nitrogen and carbon cycles in: 1- bacteria names and its roles 2- elements 3-...
compare between Nitrogen and carbon cycles in: 1- bacteria names and its roles 2- elements 3- gases 4- aerobic and anaerobic conditions 5- beneficial of these cycles
Question 3 The Waterloo Group of Grantly and its investee companies Clo and Donte at 31...
Question 3 The Waterloo Group of Grantly and its investee companies Clo and Donte at 31 May 2020 are shown below: Draft Income Statements for the year ended 31 May 2020 Grantly Clo Donte R000 R000 R000 Revenue 1,138 488 149 Cost of sales (576) (214) (59) _____ _____ _____ Gross profit 562 274 90 Other operating expenses (138) (54) (40) _____ _____ _____ Profit from operations 424 220 50 Interest payable (38) (44) (14) _____ _____ _____ Profit before...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT