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
2. Which property is used for hiding text of the textbox?
Softa [21]

Answer:

password char

Explanation:

The password char property allows the text being written in the textbox to be hidden in the form of dots or stars. As such the user entering the password is secure, as no one nearby can know the password by watching the texts.

8 0
3 years ago
Which one of these do you need to become president of the US ?
gladu [14]

Answer:

Tbh i dont even know

Explanation:

I had who i wanted to become president but i don't even know anymore

7 0
2 years ago
Read 2 more answers
Question 6 Which of the following statements about datasets used in Machine Learning is NOT true? 1 point Testing data is data t
Inessa [10]

Answer:

Training data is used to fine-tune the algorithm’s parameters and evaluate how good the model is

Explanation:

The statement about datasets used in Machine Learning that is NOT true is "Training data is used to fine-tune algorithm’s parameters and evaluate how good the model is."

This is based on the fact that a Training dataset is a process in which a dataset model is trained for corresponding it essentially to fit the parameters.

Also, Testing the dataset is a process of examining the performance of the dataset. This refers to hidden data for which predictions are determined.

And Validation of dataset is a process in which results are verified to perfect the algorithm's details or parameters

4 0
3 years ago
Write a loop statement to count and display the number of positive integers in the array. That is, your loop should display the
dlinn [17]

Answer:

int count =0;

    for(int i=0;i<10;i++)

    {

        if(myArray[i]>=0)

        {

            count++;

        }

    }

    cout<<"Number of positive integers is "<<count<<endl;

Explanation:

The above written loop is for counting positive integers in the myArray[].

For counting we have taken a count integer initialized with 0.On iterating over the array if the element is greater than or equal to 0 we consider it as positive and increasing the count.At the end printing the count.

3 0
3 years ago
Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should have me
RSB [31]

Answer:

Explanation:

The code provided worked for the most part, it had some gramatical errors in when printing out the information as well as repeated values. I fixed and reorganized the printed information so that it is well formatted. The only thing that was missing from the code was the input validation to make sure that no negative values were passed. I added this within the getMonths() method so that it repeats the question until the user inputs a valid value. The program was tested and the output can be seen in the attached image below.

import java.io.*;

import java.util.*;

class Rainfall

{

   Scanner in = new Scanner(System.in);

   private int month = 12;

   private double total = 0;

   private double average;

   private double standard_deviation;

   private double largest;

   private double smallest;

   private double months[];

   public Rainfall()

   {

       months = new double[12];

   }

   public void setMonths()

   {

       for(int n=1; n <= month; n++)

       {

           int answer = 0;

           while (true) {

               System.out.println("Enter the rainfall (in inches) for month #" + n + ":" );

               answer = in.nextInt();

               if (answer > 0) {

                   months[n-1] = answer;

                   break;

               }

           }

       }

   }

   public void getTotal()

   {

       total = 0;

       for(int i = 0; i < 12; i++)

       {

           total = total + months[i];

       }

       System.out.println("The total rainfall for the year is " + total);

   }

   public void getAverage()

   {

       average = total/12;

       System.out.println("The average monthly rainfall is " + average);

   }

   public void getLargest()

   {

       double largest = 0;

       int largeind = 0;

       for(int i = 0; i < 12; i++)

       {

           if (months[i] > largest)

           {

               largest = months[i];

               largeind = i;

           }

       }

       System.out.println("The largest amount of rainfall was " + largest +

               " inches in month " + (largeind + 1));

   }

   public void getSmallest()

   {

       double smallest = Double.MAX_VALUE;

       int smallind = 0;

       for(int n = 0; n < month; n++)

       {

           if (months[n] < smallest)

           {

               smallest = months[n];

               smallind = n;

           }

       }

       System.out.println("The smallest amount of rainfall was " + smallest +

               " inches in month " + (smallind + 1));

   }

   public static void main(String[] args)

   {

       Rainfall r = new Rainfall();

       r.setMonths();

       r.getTotal();

       r.getSmallest();

       r.getLargest();

       r.getAverage();

   }

}

8 0
2 years ago
Other questions:
  • A brick weighs 26 N. Measured underwater, it weighs 11 N.
    10·1 answer
  • As yall know its spoopy season. This means spoopy music! I am having a live stream on the Spoon app under the username teendrago
    11·1 answer
  • Jason is working on a project that requires him to manage a huge amount of data. The spreadsheet he is working on has data relat
    12·1 answer
  • A four year old laptop will not boot and presents error messages on the screen
    8·1 answer
  • Match each invention with its effects on the age of exploration.
    6·2 answers
  • What are three softwares for cloud computing
    8·1 answer
  • It is possible to change the shape of a text box.
    10·1 answer
  • List at least 5 professions for people working in the Information/Communication<br> fields.
    10·1 answer
  • Please write a Java program to read movies.txt file. (It is in Modules under Chapter Code) Create your own movies.ser file from
    14·1 answer
  • A search expression entered in one search engine will yield the same results when entered in a different search engine.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!