LAB 2

DESCRIPTION:
For this lab we basically created two class. One tempsensor and tempsensorstats. In TempsenSor class we basically created methods(get Wintertemp, getSpringtemp,e.t.c.). in Tempsensorstats we basically call those functions to get the random values. In Tempsensorstats, we also asked the user to select season and the number of simulations. I added some code to get the first, last , low , high , sum , and average. The code outputs first,last, low, high and sum.
code:

import java.util.Scanner;
import java.io.*;

public class TempsensorStats {
public static void main(String[] args){
//create object
TemperaturesenSor temp = new TemperaturesenSor();
Scanner input = new Scanner(System.in);
int first = 0, last = 0, lo = 0, high = 0, sum = 0, getNum = 0 , object = 0, simul = 0;
boolean done = false;
//welcome screen
System.out.println("welcome to Temp Geni!!");
System.out.println("enter number as follows \n1 winter\n2 spring \n3 summer \n4 fall \nother numbers to exit ");

getNum = input.nextInt();
if(getNum>0 && getNum0){
for (int i = 0;ihigh){
high = object;
}if(object<lo){
lo = object;
}
sum +=object;

}

}}
System.out.println("the highest value is: "+ high);
System.out.println("the lowest value is: "+ lo);
System.out.println("the first value is: "+ first);
System.out.println("the last value is: "+ last);
System.out.println("the average value is: "+ (sum/simul));
System.out.println("the sum of all the value "+ sum);

}
}
code 2:
import java.util.Random;
public class TemperaturesenSor {
static int first, last, low, high, randi;
public static int getWintertemp(){
int max = 40;
int min = 20;
Random rando = new Random();
randi = rando.nextInt((max - min) + 1) + min;

return randi;
}
public static int getSpringtemp(){
int max = 60;
int min = 40;
Random rando = new Random();
randi = rando.nextInt((max - min) + 1) + min;
return randi;
}
public static int getSummertemp(){
int max = 90;
int min = 70;
Random rando = new Random();
randi = rando.nextInt((max - min) + 1) + min;
return randi;
}
public static int getFalltemp(){
int max = 70;
int min = 40;
Random rando = new Random();
randi = rando.nextInt((max - min) + 1) + min;
return randi;
}

}

screenshot:

lab2

Leave a Reply

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