0

I have a file I know the size of it and have a list of bytes downloaded for each file and have the minutes downloaded how to get the remaining time to download the rest of the file?

public static int remaining_download_time(int file_size, int[] bytes_downloaded, int minutes_of_observation) {
    if(bytes_downloaded==null)
        return file_size;
    
    int bytesize = 0;
    for(int i=0;i< bytes_downloaded.length;i++){
        bytesize= bytesize + bytes_downloaded[i];
    }
    
    int last2 = 0;
    for(int j=bytes_downloaded.length-1, k= minutes_of_observation; j>=0; j--, k--) {
        if(k!=0){
            last2+= bytes_downloaded[j];
        }
    }

    int totalRemainSize = file_size - bytesize;
    int avg = last2/2;
    int result = totalRemainSize/avg;
    return result;
}

I have those inputs

Input

file_size = 100, bytes_downloaded = [10,6,6,8], minutes_of_observation = 2

Expected output

10

Input

file_size = 80, bytes_downloaded = [10,5,0,0], minutes_of_observation = 2

Expected output

17

What did I do wrong?

Sawsan
  • 11
  • 5
  • Mistakes #1 - Doing the calculation using integers. Integer division truncates ... #2 - Using minutes (rather than seconds) as the time unit. #3 - Converting the sizes into bits (really? bits? why ...) – Stephen C Sep 24 '22 at 03:14

0 Answers0