Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve it by JAVA please. Now, write a class named InputSplitter. This class will take input from the keyboard (using a Scanner) and split

Please solve it by JAVA please.

Now, write a class named InputSplitter. This class will take input from the keyboard (using a Scanner) and split the incoming tokens into integers, floating point numbers, and strings. The incoming tokens will be added to one of three accumulators which start out at zero, and which keep a running total.

Thus, the class will have an accumulator for integers. It starts out with the value zero. Every time another integer is read in, it is added to the integer accumulator. The accumulator keeps a running total of all the integers which have been seen so far. Likewise, there is an accumulator for floating point values. It starts at zero, but adds every floating point value which is seen. Finally, there is a string accumulator. It starts out as an empty string, but appends to the string every time another string token is read. Your class will need to be able to decide the type of each input token (hint: a Scanner has the methods hasNextInt(), hasNextDouble(), and hasNext()) as well as to keep track of the running totals (hint: you can use instance variables).

The only import statement you may use in this implementation is the Scanner class. Any data elements should be declared private, although this will not be graded. If you think it is necessary you may include helper methods of your own. The class should implement the following public methods:

  • public InputSplitter() this constructor will initialize the three accumulators as well as the Scanner which is used for input.
  • public void next() read the next token, and print its type and value. This method will use the input Scanner object which was initialized earlier to read the next token from the input. Depending on the type of the input token, method will print the value of the token in one of the following three formats:
  • In addition to the printed output, the value will be added (appended, in the case of a string) to the accumulator for the specific type.
  • public int getIntTotal() retrieves the total value summed in the integer accumulator.
  • public double getDoubleTotal() retrieves the total value summed in the floating point accumulator.
  • public String getStringTotal() retrieves the complete value concatenated in the string accumulater.
  • public String toString() returns the current contents of each of the three accumulators as a single string in the following format

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions