Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. package com.company;
  2.  
  3. /*
  4. * Problem Set 1
  5. *
  6. * File: Statistics.java
  7. * Author: JunCheng Zhang
  8. * Course: CS112, Boston University
  9. * Section: B1
  10. *
  11. * Purpose: Template code - Alter to state the purpose of this program
  12. */
  13.  
  14. // The following import command is required for performing user input:
  15. // The Scanner class is a library which provides functionality for
  16. // reading input from the user in the Interactions Pane. Some
  17. // libraries (such as Math) are already inported, but most (such
  18. // as Scanner) you need to explicitly import. The import statement
  19. // must occur before your class definition.
  20.  
  21. import java.util.Scanner;
  22.  
  23. public class Statistics {
  24.  
  25. /*
  26. * main method of the Statistics program which will
  27. * be used as the main entry point of our program and
  28. * to test the methods of the class.
  29. */
  30. public static void main(String[] args) {
  31. Scanner console = new Scanner(System.in);
  32. int num1 = console.nextInt();
  33. int num2 = console.nextInt();
  34. int num3 = console.nextInt();
  35. display_statistics(num1,num2,num3);
  36.  
  37.  
  38. // Enter your code
  39.  
  40.  
  41.  
  42. }
  43.  
  44. /*
  45. * display_statistics()
  46. *
  47. * Static method of this class which will be used to calulate and
  48. * display the required statistics.
  49. *
  50. * This method accepts three integer arguments as input values and uses
  51. * the input values to compute the statistics. This method is a void
  52. * method and does not return any value.
  53. */
  54. public static void display_statistics( int num1, int num2, int num3) {
  55.  
  56. // Enter your code
  57. int sum = num1 + num2 + num3;
  58. int maxi = Math.max(Math.max(num1,num2), num3);
  59. int mini = Math.min(Math.min(num1,num2), num3);
  60. double avg = ((num1 + num2 + num3) / 3);
  61.  
  62.  
  63. // The sum of three numbers
  64. System.out.println(sum);
  65.  
  66. // The maximum of the three numbers
  67. System.out.println(maxi);
  68.  
  69. // The range of the numbers
  70. System.out.println(maxi - mini);
  71.  
  72. // The mean(average) of the three numbers
  73. System.out.println(avg);
  74.  
  75. // The (population) standard deviation of the three numbers
  76. System.out.println(Math.sqrt(((num1 - avg) * (num1 - avg) + (num2 - avg) * (num2 - avg) + (num3 - avg) * (num3 - avg)) / 2));
  77.  
  78. // print out the three numbers in ascending order
  79. System.out.println(mini + (sum - maxi - mini)+ maxi);
  80.  
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement