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.

I'm stuck on the "If 'week' is entered, the output for your program should provide the temperature for each day and the weekly average.

Here is what I have so far:

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; int sum = 0; // 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(); sum += temperatures[i]; }

for (i = 0; i < days; ++i){ System.out.println(day[i] + "'s temperature: " + temperatures[i]); } average = sum / (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

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

=+ Can you briefly outline a way in which it could be tested?

Answered: 1 week ago