Lab 1

Description:
This lab was about temperature; basically we were given 4 seasons, which represented the season of the year, winter, summer, fall, and spring. The goal of this lab was for us to generate the temperature of each season when and each season suppose to have certain numbers display randomly, for example winter was suppose to display a number between 20-40, while summer was suppose to display a number between 70-90 and it all suppose to be done randomly base on how many times you stimulate it. This was accomplish by using the random class or Random ran = new Random(); to generate random numbers so the stimulation can run smooth, Also this was accomplishing by using the public class, import java.util.Random; import java.util.Scanner. (Work with Robert Marino)

Code:

package temp;

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

public class temp
{
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 highestTemp)
highestTemp = temp;
if(temp  highestTemp)
highestTemp = lastTemp;
if(lastTemp < lowestTemp)
lowestTemp = lastTemp;
averageTemp = sumTemp/numofsim;
System.out.println("1- First temperature generated: " +firstTemp +"\n" +
"2- Last temperature generated: " +lastTemp +"\n" +
"3- Lowest temperature generated: " +lowestTemp +"\n" +
"4- Highest temperature generated: " +highestTemp +"\n" +
"5- Total sum of all temperatures generated: " + sumTemp+"\n" +
"6- Average for the season: " + averageTemp+"\n" );
}
public static void main (String [] args)
{
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
int choice=0;
int numberOfSimulation;
System.out.println(" please pick a season you would like to simulate");
        System.out.println(" 1 for winter");
        System.out.println(" 2 for spring");
        System.out.println(" 3 for summer");
        System.out.println(" 4 for fall");
        System.out.println(" 5 to exist");
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(" 1 for winter");
System.out.println(" 2 for spring");
System.out.println(" 3 for summer");
System.out.println(" 4 for fall");
System.out.println(" 5 to exist");
choice = sc.nextInt();
}
System.out.println("No more to stimulate, thanks for using this simulation bye-bye");
}
}

screenshots:
pic1 reyes
pic2 reyes
pic3 reyes
pic4 reyes
pic5 reyes

Leave a Reply

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