bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 7, Problem 1E

Write a program in a class NumberAboveAverage that counts the number of days that the temperature is above average. Read ten temperatures from the keyboard and place them in an array. Compute the average temperature and then count and display the number of days on which the temperature was above average.

Expert Solution & Answer
Check Mark
Program Plan Intro

“NumberAboveAverage” class

Program Plan:

“NumberAboveAverage.java”:

  • • Define “NumberAboveAverage” class.
    • ○ Define main function.
      • ■ Declare an array “temperature” in “double” base type.
      • ■ Create an object for scanner class.
      • ■ Display prompt statement.
      • ■ Read ten temperature from user using “for” loop.
        • • Display prompt statement for each temperature.
        • • Read temperature one by one from user.
      • ■ Initializes total temperature “total_temp” to “0.0”.
      • ■ Compute sum of all temperature using “for” loop.
        • • The sum is computed by using “total_temp += temperature[i];”
      • ■ The average temperature is computed by using “total_temp/10” and it is stored to a variable “tempAverage”.
      • ■ Display average temperature.
      • ■ Initializes the day count “dayCount” to “0”.
      • ■ Using “for” loop, compute which day has above average.
        • • If temperature is greater than average temperature, then increment the day count.
        • • Display the day which has above average temperature.
      • ■ Finally display total number of days has above temperature.
Program Description Answer

The below java program is used to counts the number of days that the temperature is above the average of temperature.

Explanation of Solution

Program:

Filename: “NumberAboveAverage.java”

//Import required package

import java.util.Scanner;

//Define "NumberAboveAverage" class

public class NumberAboveAverage

{

    //Define main function

    public static void main(String[] args)

    {

        //Declare an array for temperature

        double[] temperature = new double[10];

        //Create object for scanner class

        Scanner reader = new Scanner(System.in);

        //Display prompt statement

System.out.println("Please enter the values of ten temperature");

//Read ten temperatures from user using "for" loop

        for(int i = 0; i < 10; i++)

        {

            //Prompt statement for temperature

System.out.print("Enter temperature for Day " + i + " is: ");

            //Read temperature one by one from user

            temperature[i] = reader.nextDouble();

        }

        //Initializes total temperature to "0".

        double total_temp = 0.0;

//Compute sum of all temperature using "for" loop

        for(int i = 0; i < 10; i++)

        {

            total_temp += temperature[i];

        }

        //Compute the average temperature to "0"

        double tempAverage = total_temp/10;

        //Display average temperature

System.out.println("The average temperature is: " + tempAverage);

        //Initializes the day count to "0"

        int dayCount = 0;

//Using "for" loop, compute which day has above average

        for(int i = 0; i < 10; i++)

        {

/* If temperature is greater than average temperature, then */

            if( temperature[i] > tempAverage)

            {

                //Increment the day count

                dayCount++;

//Display the day which has above average temperature

System.out.println("Day " + i + " had temperature " + temperature[i] + " which was above average");               

            }

        }     

//Finally display total number of days has above temperature

System.out.println("The number of days with a temperature above average is: " + dayCount);

    }

}

Sample Output

Output:

Please enter the values of ten temperature

Enter temperature for Day 0 is: 10

Enter temperature for Day 1 is: 40

Enter temperature for Day 2 is: 15

Enter temperature for Day 3 is: 80

Enter temperature for Day 4 is: 42

Enter temperature for Day 5 is: 28

Enter temperature for Day 6 is: 48

Enter temperature for Day 7 is: 12

Enter temperature for Day 8 is: 30

Enter temperature for Day 9 is: 84

The average temperature is: 38.9

Day 1 had temperature 40.0 which was above average

Day 3 had temperature 80.0 which was above average

Day 4 had temperature 42.0 which was above average

Day 6 had temperature 48.0 which was above average

Day 9 had temperature 84.0 which was above average

The number of days with a temperature above average is: 5

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Use a simple exponential smoothing Method to forecast one-quarter-ahead revenues for Home Depot. Refer to the Home Depot Quarterly.xlsx dataset Year and Quarter Homedepot sales 19811 8.010999978 19812 10.60699999 19813 13.71499997 19814 19.20899999 19821 25.60999996 19822 33.06299996 19823 28.727 19824 30.24599999 19831 42.99299991 19832 66.61299992 19833 64.08299995 19834 82.49499989 19841 95.87199998 19842 119.0679998 19843 100.4589999 19844 117.3799999 19851 145.0479999 19852 174.2389998 19853 177.7179999 19854 203.724 19861 222.619 19862 263.4329996 19863 251.5369997 19864 273.8729992 19871 333.9689999 19872 381.4429998 19873 364.2449999 19874 374 19881 446.5919991 19882 518.1589985 19883 509.9899998 19884 524.7729988 19891 641.5209999 19892 704.0249996 19893 699.7399998 19894 713.2489986 19901 880.855999 19902 990.3459988 19903 936.6119995 19904 1007.542 19911 1186.889999 19912 1352.792 19913…
Write the set of SQL commands necessary to insert the data into the INVOICE table you created in Problem 17, as illustrated in Figure P8.16.
Refer to the shampoo_sales.xlsx time-series dataset. This data shows sales of shampoo over three years monthly. Carry out simple exponential smoothing and Holt's Trend-Corrected on this data and determine whether the data shows any trend. Assume the initial value for the level smoothing parameter (alpha) and Trend smoothing parameter (gamma) is 0.5 Month Sales of shampoo over a three year period 1-Jan 266 1-Feb 145.9 1-Mar 183.1 1-Apr 119.3 1-May 180.3 1-Jun 168.5 1-Jul 231.8 1-Aug 224.5 1-Sep 192.8 1-Oct 122.9 1-Nov 336.5 1-Dec 185.9 2-Jan 194.3 2-Feb 149.5 2-Mar 210.1 2-Apr 273.3 2-May 191.4 2-Jun 287 2-Jul 226 2-Aug 303.6 2-Sep 289.9 2-Oct 421.6 2-Nov 264.5 2-Dec 342.3 3-Jan 339.7 3-Feb 440.4 3-Mar 315.9 3-Apr 439.3 3-May 401.3 3-Jun 437.4 3-Jul 575.5 3-Aug 407.6 3-Sep 682 3-Oct 475.3 3-Nov 581.3 3-Dec 646.9

Chapter 7 Solutions

Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)

Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License