Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package frequency;
- import java.util.Scanner;
- import java.util.Stack;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author L13Y13W18
- */
- public class FrequencyQualitative {
- private Stack<Integer> data = new Stack();
- int n=0;
- float sum = 0;
- float g = 0;
- public static void main(String[] args)
- {
- }
- public void add(int num)
- {
- data.push(num);
- setSum(num);
- n++;
- }
- public void setSum(int n)
- {
- sum+= n;
- }
- public void setMean(float s)
- {
- s = sum;
- g = s/n;
- }
- public float getMean()
- {
- setMean(sum);
- return g;
- }
- public float getMedian()
- {
- float median = 0;
- int[] score = new int[n];
- for(int i = 0;i<n;i++)
- {
- score[i] = data.pop();
- }
- for(int q = (score.length -1);q>= 0; q++)
- {
- for(int j = q; j<=1; j++)
- {
- if(score[j-1]>score[j])
- {
- int temp = score[j-1];
- score[j-1] = score[j];
- score[j] = temp;
- }
- }
- }
- if(n%2!=0)
- {
- median = score[((n+1)/2)-1];
- }else
- {
- median = ((float)score[(n/2)-1]+score[(n/2)])/2;
- }
- return median;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement