Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Beginner question

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Beginner question

    I need help with my code to declare the total value.

    --- Update ---


    import java.util.Scanner;
     
     
    /**
     *
     * @author Joyce
     */
    public class DownloadTimeApp {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) 
        {
            Scanner sc = new Scanner(System.in);
            String choice = "y";
            while (choice.equalsIgnoreCase("y")) {
     
            System.out.println ("Welcome to the Download Time Estimator");
            System.out.println();
     
            //gets input from the user
            System.out.println("Enter file size (MB):");
            int fileSize = sc.nextInt();
            System.out.println("Enter download speed )(MB/sec):");
            int totalSec = sc.nextInt();
     
     
            //variables
            int total = total (fileSize / totalSec);
     
            int hours = totalSec / 3600;
            int minutes = (totalSec % 3600) / 60;
            int seconds = totalSec % 60;
     
            //calculated message
            System.out.println();
            String message = 
                    "This download will take approximately" + hours + "hours" + minutes + 
                    "minutes" + seconds + "seconds";
            System.out.println(message);
     
            //if user wants to continue
            System.out.print("Continue? (y/n): ");
            choice = sc.next();
            System.out.println();
            // TODO code application logic here
     
            }
        }
     
    }
    I'm trying to figure out where to declare my total.
    this is my formula total = fileSize / totalSec


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    898
    Thanks
    0
    Thanked 166 Times in 148 Posts

    Default Re: Beginner question

    What is the problem? Do you have any specific question or error messages?

  3. The Following User Says Thank You to Cornix For This Useful Post:

    jwillett29 (June 24th, 2014)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,304
    My Mood
    Mellow
    Thanks
    252
    Thanked 778 Times in 763 Posts

    Default Re: Beginner question

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    Where it is is will need to be adjusted in order to use the totalSec value. How it has been done is not so good. Why can't you follow the models of hours, minutes, and seconds to declare and initialize total?

  5. The Following User Says Thank You to GregBrannon For This Useful Post:

    jwillett29 (June 24th, 2014)

  6. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Beginner question

    One possible problem could be the code is doing int math:
    40/60 = 0
    vs floating point
    40/60.0 = 0.66666666
    If you don't understand my answer, don't ignore it, ask a question.

  7. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Beginner question

    Quote Originally Posted by Cornix View Post
    What is the problem? Do you have any specific question or error messages?
    There is no error message my problem is that I need to get 2 input values.

    Basically I just need to divide the fileSize and totalSec then the Total will have to be shown in hrs mins and secs.

    For example:

    800 / 2 = 400secs -> Then I need to convert 400secs into hrs mins and secs

    It should show output "This download will take approximately 0 hrs 6 mins and 40 secs"

    I already got the formula right for converting seconds to hrs mins and secs my only problem is I need to get the total value first before it converts it to hrs mins and secs. Right now my program only reads the second value which is the totalSec.

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Beginner question

    I need to get the total value first
    Is that value input by the user?
    If so, use the same technique that the code uses to get the totalSec value from the user: print a message and use a Scanner class method to read the user's input.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #7
    Junior Member
    Join Date
    Jun 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Beginner question

    No the total value is not from the user input. I need it to be calculated after the user inputs fileSize and totalSec. I just need it to calculate internally then produce hr min sec output.

  10. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Beginner question

    I just need it to calculate internally
    Do you have the formula or equation to do that?
    If you don't understand my answer, don't ignore it, ask a question.

  11. The Following User Says Thank You to Norm For This Useful Post:

    jwillett29 (June 24th, 2014)

  12. #9
    Junior Member
    Join Date
    Jun 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Beginner question

    Quote Originally Posted by Norm View Post
    Do you have the formula or equation to do that?
    My formula goes like this:

    The user inputs MBytes and Seconds/DL
    Then after the user inputs two values the program has to divide the two values to get the total.
    The total which is not reflected through the output will be converted into hrs mins and secs.

    My problem is I don't know where I Am supposed to put the fileSize / totalSec = total formula in my code. Like I said right now, it only reads the second user input which is totalSec.

  13. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Beginner question

    divide the two values to get the total.
    Are the values: bytes and seconds? Dividing those two would give a rate: bytes/second Not a total.

    What is the total you are trying to compute? What units is it in? time or bytes or ???

    Is there an equation for computing it?
    I was looking for something like this: x = ay + z

    Or bytes/(bytes/sec) gives sec. Is that what you want: seconds?

    Does the variable: totalSec have a wrong name? Should it be named MBPerSecond?
    If you don't understand my answer, don't ignore it, ask a question.

  14. The Following User Says Thank You to Norm For This Useful Post:

    jwillett29 (June 24th, 2014)

  15. #11
    Junior Member
    Join Date
    Jun 2014
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Beginner question

    Yes thank you I did renamed it finally figured it out. Thank you I think I got it.

Similar Threads

  1. Beginner question about main
    By Samaras in forum Java Theory & Questions
    Replies: 2
    Last Post: July 31st, 2012, 11:10 AM
  2. Beginner question about for loops...
    By ninjaBob in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 29th, 2012, 03:57 PM
  3. Loop Question - Very new beginner
    By Callcollect in forum Loops & Control Statements
    Replies: 12
    Last Post: January 18th, 2012, 04:01 AM
  4. Beginner Question
    By jrt224 in forum Loops & Control Statements
    Replies: 1
    Last Post: March 10th, 2011, 12:56 PM
  5. beginner's question
    By bardd in forum Java Theory & Questions
    Replies: 5
    Last Post: September 14th, 2010, 05:02 PM