Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M92781004

Have any Question?


Related Questions in Java

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As