Lab 1

Lab Description: In this lab, We are tasked with creating a temperature sensor that will generate random numbers that are meant to represent a reasonable range for each respective season. We are also tasked with making sure the program records and displays the first and last temperatures generated, the lowest and highest temperatures generated and the Sum and average for the seasons.

For the first and last temperatures, i used the counter in a for loop to designate the first and last generated temperatures with an if statement. For the lowest and highest temperatures i compared each simulation to the one after it and only increased/decreased the values if they were bigger or smaller depending on what i wanted. For the lowest temperatures, i gave it an initial value of 100 as to not compare to 0 or else i wouldnt get results. The sum was just an addition operator within the for loop, and the average divided by the amount of simulations entered. All of those were in case statements to develop a menu, and all of that was inside a while loop so that the user can choose to run the program over if they wished.

import java.util.Scanner;
import java.util.Random;

public class Menu {

	public static void main(String[] args) 
	{
	boolean run = false;

	System.out.println("Welcome to the Temperature Sensor Simulator.\n");

	 while(!run){

	 System.out.println("\n\nPlease select the Season you wish to simulate: \n\n"
	 		+ "1. Winter\n"
	 		+ "2. Spring\n"
	 		+ "3. Summer\n"
	 		+ "4. Fall\n"
	 		+ "5. Exit\n");

	int degrees;
	int min = 100; //used 100 so that program can update lower values as they process
	int max = 0;
	int firsttemp = 0;
	int lasttemp = 0;
	int sum = 0;
	int average = 0;
	int simulations;
	Random sim = new Random(); 
	Scanner input = new Scanner(System.in);
	int selection = input.nextInt();

	 switch(selection){

	 case 1:
		 System.out.println("How many simulations would you like to run?\n");
		 Scanner input1 = new Scanner(System.in);
		 simulations = input1.nextInt();
		 for(int counter=1;countermax){
				 max=degrees;
			 }
			 else if(degrees<min){
				 min=degrees;
			 }
			if(counter==1){
				firsttemp = degrees;
			}
			else if(counter==simulations){
				lasttemp = degrees;
			}
			sum+=degrees;
			average = sum/simulations;
		 }

		 System.out.println("\n\nFirst temperature generated: " + firsttemp);
		 System.out.println("Last temperature generated: " + lasttemp);
		 System.out.println("Lowest temperature generated: " + min);
		 System.out.println("Highest temperature generated: " + max);
		 System.out.println("Total sum of all temperatures generated " + sum);
		 System.out.println("Average for the season: " + average);
		 break;
	 case 2:
		 System.out.println("How many simulations would you like to run?\n");
		 Scanner input2 = new Scanner(System.in);
		 simulations = input2.nextInt();
		 for(int counter=1;countermax){
				 max=degrees;
			 }
			 else if(degrees<min){
				 min=degrees;
			 }
			if(counter==1){
				firsttemp = degrees;
			}
			else if(counter==simulations){
				lasttemp = degrees;
			}
			sum+=degrees;
			average = sum/simulations;
		 }

		 System.out.println("\nFirst temperature generated: " + firsttemp);
		 System.out.println("Last temperature generated: " + lasttemp);
		 System.out.println("Lowest temperature generated: " + min);
		 System.out.println("Highest temperature generated: " + max);
		 System.out.println("Total sum of all temperatures generated " + sum);
		 System.out.println("Average for the season: " + average);
		 break;
	 case 3:
		 System.out.println("How many simulations would you like to run?\n");
		 Scanner input3 = new Scanner(System.in);
		 simulations = input3.nextInt();
		 for(int counter=1;countermax){
				 max=degrees;
			 }
			 else if(degrees<min){
				 min=degrees;
			 }
			if(counter==1){
				firsttemp = degrees;
			}
			else if(counter==simulations){
				lasttemp = degrees;
			}
			sum+=degrees;
			average = sum/simulations;
		 }

		 System.out.println("\nFirst temperature generated: " + firsttemp);
		 System.out.println("Last temperature generated: " + lasttemp);
		 System.out.println("Lowest temperature generated: " + min);
		 System.out.println("Highest temperature generated: " + max);
		 System.out.println("Total sum of all temperatures generated " + sum);
		 System.out.println("Average for the season: " + average);
		 break;
	 case 4:
		 System.out.println("How many simulations would you like to run?\n");
		 Scanner input4 = new Scanner(System.in);
		 simulations = input4.nextInt();
		 for(int counter=1;countermax){
				 max=degrees;
			 }
			 else if(degrees<min){
				 min=degrees;
			 }
			if(counter==1){
				firsttemp = degrees;
			}
			else if(counter==simulations){
				lasttemp = degrees;
			}
			sum+=degrees;
			average = sum/simulations;
		 }

		 System.out.println("\nFirst temperature generated: " + firsttemp);
		 System.out.println("Last temperature generated: " + lasttemp);
		 System.out.println("Lowest temperature generated: " + min);
		 System.out.println("Highest temperature generated: " + max);
		 System.out.println("Total sum of all temperatures generated " + sum);
		 System.out.println("Average for the season: " + average);
		 break;
	 case 5:
		 run = true;
		 System.out.println("Thank you for using the temperature simulator!");
		 break;	
		 default:
			 System.out.println("huh? Try Again");
	 }//end of Switch
	} //end of While loop

	}

}

lab1

Leave a Reply

Your email address will not be published. Required fields are marked *