17.5k views
5 votes
The common field cricket chirps in direct proportion to the current tem­perature. Adding 40 to the number of times a cricket chirps in a minute, then dividing by 4, gives us the temperature (in Fahrenheit degrees). Write a program that accepts as input the number of cricket chirps in fifteen seconds, then outputs the current temperature

1 Answer

4 votes

Answer:

This program is written in Java programming language;

First, you should understand that:

The formula given in the question implies that the current temperature can only be calculated using measurement of time in minutes;

Given that the number of chirps is directly proportional to the temperature.

If the cricket made n chirps in 15 seconds, it will make n * (60/15) chirps in 1 minutes;

n * (60/15) = n * 4

Base on this analysis, the program is as follows

import java.util.*;

public class cricket

{

public static void main(String []args)

{

//Declare number of chips in 1 minutes

int num;

Scanner input = new Scanner(System.in);

//Prompt user for input

System.out.print("Number of chirps (in 15 seconds): ");

num = input.nextInt();

//Calculate temperature (multiply temperature by 4 to get number of chirps in minutes

double temp = (num * 4+ 40)/4;

//Print temperature

System.out.print("Current Temperature = "+temp+" F");

}

}

User KeithB
by
6.9k points