Question

In: Computer Science

This is my code I want the average temp for the week to be printed when...

This is my code

I want the average temp for the week to be printed when the user types : 'week'

currently when the user types  'week' it only prints  Monday - Sunday and the average temp for each day.


import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
public class weeklytemps {

   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
  
      
       ArrayList 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 without Capitalization
       System.out.println("Days of the week and Temperatures for each day");
       for(int i = 0; i < Day.size(); i++) {
           System.out.println(Day.get(i)+ " " + "-" + " " + Temperature.get(i));  
   }
       }
   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));

      
       }
   }
   }
   }

Solutions

Expert Solution


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));

           }
       }
   }
}


Related Solutions

Python I want to name my hero and my alien in my code how do I...
Python I want to name my hero and my alien in my code how do I do that: Keep in mind I don't want to change my code except to give the hero and alien a name import random class Hero:     def __init__(self,ammo,health):         self.ammo=ammo         self.health=health     def blast(self):         print("The Hero blasts an Alien!")         if self.ammo>0:             self.ammo-=1             return True         else:             print("Oh no! Hero is out of ammo.")             return False     def...
Below is my source code for file merging. when i run the code my merged file...
Below is my source code for file merging. when i run the code my merged file is blank and it never shows merging complete prompt. i dont see any errors or why my code would be causing this. i saved both files with male names and female names in the same location my source code is in as a rtf #include #include #include using namespace std; int main() { ifstream inFile1; ifstream inFile2; ofstream outFile1; int mClientNumber, fClientNumber; string mClientName;...
Here is my fibonacci code using pthreads. When I run the code, I am asked for...
Here is my fibonacci code using pthreads. When I run the code, I am asked for a number; however, when I enter in a number, I get my error message of "invalid character." ALSO, if I enter "55" as a number, my code automatically terminates to 0. I copied my code below. PLEASE HELP WITH THE ERROR!!! #include #include #include #include #include int shared_data[10000]; void *fibonacci_thread(void* params); void parent(int* numbers); int main() {    int numbers = 0; //user input....
JAVA: This is my code, but when it runs, for the "Average Score" output, it only...
JAVA: This is my code, but when it runs, for the "Average Score" output, it only gives me NaN. How can I fix that? import java.util.Scanner; public class prog4 { public static void main(String[] args) { Scanner reader = new Scanner(System.in); String name; double score; double minScore = 0; double maxScore = 0; int numberOfRecords = 0; double sum = 0; double average = sum / numberOfRecords; System.out.printf("%-15s %-15s %-15s\n", "Student#", "Name", "Score");           while (reader.hasNext()) { name...
How would I make it so that when I run my code it does not ask...
How would I make it so that when I run my code it does not ask for input (not having to enter after the statement and enter 0 for example) after ROXY (Forever ROXY Enterprises) appears? Like it would tell me the second statement right away along with the Roxy phrase. This is in C++. My code: #include / #include using std::endl; int main() {    void readAndConvert();    unsigned int stockSymbol;    unsigned int confNum;    std::cout << "ROXY...
I want to estimate the average money spent on Xmas toys each week in December.
            Confidence Intervals                                                      1.         I want to estimate the average money spent on Xmas toys each week in December. I take a             sample of 40 individuals and determine that the mean spent is $210 with a standard             deviation of $32.00             a.         For a 95% confidence interval, estimate the interval within which the true population                         would fall. b.         If I reduced the interval size to just 90%, what would that interval be? c.         For the 90% confidence interval, calculate the maximum error...
I want my answer typed.                                      I. What i
I want my answer typed.                                      I. What is presbyopia? Hyperopia? Myopia? 2. Which cranial nerves assesses eye function and acoustic function? 3. What is the Rinne test? Weber test? 4. Do you or anyone you know have any of the issues/symptoms/conditions mentioned in the video? Is it due to genetics or aging? How is it being managed?
Could you modify my code so it meets the following requirement? (Python Flask) I want the...
Could you modify my code so it meets the following requirement? (Python Flask) I want the user to register for account using email and password, then store that data into a text file. Then I want the data to be read when logging in allowing the user to go to home page. -------------Code-------------------- routes.py from flask import Flask, render_template, redirect, url_for, request, session import json, re app = Flask(__name__) '''@app.before_request def before_request(): if 'visited' not in session: return render_template("login.html") else:...
This is the code I have. My problem is my output includes ", 0" at the...
This is the code I have. My problem is my output includes ", 0" at the end and I want to exclude that. // File: main.cpp /*---------- BEGIN - DO NOT EDIT CODE ----------*/ #include <iostream> #include <fstream> #include <sstream> #include <iomanip> using namespace std; using index_t = int; using num_count_t = int; using isConnected_t = bool; using sum_t = int; const int MAX_SIZE = 100; // Global variable to be used to count the recursive calls. int recursiveCount =...
I want to know how to get the "temp" information from a API response like this...
I want to know how to get the "temp" information from a API response like this in javascript: { "coord": { "lon": -122.08, "lat": 37.39 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ], "base": "stations", "main": { "temp": 282.55, "feels_like": 281.86, "temp_min": 280.37, "temp_max": 284.26, "pressure": 1023, "humidity": 100 }, "visibility": 16093, "wind": { "speed": 1.5, "deg": 350 }, "clouds": { "all": 1 }, "dt": 1560350645, "sys": { "type": 1, "id": 5122, "message":...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT