Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a Java program that will store data in the form of daily average temperatures for one week. Store the day and average temperature in

Develop a Java program that will store data in the form of daily average temperatures for one week. Store the day and average temperature in two different arrays. Your program should prompt the user for the day of the week (Monday through Sunday) and display both the day and temperature for each day. If "week" is entered, the output for your program should provide the temperature for each day and the weekly average. Use the looping and decision constructs in combination with the arrays to complete this assignment.

Here is what I have so far, but I get an error when trying to calculate the average:

import java.util.Scanner;

public class Project5Temperature {

public static void main(String[] args) { Scanner scnr = new Scanner(System.in); double average; System.out.print("How many days' temperatures? "); int days = scnr.nextInt(); //array to store day of week String[] day = new String [days]; // array to store days' temperatures int[] temperatures = new int[days]; int i; // read/store each day's temperature for (i = 0; i < days; ++i){ System.out.print("Enter day of week: "); day[i] = scnr.next(); System.out.println(day[i] + "'s temperature"); temperatures[i] = scnr.nextInt(); } for (i = 0; i < days; ++i){ System.out.println(day[i] + "'s temperature: " + temperatures[i]); } average = temperatures[i] / (double) days; System.out.print("Average temperature: "); System.out.printf("%.2f", average); } }

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

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions