Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

On the planet Dax there are 10 months, 30 days each month, and temperatures range from 0-200 degrees . Months have numbers (not names), and

On the planet Dax there are 10 months, 30 days each month, and temperatures range from 0-200 degrees . Months have numbers (not names), and so do days. So the first day of the year is Month 1, day 1 and the last day of the year is Month 10, day 30. You have been given an input file of 300 integers representing the temperatures for one year. The first 30 integers are for month 1, the next 30 for month 2 etc. They are in order. The first number is for Month 1 day 1, the second is for Month 1 day 2, the next for Month 1 day 3 etc. You are to put these numbers in a 2 dimensional array, then ask the user for a Month and day and output the temperature on that day.

import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner;

public class L19 {

public static void main(String[] args) { int [][]temp= getInput(); double av= findAverage(temp); System.out.println("The average temperature for the year was " + av); Scanner scan=new Scanner(System.in); System.out.println("If you tell me a month and a day I will tell you the temperature"); System.out.println("Which month (1-10)"); int month=scan.nextInt(); System.out.println("Which day (1-30)"); int day=scan.nextInt(); int dailyTemp=findTemp(temp, month, day); System.out.println("The temperature was " + dailyTemp); } public static int[][] getInput() { Scanner sc = new Scanner(System.in); try { sc = new Scanner(new BufferedInputStream(new FileInputStream("temps.txt")));// text file } catch (FileNotFoundException e) { System.out.println("File does not exist."); } //declare the array //input temps into the array //return the array } public static int findTemp(int[][]t, int m, int d) { //find and return the temp } public static double findAverage(int[][]t) { //find and return the average temp for the year } }

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

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions