Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. package frequency;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Stack;
  5.  
  6. /*
  7. * To change this license header, choose License Headers in Project Properties.
  8. * To change this template file, choose Tools | Templates
  9. * and open the template in the editor.
  10. */
  11.  
  12. /**
  13. *
  14. * @author L13Y13W18
  15. */
  16. public class FrequencyQualitative {
  17. private Stack<Integer> data = new Stack();
  18. int n=0;
  19. float sum = 0;
  20. float g = 0;
  21. public static void main(String[] args)
  22. {
  23.  
  24. }
  25.  
  26. public void add(int num)
  27. {
  28. data.push(num);
  29. setSum(num);
  30. n++;
  31. }
  32.  
  33. public void setSum(int n)
  34. {
  35. sum+= n;
  36. }
  37.  
  38.  
  39. public void setMean(float s)
  40. {
  41.  
  42. s = sum;
  43. g = s/n;
  44.  
  45. }
  46.  
  47. public float getMean()
  48. {
  49. setMean(sum);
  50. return g;
  51. }
  52.  
  53. public float getMedian()
  54. {
  55. float median = 0;
  56. int[] score = new int[n];
  57. for(int i = 0;i<n;i++)
  58. {
  59. score[i] = data.pop();
  60. }
  61. for(int q = (score.length -1);q>= 0; q++)
  62. {
  63. for(int j = q; j<=1; j++)
  64. {
  65. if(score[j-1]>score[j])
  66. {
  67. int temp = score[j-1];
  68. score[j-1] = score[j];
  69. score[j] = temp;
  70. }
  71. }
  72. }
  73. if(n%2!=0)
  74. {
  75. median = score[((n+1)/2)-1];
  76.  
  77. }else
  78. {
  79. median = ((float)score[(n/2)-1]+score[(n/2)])/2;
  80. }
  81. return median;
  82. }
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement