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.

Page 3 of 3 FirstFirst 123
Results 51 to 64 of 64

Thread: Time Class problem

  1. #51
    Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Class problem

    Quote Originally Posted by Norm View Post
    I don't see any comments as I requested on this line. I assume that is not what is desired.
    The value after the = is the String returned by the Object class's default toString method. The Time1 method needs a toString method that returns the String you want to see.
    What happened to the toString method that was in earlier versions of the Time1 class? Copy it into the new version. See post#31
    it was with string.formatter and i am not allowed to use it

  2. #52
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Time Class problem

    i am not allowed to use it
    Strange. Why is that I wonder?
    What else is not allowed?

    Can you build a String using concatenation(using + operator) and return that in the toString method?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #53
    Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Class problem

    Quote Originally Posted by Norm View Post
    Strange. Why is that I wonder?
    What else is not allowed?

    Can you build a String using concatenation(using + operator) and return that in the toString method?
    public String toString() {
            final StringBuilder sb = new StringBuilder ("Time1{");
            sb.append ("_hour=").append (_hour);
            sb.append (", _minute=").append (_minute);
            sb.append ('}');
            return sb.toString ();
        }
    but now how can i dispose the part that i dont need so the out put will be
    1. Testing Constructors and toString:
    	t1=17:45
    	t2=00:00

  4. #54
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Time Class problem

    how can i dispose the part that i dont need so the out put will be
    What is it you want to disposed of?
    Why not build the exact String you want so nothing has to be removed or changed?

    Again I can not see what you are seeing so I need you to paste it here so I can see what you are talking about.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #55
    Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Class problem

    Quote Originally Posted by Norm View Post
    What is it you want to disposed of?
    Why not build the exact String you want so nothing has to be removed or changed?

    Again I can not see what you are seeing so I need you to paste it here so I can see what you are talking about.
    i managed to figure it out now to my next question how the method minFromMidnight will look like
    this method returns how much minutes passed after midnightfor example if the time stored inside the object is 07:30 than a value of 450 will be returned

  6. #56
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Time Class problem

    if the time stored inside the object is 07:30 than a value of 450 will be returned
    Do you have the equation for that? Can you code that equation in the method and return its results?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #57
    Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Class problem

    Quote Originally Posted by Norm View Post
    Do you have the equation for that? Can you code that equation in the method and return its results?
    i got no idea how to do that

  8. #58
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Time Class problem

    Do you know any algebra? Can you write a simple formula to compute the needed value?
    Expressions in java use standard math symbols: +, -,*, / for add, subtract, multiply, divide
    Take a look at the tutorial: https://docs.oracle.com/javase/tutor...bolts/op1.html

    How did you get the value of 450?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #59
    Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Class problem

    Quote Originally Posted by Norm View Post
    Do you know any algebra? Can you write a simple formula to compute the needed value?
    Expressions in java use standard math symbols: +, -,*, / for add, subtract, multiply, divide
    Take a look at the tutorial: https://docs.oracle.com/javase/tutor...bolts/op1.html

    How did you get the value of 450?
    60*7+30

  10. #60
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Time Class problem

    Ok, that looks like an equation.
    Now replace the 7 and 30 with the variable names from the class and assign the results to a variable.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #61
    Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Class problem

    Quote Originally Posted by Norm View Post
    Ok, that looks like an equation.
    Now replace the 7 and 30 with the variable names from the class and assign the results to a variable.
     public int minFromMidnight()
        {
            return _hour+_minute*60;
        }
    ??? like this

  12. #62
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Time Class problem

    Did you try it? What happened? What value was returned? Print it out to see.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #63
    Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Time Class problem

    Quote Originally Posted by Norm View Post
    Did you try it? What happened? What value was returned? Print it out to see.
    470

  14. #64
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Time Class problem

    What is 470? What were the values of hour and minutes used in the computation?
    Is that the correct answer?

    Also posted at: https://www.dreamincode.net/forums/t...&#entry2416145

    Please read: http://www.javaprogrammingforums.com...s-posting.html
    and https://coderanch.com/wiki/660346/Wi...-Posting-Sites
    If you don't understand my answer, don't ignore it, ask a question.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. current execution time of a class in java by running another class
    By priyap761 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 14th, 2014, 06:12 AM
  2. Time class - previousSecond()
    By kennylty in forum Object Oriented Programming
    Replies: 1
    Last Post: March 7th, 2014, 10:16 AM
  3. Problem in getting time of different time zone
    By anks.coder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 13th, 2013, 05:44 PM
  4. Help!! Schedual class with time and date
    By passoa in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 30th, 2013, 07:36 AM
  5. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM

Tags for this Thread