Converting hours:minutes into minutes












0















I'm trying to write a simple console application that will accept a string from the keyboard that represents hours and minutes in the HH:MM form and then the string must then be put into two integers for hours and mins before showing the total minutes so 02:20 would add up to 140 minutes. I feel like I'm close but I'm not entirely positive I'm doing it right. I'm very new to Java so if there's anything I'm doing wrong please let me know and any help would be very appreciated! As of now my code is presenting a number far too long?



import java.util.Scanner;

public class TimeAssignment {

public static void main(String args){
Scanner input = new Scanner(System.in);

final double minConv = 0.0166667;
final double hourConv = 60;

int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();

int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();

System.out.println("Total minutes: "+hours/hourConv+minutes/minConv);

}
}









share|improve this question




















  • 3





    Multiply hours by 60, add minutes.

    – Andy Turner
    Oct 26 '15 at 16:09








  • 3





    Remove hours/hourConv+minutes/minConv and add hours*hourConv+minutes

    – Rakesh
    Oct 26 '15 at 16:10











  • If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).

    – Andy Turner
    Oct 26 '15 at 16:11


















0















I'm trying to write a simple console application that will accept a string from the keyboard that represents hours and minutes in the HH:MM form and then the string must then be put into two integers for hours and mins before showing the total minutes so 02:20 would add up to 140 minutes. I feel like I'm close but I'm not entirely positive I'm doing it right. I'm very new to Java so if there's anything I'm doing wrong please let me know and any help would be very appreciated! As of now my code is presenting a number far too long?



import java.util.Scanner;

public class TimeAssignment {

public static void main(String args){
Scanner input = new Scanner(System.in);

final double minConv = 0.0166667;
final double hourConv = 60;

int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();

int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();

System.out.println("Total minutes: "+hours/hourConv+minutes/minConv);

}
}









share|improve this question




















  • 3





    Multiply hours by 60, add minutes.

    – Andy Turner
    Oct 26 '15 at 16:09








  • 3





    Remove hours/hourConv+minutes/minConv and add hours*hourConv+minutes

    – Rakesh
    Oct 26 '15 at 16:10











  • If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).

    – Andy Turner
    Oct 26 '15 at 16:11
















0












0








0








I'm trying to write a simple console application that will accept a string from the keyboard that represents hours and minutes in the HH:MM form and then the string must then be put into two integers for hours and mins before showing the total minutes so 02:20 would add up to 140 minutes. I feel like I'm close but I'm not entirely positive I'm doing it right. I'm very new to Java so if there's anything I'm doing wrong please let me know and any help would be very appreciated! As of now my code is presenting a number far too long?



import java.util.Scanner;

public class TimeAssignment {

public static void main(String args){
Scanner input = new Scanner(System.in);

final double minConv = 0.0166667;
final double hourConv = 60;

int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();

int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();

System.out.println("Total minutes: "+hours/hourConv+minutes/minConv);

}
}









share|improve this question
















I'm trying to write a simple console application that will accept a string from the keyboard that represents hours and minutes in the HH:MM form and then the string must then be put into two integers for hours and mins before showing the total minutes so 02:20 would add up to 140 minutes. I feel like I'm close but I'm not entirely positive I'm doing it right. I'm very new to Java so if there's anything I'm doing wrong please let me know and any help would be very appreciated! As of now my code is presenting a number far too long?



import java.util.Scanner;

public class TimeAssignment {

public static void main(String args){
Scanner input = new Scanner(System.in);

final double minConv = 0.0166667;
final double hourConv = 60;

int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();

int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();

System.out.println("Total minutes: "+hours/hourConv+minutes/minConv);

}
}






java debugging






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 26 '15 at 16:18









Perdomoff

8212723




8212723










asked Oct 26 '15 at 16:06









lxtrxilxtrxi

40212




40212








  • 3





    Multiply hours by 60, add minutes.

    – Andy Turner
    Oct 26 '15 at 16:09








  • 3





    Remove hours/hourConv+minutes/minConv and add hours*hourConv+minutes

    – Rakesh
    Oct 26 '15 at 16:10











  • If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).

    – Andy Turner
    Oct 26 '15 at 16:11
















  • 3





    Multiply hours by 60, add minutes.

    – Andy Turner
    Oct 26 '15 at 16:09








  • 3





    Remove hours/hourConv+minutes/minConv and add hours*hourConv+minutes

    – Rakesh
    Oct 26 '15 at 16:10











  • If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).

    – Andy Turner
    Oct 26 '15 at 16:11










3




3





Multiply hours by 60, add minutes.

– Andy Turner
Oct 26 '15 at 16:09







Multiply hours by 60, add minutes.

– Andy Turner
Oct 26 '15 at 16:09






3




3





Remove hours/hourConv+minutes/minConv and add hours*hourConv+minutes

– Rakesh
Oct 26 '15 at 16:10





Remove hours/hourConv+minutes/minConv and add hours*hourConv+minutes

– Rakesh
Oct 26 '15 at 16:10













If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).

– Andy Turner
Oct 26 '15 at 16:11







If you need to debug something like this, break it down into easier problems: get it working for zero hours and zero minutes; then get it working for M hours and zero minutes; then get it working for zero hours and N minutes; finally, get it working for for M hours and N minutes (although that should just work anyway by now).

