File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Microwave Oven Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Microwave Oven" Watch "Microwave Oven" New topic

Microwave Oven

Jeffrey Samuel

Joined: Oct 30, 2009
Posts: 2
Hi, I have a problem with this code. I'm not sure if this is right. The question is:

A microwave oven manufacturer recommends that when heating two items, add 50% to the heating time, and when heating three items double the heating time. Heating more than three items at once is not recommended.

Write a program that asks the user for the number of items and the single-item heating time. The program then writes out the recommended heating time.

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1789

Welcome to JavaRanch!

So far it looks ok...... I mean for what's been completed.
You're missing the math/programming logic for the heating times, and what if someone says they have 3 items? 4? 15?

Are you sure heating time should be an int? Always? Why or why not? Will it be expressed in minutes or seconds? How will the user know this?

What do you need help with? The logic? What do you think it should do? Why? Do you need help with the code? You should write some pseudocode so people know you've done your homework.


When you do things right, people won't be sure you've done anything at all.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11919

A few tips...

1) it would greatly help others if you properly indented your code. it's VERY hard to read otherwise. if you want folks to help you, you should make it as easy as possible.

2) Generally, you'll get the best/most help if you ask a SPECIFIC question. For example..."How would I format the output to look like blah blah blah". What you have posted is your homework assignment, some partial code...and nothing else. Nobody knows WHERE you are stuck, what you are trying to do, etc. It look like you are hoping someone will just do this for you - and we don't do that here.

3) i'm guessing you need help with what goes in your "else if (numItems == 2)" block? if so, think about what the requirements say you should do for two items. if someone enters "30" (assuming seconds), how long should 2 items ACTUALLY cook for? what if they enter 10 seconds? after you figure that out, ask yourself HOW EXACTLY you calculated your answer. Did you add something? divide? take the sine of an angle? you probably did some kind of math. If you get a specific answer (like "i took 10 and raised it to the 3rd power, and I took 30 seconds and raised it to the third power"), see if you can generalize it into an equation, like "I took the input and raised it to the third power".

Once you figure out how to do this in ENGLISH (or whatever your native language is), see if you can translate it into code, a little at a time.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
It is sorta covered in the JavaRanch Style Guide.
subject: Microwave Oven
It's not a secret anymore!