Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You shall write a program that reads in an arbitrary number of data points from standard input, formatted as follows, where each value is separated

You shall write a program that reads in an arbitrary number of data points from standard input, formatted as follows, where each value is separated by whitespace:

Date (String)

Time (String)

Value (int)

For example, input data might look like this (the output from weather -t temp all | head -10):

2013-08-20 01:00:01 58 2013-08-20 01:05:02 58 2013-08-20 01:10:01 57 2013-08-20 01:15:02 57 2013-08-20 01:20:01 57 2013-08-20 01:25:02 57 2013-08-20 01:30:01 57 2013-08-20 01:35:01 57 2013-08-20 01:40:02 57 2013-08-20 01:45:01 57 

Your program shall determine the number of values, the maximum value, the minimum value, and the average value (to doubleprecision), along with the date and time at which the extreme values occurred, and print those data, formatted as in the examples below.

Further specifications and tips

Do not repeatedly create a Scanner object for reading from standard input. Create it once and reuse it.

You can simulate the end of standard input on the terminal by pressing Ctrl-D.

This also works in Eclipse's console on Mac or GNU/Linux.

On Windows (including in Eclipse on Windows), the equivalent is Ctrl-Z.

If you get stuck in a loop, Ctrl-C will usually kill the program.

Print the average value to two digits after the decimal point.

Your program need not account for unexpected/malformed input data.

Consider using the hasNext method of the Scanner class to control whether your program repeats the process of reading input.

You may assume that integer values will never be smaller than Integer.MIN_VALUE + 1 nor bigger than Integer.MAX_VALUE - 1.

If an extremum is not unique, opt for the date and time where the extremum is first encountered.

Include appropriate comments in your code, describing your approach.

Pseudocode for reading in the input might look something like this:

while Scanner hasNext() returns true: Read the date with Scanner's next() method Read the time with Scanner's next() method Read the value with Scanner's nextInt() method 

Example I/O

Possible sessions follow, describing expected I/O. Commands are also given, assuming the class containing the main method is named Assignment04. The values related to the output from the weather program are correct as of this writing, but correct output will change over time.

Command:

echo 'DummyDate1 DummyTime1 50 DummyDate2 DummyTime2 10 DummyDate3 DummyTime3 75' | java Assignment04 

Output:

Count: 3 Minimum: 10 @ DummyDate2 DummyTime2 Maximum: 75 @ DummyDate3 DummyTime3 Average: 45.00 

Command:

weather -t temp all | head -10 | java Assignment04 

Output:

Count: 10 Minimum: 57 @ 2013-08-20 01:10:01 Maximum: 58 @ 2013-08-20 01:00:01 Average: 57.20 

Command:

weather -t temp all | java Assignment04 

Output:

Count: 469724 Minimum: 28 @ 2013-12-09 05:40:01 Maximum: 103 @ 2017-09-02 16:45:02 Average: 57.15 

Command:

weather -t pressure all | java Assignment04 

Output:

Count: 469724 Minimum: 986 @ 2017-02-17 16:00:02 Maximum: 1034 @ 2017-01-27 08:05:01 Average: 1016.70 

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

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

2. How much time should be allocated to the focus group?

Answered: 1 week ago