– Andy Turner
Oct 26 '15 at 16:11














3 Answers
3






active

oldest

votes


















2














Fixed: Multiply hours by 60 then add your minutes.



import java.util.Scanner;

public class TimeAssignment {

public static void main(String args){
Scanner input = new Scanner(System.in);

final double minConv = 0.0166667;
final double hourConv = 60;

int hours;
System.out.print("Enter the hours to convert:");
hours = input.nextInt();

int minutes;
System.out.print("Enter the minutes to convert:");
minutes = input.nextInt();

System.out.println("Total minutes: "+((hours * 60)+minutes));

}
}





share|improve this answer

































    2














    If you want the result of 02:20 to 140 then you have just have to do this:



    System.out.println("Total minutes: "+(hours*hourConv+minutes));





    share|improve this answer

































      1














      you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .






      share|improve this answer



















      • 1





        Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.

        – APH
        Oct 26 '15 at 16:33











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33350373%2fconverting-hoursminutes-into-minutes%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      Fixed: Multiply hours by 60 then add your minutes.



      import java.util.Scanner;

      public class TimeAssignment {

      public static void main(String args){
      Scanner input = new Scanner(System.in);

      final double minConv = 0.0166667;
      final double hourConv = 60;

      int hours;
      System.out.print("Enter the hours to convert:");
      hours = input.nextInt();

      int minutes;
      System.out.print("Enter the minutes to convert:");
      minutes = input.nextInt();

      System.out.println("Total minutes: "+((hours * 60)+minutes));

      }
      }





      share|improve this answer






























        2














        Fixed: Multiply hours by 60 then add your minutes.



        import java.util.Scanner;

        public class TimeAssignment {

        public static void main(String args){
        Scanner input = new Scanner(System.in);

        final double minConv = 0.0166667;
        final double hourConv = 60;

        int hours;
        System.out.print("Enter the hours to convert:");
        hours = input.nextInt();

        int minutes;
        System.out.print("Enter the minutes to convert:");
        minutes = input.nextInt();

        System.out.println("Total minutes: "+((hours * 60)+minutes));

        }
        }





        share|improve this answer




























          2












          2








          2







          Fixed: Multiply hours by 60 then add your minutes.



          import java.util.Scanner;

          public class TimeAssignment {

          public static void main(String args){
          Scanner input = new Scanner(System.in);

          final double minConv = 0.0166667;
          final double hourConv = 60;

          int hours;
          System.out.print("Enter the hours to convert:");
          hours = input.nextInt();

          int minutes;
          System.out.print("Enter the minutes to convert:");
          minutes = input.nextInt();

          System.out.println("Total minutes: "+((hours * 60)+minutes));

          }
          }





          share|improve this answer















          Fixed: Multiply hours by 60 then add your minutes.



          import java.util.Scanner;

          public class TimeAssignment {

          public static void main(String args){
          Scanner input = new Scanner(System.in);

          final double minConv = 0.0166667;
          final double hourConv = 60;

          int hours;
          System.out.print("Enter the hours to convert:");
          hours = input.nextInt();

          int minutes;
          System.out.print("Enter the minutes to convert:");
          minutes = input.nextInt();

          System.out.println("Total minutes: "+((hours * 60)+minutes));

          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '18 at 21:14

























          answered Oct 26 '15 at 16:15









          PerdomoffPerdomoff

          8212723




          8212723

























              2














              If you want the result of 02:20 to 140 then you have just have to do this:



              System.out.println("Total minutes: "+(hours*hourConv+minutes));





              share|improve this answer






























                2














                If you want the result of 02:20 to 140 then you have just have to do this:



                System.out.println("Total minutes: "+(hours*hourConv+minutes));





                share|improve this answer




























                  2












                  2








                  2







                  If you want the result of 02:20 to 140 then you have just have to do this:



                  System.out.println("Total minutes: "+(hours*hourConv+minutes));





                  share|improve this answer















                  If you want the result of 02:20 to 140 then you have just have to do this:



                  System.out.println("Total minutes: "+(hours*hourConv+minutes));






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Oct 26 '15 at 16:21

























                  answered Oct 26 '15 at 16:11









                  ShivamShivam

                  479619




                  479619























                      1














                      you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .






                      share|improve this answer



















                      • 1





                        Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.

                        – APH
                        Oct 26 '15 at 16:33
















                      1














                      you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .






                      share|improve this answer



















                      • 1





                        Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.

                        – APH
                        Oct 26 '15 at 16:33














                      1












                      1








                      1







                      you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .






                      share|improve this answer













                      you can use simple conversion of hours to minutes by just multiplying with 60 and add this with user entered minutes .







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Oct 26 '15 at 16:20









                      dinesh kumardinesh kumar

                      143




                      143








                      • 1





                        Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.

                        – APH
                        Oct 26 '15 at 16:33














                      • 1





                        Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.

                        – APH
                        Oct 26 '15 at 16:33








                      1




                      1





                      Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.

                      – APH
                      Oct 26 '15 at 16:33





                      Welcome to StackOverflow. Your answer would be more helpful if you included information about how to make this conversion - otherwise, it would be more appropriate as a comment. Please see How to Answer for details.

                      – APH
                      Oct 26 '15 at 16:33


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33350373%2fconverting-hoursminutes-into-minutes%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                      Alcedinidae

                      Origin of the phrase “under your belt”?