Question: Java programming problem In this problem you will implement a program that counts the number of distinct strings that are streamed by it. For example,

Java programming problem

Java programming problem In this problem you will implement a program that

In this problem you will implement a program that counts the number of distinct strings that are streamed by it. For example, if your program sees the following strings (one per line): Bravo Alfa Charlie Kilo Charlie Alfa Bravo Then it should, ideally, output 4 , corresponding to the four different strings that it saw (Alfa, Bravo, Charlie, Kilo ). The catch is that your program only has access to a fixed amount of memory. More technically, you are to design and implement a class myDistinctCounter that extends DistinctCounter in the code on the hw1p1 repository page. Your class should have: a constructor that takes in a memory size and constructs a new object; a constructor that takes in a byte array of state and constructs an object with that state; an overridden method saw (String newElement) which records that you have seen a new string within your object's state; an overridden method numDistinct() which returns a guess of the number of distinct strings that your object has seen. To test your counter, I will create a new object and call saw on a variety of Strings. Then I will create a new counter with the same state as your previous counter (so that any memory that is not part of the state is lost), and ask for the number of distinct elements that this counter represents. In this problem you will implement a program that counts the number of distinct strings that are streamed by it. For example, if your program sees the following strings (one per line): Bravo Alfa Charlie Kilo Charlie Alfa Bravo Then it should, ideally, output 4 , corresponding to the four different strings that it saw (Alfa, Bravo, Charlie, Kilo ). The catch is that your program only has access to a fixed amount of memory. More technically, you are to design and implement a class myDistinctCounter that extends DistinctCounter in the code on the hw1p1 repository page. Your class should have: a constructor that takes in a memory size and constructs a new object; a constructor that takes in a byte array of state and constructs an object with that state; an overridden method saw (String newElement) which records that you have seen a new string within your object's state; an overridden method numDistinct() which returns a guess of the number of distinct strings that your object has seen. To test your counter, I will create a new object and call saw on a variety of Strings. Then I will create a new counter with the same state as your previous counter (so that any memory that is not part of the state is lost), and ask for the number of distinct elements that this counter represents

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!