lab 1

Description:
In this lab we basically create a program to generate temperature of a certain season. The temperatures are randomly generated between a specific range. The program will display, highest value, lowest value, first value, last value, average value and the sum of all the values.

code:

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

public class Season {
public static void main(String[] args){
//variable
int max = 0, min = 0, sum=0 , first = 0, last = 0, lowest = 0, highest = 0,numIn, rand;
Scanner input = new Scanner(System.in);
Random ranVal = new Random();
do{
sum = 0;
//menu
System.out.println(“please enter 1 for winter\npleaser enter 2 for summer\nplease enter 3 for spring\nplease enter 4 for fall\nplease enter 5 to exit”);
//user input
numIn = input.nextInt();

//switch statements

switch(numIn){
case 1:
min = 20;
max = 40;
break;
case 2:
min = 70;
max = 90;
break;
case 3:
min =40 ;
max = 70;
break;
case 4:
min = 40;
max = 60;
break;

}
// asks the user how many times to generate random numbers

System.out.println(“how many times do you want to simulate?”);
int howManytimes =input.nextInt();

//generate random number
if(numIn>0 && numIn<5){
for(int i=0; ihighest){
highest = rand;
}if(rand<lowest){
lowest = rand;
}
sum +=rand;

}

System.out.println("the highest value is: "+ highest);
System.out.println("the lowest value is: "+ lowest);
System.out.println("the first value is: "+ first);
System.out.println("the last value is: "+ last);
System.out.println("the average value is: "+ (sum/100));
System.out.println("the sum of all the value "+ sum);
}}while(numIn != 5);

}}

screenshots:
lab001lab

Leave a Reply

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