2014-05-16 Homework!!

posted May 16, 2014, 10:50 AM by Samuel Konstantinovich   [ updated May 16, 2014, 12:17 PM ]
Deadline Sunday the 18th of May at 1159pm

UPDATED - don't do it 30 times, do it size times!!!

You are writing a Sorry class which is a driver to test your RunningMedian

command line usage:  java Sorry size seed1 seed2 seed3... (at least 2 integer argunments on the command line)
java Sorry 30 99 45  //size is 30, seeds are 99 and 45

The first integer (size) tells you how many iterations per test. 

For each subsequent integer you will create a java Random  ( http://docs.oracle.com/javase/7/docs/api/java/util/Random.html )
and use that random in 2 tests.

so:
for each seed in arguments {
   Random R=new Random(seed);
   test1(R,size);
   test2(R,size);
}

//////////////////////////////////


void test1(Random r, int size){
    //create a runningMedian
    //repeat size times:
    //create a random value, and add it to your running median.
    //print what you added and the median after each add.
}


void test2(Random r,int size){
    //create a runningMedian
    //repeat size times:
    //create a random value, and add it to your running median.
    //print what you added, and the median after each add.
    //there is a 20% chance that the median is removed. (print that you are doing this)
}



Output test1:
added: 2, median is: 2.0
added: 6, median is: 4.0
added: 100, median is: 6.0
....

Optional1: You can improve it by making it display the values added so far (make a sorted array that you calculate as you go)
added: 2, median is: 2. [2 ]
added: 6, median is: 4. [2, 6]
added: 100, median is: 6.  [2, 6, 100]
....


Optional2: You can improve it by making it display the values added so far (make a sorted array that you calculate as you go) BUT! Only display the middle 9 elements(if an odd number of elements are present) OR the middle 8 elements (if an even number of elements are present)
added: 0, median is: 5.0 [0, 1, 2, 3, 4, 5, 6, 7, 8]
added: 9, median is: 4.5 [... 1, 2, 3, 4, 5, 6, 7, 8...]
added: 10, median is: 5.0 [... 1, 2, 3, 4, 5, 6, 7, 8, 9...]
added: 100, median is: 5.5 [... 2, 3, 4, 5, 6, 7, 8, 9...]
....



Output test2:
added: 5, median is: 5.0  [5]
added: 4, median is: 4.5 [4, 5]
added: 100, median is: 5.0 [4,5,100]
removed median 5.0. [4,100] new median is: 52.0  //it removes only 1
added: 10 median is: 10.0 [4,10,100]
added: 100 median is: 55.0 [4,10,100,100]
removed median 55.0. [4, 100] new median is: 52.0  //notice it removes both




Comments