Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Lab 10: Text Files

flamenca91
flamenca91 


Exercise 1 1. Create a New Project named TextFileExample. 2. Declare and instantiate a two-dimensional int array called temperatures which contains four rows (corresponding to weeks) and seven columns (corresponding to days). Read the temperature data from a file called TemperatureData.txt that you will download from Blackboard. Write a nested for loop that prints out the values of the temperature data. The output will appear as follows: Temperature Data Week 1: 73 71 68 69 75 77 78 Week 2: 76 73 72 72 75 79 76 Week 3: 79 82 84 84 81 78 78 Week 4: 75 72 68 69 65 63 65 Attachments
Tags Clarifications

Answers

Java - Temperature Data - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - Temperature Data assignment including source and comments Attachments
TemperatureFileReader.zip (1 K) Download
Preview
= 0; week < temps.length; week++){ //loop through days for(int day = 0; day<temps[week].length; day++){ //set value in array temps[week][day] = fileReader.nextInt(); } } //loop through weeks for(int week = 0; week < temps.length; week++){ //display week

Preview
69 75 77 78 76 73 72 72

Screenshots
Purchase Answer

Solution

mariobeka
mariobeka 



Below you will find the TextFileExample class and the .txt file I used to make the solution. A screenshot of the executed program is also provided. Attachments
TextFileExample.java (1 K) Download Preview
{ for (int i = 0; i < 4; i++) { counter = counter + 1; for (int m = 0; m < 7; m++) { temperatures[i][m] = scan.nextInt(); } } } // Print the weeks for (int i = 0; i < 4; i++) { System.out.println("Week " +

TemperatureData.txt (1 K) Download
Screen Shot 2014-04-29 at 12.31.40 AM.png (22 K) Download Preview

Screenshots
Screenshot
Purchase Answer