Write a class called set to represent a set as an arraylist

Assignment Help JAVA Programming
Reference no: EM131942348

Assignment

It is required to develop an application in Java to represent Set as a data structure using Java built-in class ArrayList.

(A) Write a class called Set to represent a set as an ArrayList and implement various set operations by using methods of class ArrayList. Assume that the elements of the set are integers.

This class will have the following instance variables: (a) an ArrayList object called list of type Integer, (b) length: the actual number of elements in the list.

This class will have thefollowing methods:

(1) Constructor without any parameter (default constructor), which uses a default value of 10 as capacity, creates ArrayListobjectlistand initializes length to 0.

(2) Constructor with parameter cap for capacity of the list. Create ArrayListobjectlistof capacity equal to parametercap and initialize length to 0.

(3) Constructor having an array of integers arras parameter. Create ArrayListobjectlist. Add theelementsof the array arrin the list. and initialize length to the length of the array arr.

(4) Instance method getLength, that returns length.

(5) Instance method isEmpty to determine whether the set is empty or not.

(6) Instance method addElement that accepts a parameter element of type int. It will insert the element in the list at the end and also increment length by one.

(7) Instance method isMember that accepts a parameter element of type int. If element exists in the list, it will return true, else it will return false.

(8) Instance method subSetthat accepts a parameteraSetof typeSet. If aSet is a subset of "this object", it will return true, else it will return false.

Ex: Let A and B be two sets;

A = {7, 4, 20, 15, 12}, B = {12, 15}. As all elements of B are contained in A, therefore, B is a subset of A.

(9) Instance method isEqualthat accepts a parameteraSetof typeSet. The method will return true, if aSet is equal to "this object", else it will return false. Two sets are equal, if they contain the same elements in any order.

Ex: Let A and B be two sets;

A = {7, 4, 20, 15, 12}, B = {4, 7, 12, 15, 20}. As sets A and B contain same elements, but in different order, therefore, they are equal.

(10) Instance method union having a parameter aSetof typeSet. The method finds the union of aSet with "this object" and returns the result as an object of type Set.

Ex: Let A = {10, 4, 20, 15, 12, 18}, B = {8, 10, 25, 15, 20},

C = A ∪ B = {10, 4, 20, 15, 12, 18, 8, 25}

(11) Instance method intersection having a parameter aSetof typeSet. The method finds the intersection of aSet with "this object" and returns the result as an object of type Set.

Ex: Let A = {10, 4, 20, 15, 12, 18}, B = {8, 10, 25, 15, 20},

C = A ∩ B = {10, 20, 15}.

(B) Write a class called SetApplication having only main method. Create objects of class type Setusing different constructors and call methods of class Set to test all functionalities of class Set.

Reference no: EM131942348

Questions Cloud

Approach apply to not-for profit organizations : Does the strategic planning approach apply to not-for profit organizations?
What are the tax consequences to george : The fair rental value of this office $1,300 per month. What are the tax consequences to George if he accepts Kramer's offer and moves his business locations
Describe the organizational structure of gm : Review the information concerning GM's handling of a safety issue and recall included in the "GM Ignition Switch Recall."
Recent change in the remote environment : Identify one recent change in the remote environment of U.S. Business and discuss its impact on an the Automobile Industry
Write a class called set to represent a set as an arraylist : Write a class called Set to represent a set as an ArrayList and implement various set operations by using methods of class ArrayList.
Benefits of the value chain analysis and resource : Compare and contrast the benefits of the Value Chain Analysis and Resource Based View methods of Internal Analysis. What challenges do you expect implementing?
Discuss how zara has developed capabilities : Discuss how Zara has developed capabilities that give it a competitive advantage.
Factors complicate environmental analysis : What factors complicate environmental analysis at the global level? Which factors are making such analysis easier?
Prepare the journal entry : If ABC's incremental borrowing rate is 14 percent and the lessor's implicit interest rate, which Rosemary is aware of, is 10 percent, Prepare the journal entry

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd