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

this is my code I want the opposite i want to convert a postfix expression to...
this is my code I want the opposite i want to convert a postfix expression to infix expression #include <iostream> #include <string> #define SIZE 50 using namespace std; // structure to represent a stack struct Stack {   char s[SIZE];   int top; }; void push(Stack *st, char c) {   st->top++;   st->s[st->top] = c; } char pop(Stack *st) {   char c = st->s[st->top];   st->top--;   //(A+B)*(C+D)   return c; } /* function to check whether a character is an operator or not. this function...
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...
My code is supposed to display a stacked bar chart of my average week. Can you...
My code is supposed to display a stacked bar chart of my average week. Can you help me locate my errors and fix them? I'm just so confused <!DOCTYPE html> <html lang = "en"> <head> <meta charset="UTF-8" /> <title>Assignment 3: My Weekly Schedule</title> <script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> <style type="text/css"> svg { font: 10px sans-serif; shape-rendering: crispEdges; } .axis path, .axis line{ fill: none; stroke: #000; } path.domain { stroke: none; } .y .tick line{ stroke: #ddd; } </style> </head> <body> <script...
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;...
My code is working fine but after selecting an option and at the end I want...
My code is working fine but after selecting an option and at the end I want user could enter another option again without going back to menu. However, in my code when I enter another option, it prints the whole menu again then I can select option.Could anyone help me on that? #include "stdafx.h" #include #include #include using namespace std; const double pi = 3.14159265358979323846; const double deg_to_rad = (pi / 180); int main() { int option; do { cout...
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...
(Python) This is my code for printing a roster for a team. When I print to...
(Python) This is my code for printing a roster for a team. When I print to the console, it makes the first player's name show up as number 2, and it says [] (its just blank for 1). How can I fix that so the first player's name is 1, not skipping 1 and going to 2. def file_to_dictionary(rosterFile): myDictionary={} myDict=[]    with open(rosterFile,'r') as f: for line in f:    (num,first,last,position)=line.split() myDictionary[num]= myDict myDict=[first, last, position] print (myDictionary) return...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT