bute: max an integer variable initialize to 10, static and final  Method signatures:  - public void add(int e) -> this method adds e in an array., e is not added in the array  if e already exists in the array. Attribute count in increment every successful add of e. - public void display( ) -> display the contents of the array (NOTE: the array is an attribute in the class later) - public int count( ) -> returns the value of count (NOTE: count is an attribute in the class later) - public boolean isElementOf(int e) -> returns true if e is in the array false if not - public int getElement(int index) -> returns the value in array at index - public Set union(Set s) -> returns the union      Example:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a java interface code class according to the instructions below:

1. Write an interface name InterfaceSet with the following components:

 Attribute: max an integer variable initialize to 10, static and final

 Method signatures:

 - public void add(int e) -> this method adds e in an array., e is not added in the array  if e already exists in the array. Attribute count in increment every successful add of e.

- public void display( ) -> display the contents of the array (NOTE: the array is an attribute in the class later)

- public int count( ) -> returns the value of count (NOTE: count is an attribute in the class later)

- public boolean isElementOf(int e) -> returns true if e is in the array false if not

- public int getElement(int index) -> returns the value in array at index

- public Set union(Set s) -> returns the union

     Example:

    current Object set[] ={1,2,3};

     Set s[] = {1,3,10,5};

    returns: Set union[]={1,2,3,10,5};

    NOTE: current object added first, then parameter Set s.

2. Write a class Set that implements interface InterfaceSet. Class Set has the following attributesset - an array of integer and an integer variable count. Default constructor must set the size of the array with the max variable from interface. A constructor that accepts an integer variable size and set the array size of attribute set array to size. 

NOTE: remove the public modifier in defining interface and class

Output results that should be seen:

Test Result

Set s1 = new Set();

s1.add(1);

s1.add(2);

s1.add(3);

s1.add(2);

s1.display();

1

2

3

Set s1 = new Set();

s1.add(10);

s1.add(12);

s1.add(13);

s1.add(14);

s1.add(15);

s1.add(17);

s1.add(16);

s1.add(18);

s1.add(20);

s1.add(21);

s1.add(22);

System.out.println("Count: "+s1.count());

s1.display();

Count: 10 10 12 13 14 15 17 16 18 20 21

Set s1 = new Set();

s1.add(1);

s1.add(2);

s1.add(3);

s1.add(6);

System.out.println(s1.isElementOf(2)); System.out.println(s1.isElementOf(10));

true

false

Set s1 = new Set();

Set s2 = new Set();

Set union = null;

s1.add(1);

s1.add(2);

s1.add(3);

s1.add(4);

s2.add(10);

s2.add(2);

s2.add(20);

union = s1.union(s2); union.display();

1

2

3

4

10

20

Set s1 = new Set();

s1.add(10);

s1.add(12);

s1.add(13);

s1.add(14);

s1.add(15);

]s1.add(17);

s1.add(16);

s1.add(18);

s1.add(20);

s1.add(21);

s1.add(22);

Set s2 = new Set();

s2.add(41);

s2.add(42);

s2.add(43);

s2.add(44);

s2.add(45);

s2.add(46);

s2.add(47);

s2.add(48);

s2.add(49);

s2.add(50);

Set union = s1.union(s2); union.display();

10

12

13

14

15

17

16

18

20

21

41

42

43

44

45

46

47

48

49

50

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education