Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve it by JAVA please. PLEASE DON'T COPY FROM SOMEONE ELSE'S WORK. IF YOU DON'T KNOW HOW TO DO IT. DON'T DO IT. THANKS

Please solve it by JAVA please.

PLEASE DON'T COPY FROM SOMEONE ELSE'S WORK. IF YOU DON'T KNOW HOW TO DO IT. DON'T DO IT.

THANKS

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_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

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

More Books

Students also viewed these Databases questions

Question

Find the length of (3e t 3, 4e t + 7) for 0 t 1.

Answered: 1 week ago