- Code
<
import java.util.Scanner ; import java.util.Random ; import java.util.Arrays ; public class TempSimulator { public static void main(String[] args) { Scanner input = new Scanner(System.in); Random rand = new Random(); int season; int numberSimul; int totalSumTemp = 0 ; int avgeSeason ; do { System.out.println("\n Please choose the season you Want to simulate:\n"); System.out.println(" Enter 1 for WINTER.\n Enter 2 for SPRING.\n Enter 3 for SUMMER.\n Enter 4 for FALL.\n Enter 5 to Exit the system ."); season = input.nextInt(); switch(season) { case 1: System.out.printf("%s\n%s\n","This is WINTER :","How many simulations would you like to generate?"); numberSimul = input.nextInt(); int winter[]= new int[numberSimul]; for ( int i= 0; i< numberSimul; i++) { winter[i] = rand.nextInt(20)+ 20 ; totalSumTemp += winter[i]; } avgeSeason = totalSumTemp/(numberSimul) ; System.out.printf("The first temperature generated is: %d\n", winter[0]); System.out.printf("The last temperature generated is: %d\n", winter[numberSimul-1]); Arrays.sort(winter); System.out.printf("The lowest temperature generated is: %d\n", winter[0]); System.out.printf("The highest temperature generated is: %d\n", winter[numberSimul-1]); System.out.printf("The total sum of all temperature generated is: %d\n", totalSumTemp); System.out.printf("The average for the season is: %d\n", avgeSeason); break; case 2: System.out.printf("%s\n%s\n","This is SPRING :","How many simulations would you like to generate?"); numberSimul = input.nextInt(); int spring[]= new int[numberSimul]; for ( int i= 0; i< numberSimul; i++) { spring[i] = rand.nextInt(30)+ 40 ; totalSumTemp += spring[i]; } avgeSeason = totalSumTemp/(numberSimul) ; System.out.printf("The first temperature generated is: %d\n", spring[0]); System.out.printf("The last temperature generated is: %d\n", spring[numberSimul-1]); Arrays.sort(spring); System.out.printf("The lowest temperature generated is: %d\n", spring[0]); System.out.printf("The highest temperature generated is: %d\n", spring[numberSimul-1]); System.out.printf("The total sum of all temperature generated is: %d\n", totalSumTemp); System.out.printf("The average for the season is: %d\n", avgeSeason); break; case 3: System.out.printf("%s\n%s\n" ,"This is SUMMER :","How many simulations would you like to generate?"); numberSimul = input.nextInt(); int summer[]= new int[numberSimul]; for ( int i= 0; i< numberSimul; i++) { summer[i] = rand.nextInt(20)+ 70 ; totalSumTemp += summer[i]; } avgeSeason = totalSumTemp/(numberSimul) ; System.out.printf("The first temperature generated is: %d\n", summer[0]); System.out.printf("The last temperature generated is: %d\n", summer[numberSimul-1]); Arrays.sort(summer); System.out.printf("The lowest temperature generated is: %d\n", summer[0]); System.out.printf("The highest temperature generated is: %d\n", summer[numberSimul-1]); System.out.printf("The total sum of all temperature generated is: %d\n", totalSumTemp); System.out.printf("The average for the season is: %d\n", avgeSeason); break; case 4: System.out.printf("%s\n%s\n","This is FALL :","How many simulations would you like to generate?"); numberSimul = input.nextInt(); int fall[]= new int[numberSimul]; for ( int i= 0; i< numberSimul; i++) { fall[i] = rand.nextInt(20)+ 40 ; totalSumTemp += fall[i]; } avgeSeason = totalSumTemp/(numberSimul) ; System.out.printf("The first temperature generated is: %d\n", fall[0]); System.out.printf("The last temperature generated is: %d\n", fall[numberSimul-1]); Arrays.sort(fall); System.out.printf("The lowest temperature generated is: %d\n", fall[0]); System.out.printf("The highest temperature generated is: %d\n",fall[numberSimul-1]); System.out.printf("The total sum of all temperature generated is: %d\n", totalSumTemp); System.out.printf("The average for the season is: %d\n", avgeSeason); break; } } while(season != 5); if (season==5) System.out.println("Thank you."); } }
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.