Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a temperature sensor simulator. First, display a menu that will ask the u

ID: 3549772 • Letter: C

Question

create a temperature sensor simulator. First, display a menu that will ask the user what season to simulate (1) winter (2) spring (3) summer (4) fall or (5) to exit. Once the use selects the season your program should ask the user how many simulations to generate. Each simulation will produce a random numbers as follows: for winter a number between 20-40, for spring between 40-70, for summer between 70-90, and for fall between 40-60. For each iteration keep track of the following statistics:


1- First temperature generated

2- Last temperature generated

3- Lowest temperature generated

4- Highest temperature generated

5- Total sum of all temperatures generated

6- Average for the season


Display these results to the user. Show the menu again until the user decides to exit.


Can you write a quick java code that will run this program

Explanation / Answer


import java.util.Random;

import java.util.Scanner;


public class Simulation

{

public static void simulate(int numofsim,int range, int end)

{

Random ran = new Random();

int firstTemp;

int temp;

int lastTemp;

int lowestTemp;

int highestTemp;

int sumTemp = 0;

int averageTemp = 0;

  

firstTemp = ran.nextInt(end) + range;

sumTemp = firstTemp;

highestTemp = firstTemp;

lowestTemp = firstTemp;

  

for(int i=0; i<numofsim-2;i++)

{

temp = ran.nextInt(end)+range;

if(temp > highestTemp)

highestTemp = temp;

if(temp < lowestTemp)

lowestTemp = temp;

sumTemp += temp;

  

}

lastTemp = ran.nextInt(end) + range;

sumTemp+= lastTemp;

  

if(lastTemp > highestTemp)

highestTemp = lastTemp;

if(lastTemp < lowestTemp)

lowestTemp = lastTemp;

  

averageTemp = sumTemp/numofsim;

System.out.println("1- First temperature generated: " +firstTemp +" " +

"2- Last temperature generated: " +lastTemp +" " +

"3- Lowest temperature generated: " +lowestTemp +" " +

"4- Highest temperature generated: " +highestTemp +" " +

"5- Total sum of all temperatures generated: " + sumTemp+" " +

"6- Average for the season: " + averageTemp+" " );

  

  

}

  

  

  

public static void main (String [] args)

{

Scanner sc = new Scanner(System.in);

int choice=0;

int numberOfSimulation;

System.out.println("What season would you like to simulate");

System.out.println("Enter 1 for Winter. Enter 2 for Sring. Enter 3 for Summer. Enter 4 for Fall. Enter 5 to Exit.");

choice = sc.nextInt();

  

while(choice != 5)

{

System.out.println("How many times would you like to simulate");

numberOfSimulation = sc.nextInt();

  

if (choice == 1)

{

simulate(numberOfSimulation,20,20);

}

else if(choice == 2)

{

simulate(numberOfSimulation,40,30);

}

else if(choice == 3)

{

simulate(numberOfSimulation,70,20);

}

else if(choice == 4)

{

simulate(numberOfSimulation,40,20);

}

System.out.println("Enter 1 for Winter. Enter 2 for Sring. Enter 3 for Summer. Enter 4 for Fall. Enter 5 to Exit.");

choice = sc.nextInt();

}

System.out.println("Thanks for using our simulation");

  

}

  

  

  

}