Results 1 to 5 of 5
Thread: Need help for a project.
- 03-13-2012, 07:30 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
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, 01:06 PM #2
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!
- 03-13-2012, 02:10 PM #3
Member
- Join Date
- May 2011
- Posts
- 27
- Rep Power
- 0
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, 08:36 PM #4
Member
- Join Date
- Mar 2012
- Posts
- 7
- Rep Power
- 0
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 10:55 PM.
- 03-13-2012, 11:48 PM #5
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
-
Creating a project in eclipse from existing project
By Suraiya in forum New To JavaReplies: 1Last Post: 10-08-2011, 09:14 AM -
How to convert from Ant project to maven project?
By jiapei100 in forum New To JavaReplies: 0Last Post: 06-08-2011, 10:01 AM -
Adding a project to an existing project
By Seijuro in forum NetBeansReplies: 4Last Post: 08-08-2010, 10:15 AM -
open existing project project ..
By itaipee in forum EclipseReplies: 1Last Post: 12-28-2008, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks