Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a Java class that takes a text file as input, and is able to calculate the average, minimum and maximum values for one

Please write a Java class that takes a text file as input, and is able to calculate the average, minimum and maximum values for one column in that input text file. You should print out the average, minimum and maximum values of that data to a text file.

I can't upload my txt file but if you can make a txt file on your computer called Expenditure.txt with the following data

Jan,108 Feb,167 March,104 April,132 May,201 June,177 July,185 August,150 September,103 October,114 November,121 December,145

Here are some notes from class:

import java.io.*; import java.util.*; public class OutputFile { public static void main(String[] args) { try { double avg = 3.4; double min = 1.2; double max = 5.4; PrintWriter writer = new PrintWriter(new FileWriter("out.txt")); writer.println("Here is the average of my data: "+ avg); writer.println("Here is the min of my data: "+ min); writer.println("Here is the max of my data: "+ max); writer.close(); } catch (IOException e) { System.out.println("Oops. Java could not push my data to the file"); e.printStackTrace(); } } }

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

Students also viewed these Databases questions

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago