Question

Develop a Java program that will store data in the form of daily average temperatures for...

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 arraylists. 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.

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class weeklytemps {

   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);

       ArrayList<String> Day = new ArrayList(
               Arrays.asList("Monday", "Tuesday", "Wednesday", "Thurday", "Friday", "Saturday", "Sunday")); // Stores
                                                                                                               // days
                                                                                                               // of
                                                                                                               // the
                                                                                                               // week

       ArrayList Temperature = new ArrayList(Arrays.asList( // Stores
                                                               // temperature
                                                               // of each day
                                                               // of the week
               74, 85, 93, 84, 78, 89, 92));

       System.out.print("Please enter a day of the week or enter 'week' for each days tempature:");
       Scanner sc = new Scanner(System.in); // Allows user to enter day of week
       String Dayinput = sc.next();

       if (Dayinput.equalsIgnoreCase("week") || Dayinput.equalsIgnoreCase("Week")) { // Allows
                                                                                       // for
                                                                                       // user
                                                                                       // input
                                                                                       // with
                                                                                       // or
           int average=0;                                                                       // without
                                                                                       // Capitalization
           System.out.println("Days of the week and Temperatures for each day");
           for (int i = 0; i < Day.size(); i++) {
               //finding sum of temps
               average=average+(Integer)Temperature.get(i);
               System.out.println(Day.get(i) + " " + "-" + " " + Temperature.get(i));
           }
           //printing average temp
           System.out.println("Average temparature: "+(average/7.0));
       } else { // Allows for individual days of week to be printed
           System.out.println("Day of week and Temperature of the day ");
           for (int i = 0; i < Day.size(); i++) {
               if (Day.get(i).equalsIgnoreCase(Dayinput))
                   System.out.println(Day.get(i) + " " + Temperature.get(i));

           }
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
Develop a Java program that will store data in the form of daily average temperatures for...
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
  • I need to write a program in java using two array lists. I need to program...

    I need to write a program in java using two array lists. I need to program to prompt the user to enter a day of the week and return an output of a predetermined temperature for the day they selected. I also need the program the output the average of daily temperatures across the week if the user inputs "week". So basically if i set the temperatures to something arbitrary i.e.: Monday = 50 Tuesday = 55 Wednesday = 52...

  • 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...

  • Write a phython program that accepts six (6) daily temperatures, in Fahrenheit, for a typical October...

    Write a phython program that accepts six (6) daily temperatures, in Fahrenheit, for a typical October day this year. The program should also request the town or city and state names of where these temperatures were recorded in. The program should determine the average temperature of this ‘typical’ day then calculate the average October daily temperature in five years assuming that the temperature will rise by a total of 4.5% in those five years. The program will print in a...

  • Python 3 coding with AWS/IDLE. DDI&T a Python program to input, store, and process hourly temperatures for each hour...

    Python 3 coding with AWS/IDLE. DDI&T a Python program to input, store, and process hourly temperatures for each hour of the day (i.e., 24 temperatures). Your program should be divided logically into the following parts: In function main() declare an empty List container:          HourlyTemperatures = []     Pass the empty HourlyTemperatures list to a function, GetTemperatures(HourlyTemperatures)          This function must interactively prompt for and input temperatures for each of the 24 hours in a day (0 through 23). For each temperature that...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • Programming problem: Input Fahrenheit temperatures, storing them in an array, then display a table of those...

    Programming problem: Input Fahrenheit temperatures, storing them in an array, then display a table of those temperatures along with their Celsius equivalents. Do this as a modification of A06 if you wish, but 1. One temperature at a time, prompt for and input a record of 10 daily temperatures in Fahrenheit. 2. After that record has been input, use a second counting loop to display a table of data in which: at minimum: Use a counting loop. Store these values...

  • Code in Java and implement (source code) a program (name it WeeklyHours) to compute the total...

    Code in Java and implement (source code) a program (name it WeeklyHours) to compute the total weekly hours for 3 employees. The program main method defines a two-dimensional array of size 3x7 to store employers’ daily hours for the week. Each row represents one employee and each column represent one day of the week such that column 0 designates Monday, column 1 designates Tuesday, etc. The program main method populates the array with random numbers between 0 and 10 and...

  • Pseudocode please Special Problem for Swap A local zoo wants to keep track of how many...

    Pseudocode please Special Problem for Swap A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 x 7 array, where each row represents a different monkey and each column represents a different day of the week. The monkeys are represented by integers 1, 2, and 3; the weekdays are "Sunday" "Monday" "Tuesday". "Wednesday. Thursday"....

  • Need this program ASAP C++ language 1b. Write the implementation file timeClock.cpp for the class TimeClock....

    Need this program ASAP C++ language 1b. Write the implementation file timeClock.cpp for the class TimeClock. Com pile the file, and save it in the Chap 13 folder of your Student Data Files. 1c. Write a C++ program named weeklyPay.cpp to test your class Timeclock Your program should ask the user how many hours the user worked each day of the week. An object should be created for each day of the week with the number of hours for each...

  • Write a program that uses a two-dimensional array to store daily minutes walked and protein intake...

    Write a program that uses a two-dimensional array to store daily minutes walked and protein intake for a week. Prompt the user for 7 days of minutes exercise and protein intake; store in the array. Write a bubble sort to report out the sorted minutes walked values -lowest to highest. Write another to report out the sorted protein intake - highest to lowest. Your program should output all the values stored in the array and then output the 2 sorted...

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