Skip to content

Instantly share code, notes, and snippets.

@dchapman1988
Created January 14, 2014 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dchapman1988/8424082 to your computer and use it in GitHub Desktop.
Save dchapman1988/8424082 to your computer and use it in GitHub Desktop.
/*
* File: DownloadTimeApp.java
* Author: David Chapman, dac1988@uab.edu
* Assignment: Project 1 EE333 Fall 2013
* Vers: 1.0.1 01/12/2014 dac - initial coding
*
* Credits: (if any for sections of code)
*/
import java.util.Scanner;
/**
* The Download Time App's main class
*
* @author David
*/
public class DownloadTimeApp {
/**
* Will split a double (assumed to be seconds) into an array of hours, minutes
* and seconds
*
* @param seconds the seconds determined by user input
* @return the array of time components (hours, minutes, seconds)
*/
public static int[] splitTimeComponents(double seconds)
{
int hours = (int) seconds / 3600;
int remainder = (int) seconds - hours * 3600;
int minutes = remainder / 60;
remainder = remainder - minutes * 60;
int secs = remainder;
int[] ints = {hours, minutes, secs};
return ints;
}
/**
* The main class method
*
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String choice = "y";
double fileSize;
double downloadSpeed;
// print student name to stdout
System.out.println("------------------");
System.out.println("EE333 - P1 - Download Time Estimator");
System.out.println("David A. Chapman - dac1988");
System.out.println("------------------");
System.out.println();
while(choice.equalsIgnoreCase("y"))
{
// get the input from the user
System.out.print("Enter file size (MB): ");
// store valid input
fileSize = sc.nextDouble();
System.out.print("Enter the download speed (MB/sec): ");
downloadSpeed = sc.nextDouble();
// calculate the result: t = d/r
double downloadTime = (fileSize / downloadSpeed);
// split the time compoentns up
int[] timeComponents = splitTimeComponents(downloadTime);
// construct the output string
String outputMessage = "\nThis download will take approximately "
+ timeComponents[0] + " hours " + timeComponents[1] + " minutes "
+ timeComponents[2] + " seconds.\n";
// output the outputMessage
System.out.println(outputMessage);
// see if the user wants to continue
System.out.print("Continue? (y/n): ");
choice = sc.next();
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment