Results 1 to 5 of 5
  1. #1
    Andreas85b is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Need help for a project.

    Hello
    I am a Computer Science student recently started to learn Java, and I have this task that I cant figure out:
    I need to calculate the amount of time in minutes and seconds for a cooking process (meal = X), (cooking time = Y = 20 seconds)
    so that if i type the number 3 ill get an output of 60 seconds
    but if i type the number 4 ill get:
    "you have to cook the meals for 1 minute and 20 seconds".

    an example of my code: (calculating the heating time)

    import java.util.Scanner;
    class FishCutlet
    {
    public static void main (String[] args)
    {
    Scanner scan = new Scanner (System.in);
    final int HEATING_TIME = 20;
    System.out.println ("It takes 20 seconds to heat one fish cutlet.");
    System.out.println ("How many cutlets would you like to heat? ");
    int num = scan.nextInt();
    int seconds;
    int minutes = ((num*seconds)/num);
    if (num == 1)
    System.out.println ("You need to heat the cutlet for 20 seconds.");
    else
    if (num <= 3)
    System.out.println ("You have to heat the cutlet for "+(num*20)+ "seconds.");
    else
    System.out.println ("You have to heat the cutlet for "+minutes+" minutes and "+seconds+" seconds");
    }
    }


    im stuck with the int seconds and int minutes part :(

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Need help for a project.

    When posting code, please use the code tags. Unformatted code is really hard to read.

    What exactly is the problem? Where are you stuck? Are you getting an Exceptions? Unexpected behavior? Something else? You have to be more specific than saying you're stuck on the "int seconds and minutes part", otherwise we're just guessing at your actual question.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    dinesh.guntha is offline Member
    Join Date
    May 2011
    Posts
    27
    Rep Power
    0

    Default Re: Need help for a project.

    calculation is wrongly.
    1 minute = 60 seconds then if want to get into a time (number of cutlet * 20 seconds)/60 seconds.
    you will get the time based on the time you need to get the seconds & minutes.

  4. #4
    d2r123 is offline Member
    Join Date
    Mar 2012
    Posts
    7
    Rep Power
    0

    Default Re: Need help for a project.

    time = cuts * 20 seconds
    time/60
    time%60

    Figure out what that % symbol is and how it is different from / and abolish your if else system, you don't need it.

    If you want to not learn anything, here is the answer in white

    final int HEATING_TIME = 20;
    System.out.println ("It takes 20 seconds to heat one fish cutlet.");
    System.out.println ("How many cutlets would you like to heat? ");
    int num = scan.nextInt();
    System.out.println ("You need to heat the cutlet for " + ((num*HEATING_TIME)/60) + " minutes and " + ((num*HEATING_TIME)%60) + " seconds.");

    Last edited by d2r123; 03-13-2012 at 11:55 PM.

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Need help for a project.

    Sigh. Spoon-feeding is NOT helping.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Creating a project in eclipse from existing project
    By Suraiya in forum New To Java
    Replies: 1
    Last Post: 10-08-2011, 10:14 AM
  2. How to convert from Ant project to maven project?
    By jiapei100 in forum New To Java
    Replies: 0
    Last Post: 06-08-2011, 11:01 AM
  3. Adding a project to an existing project
    By Seijuro in forum NetBeans
    Replies: 4
    Last Post: 08-08-2010, 11:15 AM
  4. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 09:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •