1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svetlana [45]
3 years ago
12

Reimplement StringSet with the exception that it should now extend ArrayList instead of encapsulating a String[]. You can easily

abolish the 10 String limit for this new StringSet. You can also remove the int instance variable, as your class will no longer need it. Your existing StringSetTester should work with the new StringSet without being changed. Hint: What type of elements did the original StringSet store? What type of elements will be inserted into our ArrayList superclass? How can we tell Java that our ArrayList will be storing that type of element?
Computers and Technology
1 answer:
kolbaska11 [484]3 years ago
4 0

Answer:

Here is the program for the given question

Explanation:

class StringSet

{

ArrayList<String> arraylist; //a reference variable of ArrayList of generic type String

//A no argument constructor.

public StringSet()

{

arraylist=new ArrayList<String>(); //instantiating the ArrayList object

}

//A mutator that adds a String newStr to the StringSet object.

void add(String newStr)

{

arraylist.add(newStr); // add(String) method to add string to the arraylist

}

//An accessor that returns the number of String objects that have been added to this StringSet object.

int size()

{

return arraylist.size(); // size() method which gives the number of elements in the list

}

//An accessor that returns the total number of characters in all of the Strings that have been added to this StringSet object.

int numChars()

{

int sum = 0;

for(String str:arraylist) //for-each loop; can be read as for each string in arraylist

{

sum+=str.length();

}

 

return sum;

}

//An accessor that returns the number of Strings in the StringSet object that have exactly len characters.

int countStrings(int len)

{

int count = 0;

for(String str:arraylist)

{

if(str.length() == len)

count++;

}

return count;

}

}

You might be interested in
Which web browser was created by Google?
Natali5045456 [20]

Answer:

Chrome

Explanation:

6 0
3 years ago
Read 2 more answers
give an example of a technical issue you were not able to resolve on your first attempt. What troubleshooting steps did you take
erastovalidia [21]
One technical issue I had was on Windows 8.1, with the charm menu not working. The troubleshooting steps to fix it was I did CTRL+SHIFT+ESC to open task manager. I then found Windows Explorer and clicked "Reload." Then everything was fine.

Hope This Helped!
6 0
3 years ago
Out-of-order instruction execution can cause problems because a later instruction may depend on the results from an earlier inst
scoundrel [369]

Answer:

C

Explanation:

6 0
2 years ago
What is the benefit of making an archive folder visible in the Outlook folder list?
Rufina [12.5K]

Answer:

a

Explanation:

5 0
2 years ago
Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less th
Burka [1]

Answer:

// This program is written in C++

// Comments are used for explanatory purpose

// Program starts here

#include<iostream.h>

#include<stdlib.h>

int main()

{

// Declare variables

int num, selectno;

string status;

randomize();

//Generate random number;

num=rand()%10000;

// Prompt to guess a number

cout<<"You have only 10 tries\nTake a guess: ";

int tries = 0;

while (tries != 10)

{

cin>>selectno;

if(selectno == num){

cout<<"You passed at the "<<count+1<<" attempt";

tries = 10;

}

else

{

cout<<"You failed. Take another guess\n You have "<<10 - count + 1 <<" attempts";

}

tries++;

if(tries >= 10)

{

break;

}

}

return 0;

}

8 0
3 years ago
Other questions:
  • You're trying to decide which disk technology to use on your new server. the server will be in heavy use around the clock every
    10·1 answer
  • What Is the output of the following: =OR (5 &lt;7, 16*Rand ()&gt;23,FALSE)
    5·1 answer
  • How to reply to text from unknown number?
    11·1 answer
  • A lever has an effort arm that is 8 meters long and the residence (load) arm that is 1.5 meters long, how much effort is needed
    7·1 answer
  • Select one of the following strategies: active listening, sandwich technique, constructive feedback. in 2-5 paragraphs, define a
    11·1 answer
  • How might a company go about performing a load test on their website?
    7·1 answer
  • Should the use of hacktivists by a country against enemy organizations be considered an act of war? Why or why not? How about th
    8·1 answer
  • Explain what a datalist element does and is used for.
    12·1 answer
  • What is the advantage of entering metadata for electronic records that you create
    7·1 answer
  • Consider a game that is searched using random restart hill climbing strategy. Assume that the success rate for the game is 25%.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!