Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is sampling independence?

Answered: 1 week ago

Question

What would you need to work on to become a wise leader?

Answered: 1 week ago