Vertical and Horizontal retrieval ( MRT ) on Tapes | Java program to print Horizontal filling ; It is used for checking whether tape is full or not ; It is used for calculating total retrieval time ; It is used for calculating mean retrieval time ; vector is used because n number of records can insert in one tape with size constraint ; Null vector obtained to use fresh vector ' v ' ; initialize variables to 0 for each iteration ; sum is used for checking whether i 'th tape is full or not ; check sum less than size of tape ; increment in j for next record ; calculating total retrieval time ; MRT formula ; calculating mean retrieval time using formula ; v . size ( ) is function of vector is used to get size of vector ; Driver Code ; store the size of records [ ] ; store the size of tapes [ ] ; sorting of an array is required to attain greedy approach of algorithm
import java . util . * ; class GFG { static void horizontalFill ( int records [ ] , int tape [ ] , int nt ) { int sum = 0 ; int Retrieval_Time = 0 ; double Mrt ; int current = 0 ; Vector < Integer > v = new Vector < Integer > ( ) ; for ( int i = 0 ; i < nt ; i ++ ) { v . clear ( ) ; Retrieval_Time = 0 ; sum = 0 ; System . out . print ( " tape ▁ " + ( i + 1 ) + " ▁ : ▁ [ ▁ " ) ; sum += records [ current ] ; while ( sum <= tape [ i ] ) { System . out . print ( records [ current ] + " ▁ " ) ; v . add ( records [ current ] ) ; current ++ ; sum += records [ current ] ; } System . out . print ( " ] " ) ; for ( int j = 0 ; j < v . size ( ) ; j ++ ) { Retrieval_Time += v . get ( j ) * ( v . size ( ) - j ) ; } Mrt = ( double ) Retrieval_Time / v . size ( ) ; System . out . print ( " TABSYMBOL MRT ▁ : ▁ " + Mrt + "NEW_LINE"); } } public static void main ( String [ ] args ) { int records [ ] = { 15 , 2 , 8 , 23 , 45 , 50 , 60 , 120 } ; int tape [ ] = { 25 , 80 , 160 } ; int n = records . length ; int m = tape . length ; Arrays . sort ( records ) ; horizontalFill ( records , tape , m ) ; } }