Need help for a project.

• 03-13-2012, 08:30 AM
Andreas85b
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 :(
• 03-13-2012, 02:06 PM
KevinWorkman
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.
• 03-13-2012, 03:10 PM
dinesh.guntha
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.
• 03-13-2012, 09:36 PM
d2r123
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.");

• 03-14-2012, 12:48 AM
KevinWorkman
Re: Need help for a project.
Sigh. Spoon-feeding is NOT helping.