Question

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

Thursday = 50

Friday = 52

Saturday = 55

Sunday = 57

And the user enters "Monday" i need the output to display something like "The temperature for Monday will be: 50 degrees"

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class MonthTemparature {
  public static void main(String args[]){
    int arr[] = {50,55,52,50,52,55,57};
    double average = 0;
    for(int i = 0;i<arr.length;i++){
      average += arr[i];
    }
    average /= arr.length;

    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter day:");
    String s = scanner.nextLine();
    if(s.equalsIgnoreCase("monday")){
      System.out.println("The temperature for "+s+" will be: "+arr[0]+" degrees");
    }
    else if(s.equalsIgnoreCase("tuesday ")){
      System.out.println("The temperature for "+s+" will be: "+arr[1]+" degrees");
    }
    else if(s.equalsIgnoreCase("wednesday ")){
      System.out.println("The temperature for "+s+" will be: "+arr[2]+" degrees");
    }
    else if(s.equalsIgnoreCase("thursday ")){
      System.out.println("The temperature for "+s+" will be: "+arr[3]+" degrees");
    }
    else if(s.equalsIgnoreCase("friday ")){
      System.out.println("The temperature for "+s+" will be: "+arr[4]+" degrees");
    }
    else if(s.equalsIgnoreCase("saturday ")){
      System.out.println("The temperature for "+s+" will be: "+arr[5]+" degrees");
    }
    else if(s.equalsIgnoreCase("sunday ")){
      System.out.println("The temperature for "+s+" will be: "+arr[6]+" degrees");
    }
    else if(s.equalsIgnoreCase("week ")){
      System.out.println("The temperature for "+s+" will be: "+average+" degrees");
    }
  }
}
Add a comment
Know the answer?
Add Answer to:
I need to write a program in java using two array lists. I need to program...
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
  • Coding in C++ Write a program using structures to store the following weather information: - Month...

    Coding in C++ Write a program using structures to store the following weather information: - Month name - Day of month (Monday, Tuesday, etc) - High Temperature - Low Temperature - Rainfall for the day Use an the input.txt file to load the data into weather structures. Once the data for all the days is entered, the program should calculate and display the: - Total rainfall for the data - Average daily temperatures. (note: you'll need to calculate the days...

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

  • I have counted the number of statistics problems I do every day. The following data lists...

    I have counted the number of statistics problems I do every day. The following data lists the day of the week and how many problems I did on that day in the second column. The third column gives the percent of problems theory suggests I should have done. Sunday 25 0 Monday 102 20 Tuesday 87 10 Wednesday 122 20 Thursday 76 10 Friday 111 20 Saturday 50 20 Test if I followed the theory at α=10%

  • Write a php script that assigns the days of the week to an array named $days[]....

    Write a php script that assigns the days of the week to an array named $days[]. Use output statements to display "The days of the week in English are: " along with the values in the $days[ ] array. Following the output  statements, reassign the values in the $days[ ] array with the day of the week in French. Sunday is Dimanche, Monday is Lundi, Tuesday is Mardi. Wednesday is Mercredi. Thursday is Jeudi. Friday is Vendredi, and Saturday is Samedi....

  • week_days<- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") How do i write a line of code...

    week_days<- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") How do i write a line of code that will select the days Wednesday, Saturday, and Sunday in Rstudio?

  • PYTHON CODE First Code: Write a program that uses a text file to store the daysand...

    PYTHON CODE First Code: Write a program that uses a text file to store the daysand hours that a user worked in a week. The program should begin by prompting for the number of days worked in the week. It should continue with a loop for input of the days and hours and for writing these to the file, each on its own line. Sample Output (inputs shown in boldface) How many days did you work this week? 5 Enter...

  • Using the function you wrote in part 3a (refer to the bottom), write another function that, given the number of days in the month, and the day that the month starts on, the number of days that Inky Bl...

    Using the function you wrote in part 3a (refer to the bottom), write another function that, given the number of days in the month, and the day that the month starts on, the number of days that Inky Blinky Pinky and Clyde will get to play pinball in that month. The function provided will increment the day of the week to the next correct day. Function written in 3a): def pinball(dayOfWeek, dayOfMonth) : if dayOfMonth % 4 ==0: return "Pinky"...

  • What is the expected number of crimes reported on a Thursday?

     The table below lists the number of crimes reported at a police station on each day of the week for the past three months. Day of the WeekNumber of Crimes Monday Tuesday Wednesday Thursday Friday Saturday Sunday The null hypothesis for the goodness-of-fit test is that the number of crimes reported at this police station is the same for each day of the week. What is the expected number of crimes reported on a Thursday? 

  • Home U1 02 03 S1 S2 S3 S4 S5 4.1 4.2 4.3 4.4 4.5 4.6 4.7...

    Home U1 02 03 S1 S2 S3 S4 S5 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 Textbook - Help Your Task Write a function pairs(t) to display all pairs of consecutive items from a given tuple t ! Use the docstring Displays all pairs of consecutive items from tuple t""". Expected output: Monday Tuesday Tuesday Wednesday Wednesday Thursday Thursday Friday Friday Saturday Saturday Sunday C Subm Enclab V5.7.33 Predictive Da... Log 4.7 - Predict... Apps Work NCLab Virtual...

  • Use the given categorical data to construct the relative frequency distribution. Natural births randomly selected from...

    Use the given categorical data to construct the relative frequency distribution. Natural births randomly selected from four hospitals in a highly populated region occurred on the days of the week (in the order of Monday through Sunday) with the frequencies 52, 64, 72, 55, 58, 44, 55. 2 Does it appear that such births occur on the days of the week with equal frequency? Construct the relative frequency distribution. Day Relative Frequency Monday % Tuesday % Wednesday % Thursday %...

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