Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You shall write a program that reads in an arbitrary number of data points from

ID: 3723878 • Letter: Y

Question

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):

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:

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:

Output:

Command:

Output:

Command:

Output:

Command:

Output:

Explanation / Answer

JAVA PROGRAMME :

import java.util.Scanner;

public class Assignment04 {

public static void main(String[] args) {

Scanner scn=new Scanner(System.in);

int index=0;

int mini=Integer.MAX_VALUE;

int maxi=Integer.MIN_VALUE;

String mini_date="",mini_time="",maxi_date="",maxi_time="";

double sum=0;

System.out.println("Enter the input");

while(scn.hasNext()) {

String date=scn.next();

String time=scn.next();

int value=scn.nextInt();

index++;

//System.out.println(index);

if(value>maxi) {

maxi=value;

maxi_date=date;

maxi_time=time;

}

if(value<mini) {

mini=value;

mini_date=date;

mini_time=time;

}

sum+=value;

}

scn.close();

double avg=sum/index;

int temp=(int)(avg*100);

avg=(temp)/100.0;

System.out.println("Output: Count: "+index+" Minimum: "+mini+" @ "+mini_date+" "+mini_time+" Maximum: "+maxi+" @ "+

maxi_date+" "+maxi_time+" Average: "+avg);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote