complete download manager simulation and report

This commit is contained in:
Fatemesadat Mirabootalebi
2026-06-05 09:23:33 -07:00
parent 9e5c715088
commit dd1a50c8ab
6 changed files with 84 additions and 23 deletions
+9 -19
View File
@@ -25,39 +25,29 @@ public class ProgressMonitor implements Runnable {
// 4. Print a progress message
// 5. If completedChunks == chunks.size(), print a final monitor message and stop
// 6. Otherwise sleep for monitorDelayMs and continue
while (true) {
while (true){
double totalDownloadedMB = 0.0;
int completedChunks = 0;
for (ChunkStatus chunk : chunks) {
for (ChunkStatus chunk : chunks){
totalDownloadedMB += chunk.getDownloadedMB();
if (chunk.isCompleted()) {
if (chunk.isCompleted()){
completedChunks++;
}
}
double percent = 0.0;
if (totalSizeMB > 0) {
if (totalSizeMB > 0){
percent = (totalDownloadedMB * 100.0) / totalSizeMB;
}
System.out.printf(
"Progress for %s: %.1f/%.1f MB (%.2f%%), completed chunks: %d/%d%n",
fileName,
totalDownloadedMB,
(double) totalSizeMB,
percent,
completedChunks,
chunks.size()
);
System.out.printf("Progress for %s: %.1f/%.1f MB (%.2f%%), completed chunks: %d/%d%n", fileName, totalDownloadedMB, (double) totalSizeMB, percent, completedChunks, chunks.size());
// TODO:
// If all chunks are completed, print a final message and exit the loop
if (completedChunks == chunks.size()){
System.out.println("Monitor: All chunks have been successfully downloaded.");
break;
}
try {
Thread.sleep(monitorDelayMs);
} catch (InterruptedException e) {