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 6 of 6

Thread: new to programming..HELP!!

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default new to programming..HELP!!

    Okay so im new to java and I have this assignment that I started but I am now stuck
    The instructions are:

    Create an ElapsedTimeCalculator class that computes the amount of time that passes between a starting time and an ending time, in military format.

    For example, suppose the two times are 1445 and 1730. Then the program output should look something like this:

    Start time: 1445
    End time: 1730

    Exactly 2 hour(s) and 45 minute(s) have passed.

    Total elapsed time in minutes: 165
    Total elapsed time in hours: 2.75

    ElapsedTimeCalculator Class Specifications:

    1. Your class will have a constructor that takes two parameters: the starting time and the ending time in military format

    2. Your class will also have these methods:

    • “get” methods to return the starting and ending times
    • a “set” method that resets the starting and ending times to values passed as parameters
    • a method that returns the hour portion of the elapsed time
    • a method that returns the minute portion of the elapsed time
    • a method that returns the total elapsed time in minutes
    • a method that returns the total elapsed time in hours


    Now here below you can see what I have so far...



    public class ElapsedTimeCalculator {


    private int startTime, endTime;
    private int hours;
    private int minutes;
    private int seconds;

    //constructor
    ElapsedTimeCalculator(int start, int end)
    {
    startTime = start;
    endTime = end;
    }

    // “get” methods to return the starting and ending times
    public int getStart()
    {
    return startTime;
    }

    public int getEnd()
    {
    return endTime;
    }

    //a “set” method that resets the starting and ending times to values passed as parameters
    public void setElapsedTimeCalculator()
    {

    }

    private void reset() {


    if (startTime > 0 && endTime > 0)
    {
    startTime = 0 ;
    endTime = 0 ;
    }


    }



    I don't have any errors so far, I am more stuck on how to begin a method that returns the hour, minute, etc.. (the third bullet). Hopefully I have done everything okay so far but if anyone can help me with that one part I would really appreciate it. Thank you!

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: new to programming..HELP!!

    What specific questions do you have about the program?
    Given the start time and end time, what does the program need to do with those numbers to get the desired values?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: new to programming..HELP!!

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers.

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

    nessabenz (February 12th, 2014)

  5. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Beginner Java Assignment..Help!

    Okay so im new to java and I have this assignment that I started but I am now stuck
    The instructions are:

    Create an ElapsedTimeCalculator class that computes the amount of time that passes between a starting time and an ending time, in military format.

    For example, suppose the two times are 1445 and 1730. Then the program output should look something like this:

    Start time: 1445
    End time: 1730

    Exactly 2 hour(s) and 45 minute(s) have passed.

    Total elapsed time in minutes: 165
    Total elapsed time in hours: 2.75

    ElapsedTimeCalculator Class Specifications:

    1. Your class will have a constructor that takes two parameters: the starting time and the ending time in military format

    2. Your class will also have these methods:

    • “get” methods to return the starting and ending times
    • a “set” method that resets the starting and ending times to values passed as parameters
    • a method that returns the hour portion of the elapsed time
    • a method that returns the minute portion of the elapsed time
    • a method that returns the total elapsed time in minutes
    • a method that returns the total elapsed time in hours


    Now here below you can see what I have so far...


    public class ElapsedTimeCalculator { 
     
    private int startTime, endTime; 
    private int hours; 
    private int minutes; 
    private int seconds; 
     
    //constructor 
    ElapsedTimeCalculator(int start, int end) 
    { 
    startTime = start; 
    endTime = end; 
    } 
     
    // “get” methods to return the starting and ending times 
    public int getStart() 
    { 
    return startTime; 
    } 
     
    public int getEnd() 
    { 
    return endTime; 
    } 
     
    //a “set” method that resets the starting and ending times to values passed as parameters 
    public void setElapsedTimeCalculator() 
    { 
     
    } 
     
    private void reset() { 
     
     
    if (startTime > 0 && endTime > 0) 
    { 
    startTime = 0 ; 
    endTime = 0 ; 
    } 
     
     
    }




    I don't have any errors so far, I am more stuck on how to begin a method that returns the hour, minute, etc.. (the third bullet). Hopefully I have done everything okay so far but if anyone can help me with that part I would really appreciate it. Thank you!

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: new to programming..HELP!!

    Given the start time and end time, what does the program need to do with those numbers to get the desired values?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: new to programming..HELP!!

    The assignment is structured to get you thinking in small steps, so take it a step at a time. Create a method, getElapsedHours(), or a name of your choosing, and consider what must be done with the user's input to calculate and return the difference in hours between the two times. Think it through, take notes on paper or in comments in your blank method, and then code it and test it. When you think you've gotten that one right, move to the next and repeat the same steps.

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

    nessabenz (February 13th, 2014)

Similar Threads

  1. Java Programming (Object Oriented Programming) Assignment
    By azmilPhenom in forum Object Oriented Programming
    Replies: 3
    Last Post: December 21st, 2013, 07:26 AM
  2. Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming
    By judemartin99 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 20th, 2013, 02:19 PM
  3. Blackjack programming error (programmer is new to programming)
    By JSingh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2012, 09:13 PM
  4. android programming vs game programming using java
    By vgoel38 in forum Android Development
    Replies: 4
    Last Post: September 8th, 2012, 05:48 PM
  5. Replies: 0
    Last Post: December 12th, 2011, 03:17 PM

Tags for this Thread