Question

java ASAP Assume that you have tracked daily minutes of you work out for a week....

java ASAP Assume that you have tracked daily minutes of you work out for a week. Save the following data into a text file in a notepad. 50 10 36 11 47 30 Write a java program that reads the minutes for a week from the text file that you created. Read the minutes from the input file into the array in one execution of the program.write a java method to find out the maximum and minimum values. Your program should create an output file with the original array and maximum and minimum values.you must read the input file and store the hours to an array

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int arrLength = 5;
int min, max;
  
try
{
//read the input file
File file = new File("input.txt");
Scanner scanner = new Scanner(file);
min = max = scanner.nextInt();
int mints[] = new int[100];
  
for(int i=0; i<arrLength; i++)
{
mints[i] = scanner.nextInt();
}
  
//calculate the minimum and maximum of array
for(int i=0; i<arrLength; i++)
{
if(min>mints[i])
min = mints[i];
if(max<mints[i])
max = mints[i];
}

BufferedWriter bufferWriter = new BufferedWriter(new FileWriter("output.txt"));
  
//write the result into the output file
bufferWriter.write("Minimum = "+Integer.toString(min));
bufferWriter.write("\nMaximum = "+Integer.toString(max));
bufferWriter.close();
  
}
catch (IOException e)
{
System.out.println(e);
}
}
  
}

OUTPUT:

input.txt

output.txt

Add a comment
Know the answer?
Add Answer to:
java ASAP Assume that you have tracked daily minutes of you work out for a week....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and...

    IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and carb intake for a week. Prompt the user for 7 days of minutes walked and carb intake; store in the array.   Write a sort ( your choice which sort ) to report out the sorted minute values -lowest to highest. Write another to report out the sorted carb intake - highest to lowest. These methods MUST be your original code.   Your program should output...

  • In JAVA Create a program with an array with the following data: 50 12 31 76...

    In JAVA Create a program with an array with the following data: 50 12 31 76 5 23 15 Use a text file (.txt created in notepad) to read the data into the array. Write a sort method (your choice of sorting algorithm) to sort the array values values - highest to lowest. Write a method to determine the minimum value. Your program should call the sort and minimum methods. Output the sorted array and minimum value.  

  • Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month...

    Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month and stored in a file called temperature.txt. Write a complete C Language program that reads the stored temperatures, one at a time, from the file temperature.txt and converts the read temperature to its equivalent in Celsius. Your program should store each converted temperature in an output file called results.txt. Your program should find the average, the minimum, and the maximum temperatures in Celsius and...

  • IN JAVA. Write a program that reads a file (provided as attachment to this assignment) and...

    IN JAVA. Write a program that reads a file (provided as attachment to this assignment) and writes the file to a different file with line numbers inserted at the beginning of each line. For example if file input is: This is a test File output should be 1. This is a test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ BELOW FROM NOTEPAD FILE. This file contains lines of text to determine if you can properly read and write from a file.

  • Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month...

    Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month and stored in a file called temperature.txt. Write a complete C language program that reads the stored temperatures, one at a time, from the file temperature.txt and converts the read temperature to its equivalent in Celsius. Your program should store each converted temperature in an output file called results.txt. Your program should also find the average, the minimum, and the maximum temperatures in Celsius...

  • Java program The file enrollments.txt is a text file with each line containing a positive integer...

    Java program The file enrollments.txt is a text file with each line containing a positive integer that represents the enrollment in a section of CIS 103. The highest value is 36. Write a program to read the data from the file into an array, then calculate and display the number of sections, the average class size, the minimum class size, and the maximum class size. enrollments.txt 36 36 36 34 35 25 34 31 29 19 35 33 36 32...

  • Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this...

    Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this file, include your assignment documentation code block. After the documentation block, you will need several import statements. import java.util.Scanner; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; Next, declare the Lab12 class and define the main function. public class Lab12 { public static void main (String [] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare...

  • Could someone help me out here assignment due tonight. Thank you. Develop and run problem 03...

    Could someone help me out here assignment due tonight. Thank you. Develop and run problem 03 page 231. Make a function to output your results. Read the following data into your program from a text file that you make. (Use the following input data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, and 189.) Hint: to make a file use notepad++ input and...

  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a...

    in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a program that asks the user for an input file name, open, read ar number of students is not known. For each student there is a name and and display a letter grade for each student and the average test score fc • openFile: This method open and test the file, if file is not found and exit. Otherwise, return the opened file to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT