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

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

CREATE A JAVA PROGRAM (SEE ATTACHED PHOTOS 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
attributes: set - 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
Transcribed Image Text: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 attributes: set - 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
For example:
Test
Result
Set sl = new Set ();
1
s1.add (1);
s1.add (2) ;
s1.add (3);
s1.add (2);
s1.display ();
Set s1 =
new Set ();
Count: 10
s1.add (10);
10
s1.add (12);
12
sl.add (13);
13
s1.add (14);
14
s1.add (15);
15
s1.add (17);
17
s1.add (16) ;
16
s1.add (18);
18
s1.add (20) ;
20
s1.add (21);
21
s1.add (22);
System.out.println ("Count: "+s1.count ());
s1.display ();
Transcribed Image Text:For example: Test Result Set sl = new Set (); 1 s1.add (1); s1.add (2) ; s1.add (3); s1.add (2); s1.display (); Set s1 = new Set (); Count: 10 s1.add (10); 10 s1.add (12); 12 sl.add (13); 13 s1.add (14); 14 s1.add (15); 15 s1.add (17); 17 s1.add (16) ; 16 s1.add (18); 18 s1.add (20) ; 20 s1.add (21); 21 s1.add (22); System.out.println ("Count: "+s1.count ()); s1.display ();
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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