Let me guess: it's multiplying the cost by nine no matter what number of
days is input?
You have a single line in "conversions" to parse the cost, but none to
parse the days or other numbers (date, etc.); you even had compiler
errors about these "may have been used uninitialized" and went and
initialized them to dummy values. (The "date" which will come out as the
integer value zero being especially odd. I think you want a
java.util.Date and the "conversions" section using DateFormat here.)
Add the other conversions (and remove the dummy values; let the compiler
alert you if you miss any of the conversions until you have them all)
and it should then work properly.
mara.aelene@gmail.com - 24 Sep 2007 02:56 GMT
> Let me guess: it's multiplying the cost by nine no matter what number of
> days is input?
[quoted text clipped - 9 lines]
> alert you if you miss any of the conversions until you have them all)
> and it should then work properly.
Thank you to you both, (although sorry but the second response was
much more helpful) I am trying to learn jav, and am two weeks into a
class. Appreciate the first response but doesn't seem to help me
learn... had no idea what you were talking about. :)
Ben - I thought "int" in the variable section was to declare an
integer, not an initialization... The dates didn't really need to be
parsed, I didn't think be cause I only need the duration multiplied by
the cost. And yes, it is coming up with an answer in multiple of
nine... but can't understand why at all.
Sorry for asking a "school" question here - but I thought it was a
forum to get help and I'm really trying to learn this stuff.
mara.aelene@gmail.com - 24 Sep 2007 03:00 GMT
Ok so, it's multiplying by 9 of course, because of the variable
section. :) I thought 9 could be used as a integer declaration, like
in COBOL. I take it, no it cant
Ben Phillips - 24 Sep 2007 03:10 GMT
> Thank you to you both, (although sorry but the second response was
> much more helpful) I am trying to learn jav, and am two weeks into a
> class. Appreciate the first response but doesn't seem to help me
> learn... had no idea what you were talking about. :)
Sorry -- hard sometimes to gauge someone's level of knowledge from one
post. Joshua makes some good points, although I feel he might have been
more diplomatic about some of them -- perhaps we both could.
Nonetheless, asking yourself simply how I knew it was multiplying by
nine might give an idea as to how one might go about investigating a
bug. :) (And no, I didn't compile and run it either.)
> Ben - I thought "int" in the variable section was to declare an
> integer, not an initialization...
It is. The initialization occurs if you put "int variableName = value;"
rather than just "int variableName;", or later if you put "variableName
= value;" for the first time.
> The dates didn't really need to be parsed, I didn't think be cause
> I only need the duration multiplied by the cost. And yes, it is
> coming up with an answer in multiple of nine... but can't
> understand why at all.
Study it until you do; trace through the code seeing how the numbers
travel and get to where they're going. Or start somewhere and work your
way backwards -- where do the two variables in the multiplication get
their values? Work upwards from the multiplication until you find each.
If the dates are just read and later printed back to the screen, and
don't need to be validated or otherwise interpreted by the code, I'd
just store them in a String and feed them back to the output whenever
needed, without trying to parse them into Date objects, integers, or
anything else.
mara.aelene@gmail.com - 24 Sep 2007 03:20 GMT
> mara.ael...@gmail.com wrote:
> > Thank you to you both, (although sorry but the second response was
[quoted text clipped - 32 lines]
> needed, without trying to parse them into Date objects, integers, or
> anything else.
Well I've got it figured out and traced it back. But I don't
understand what value I can use in declaring the variables. Whatever
number I use, it's trying to multiply by that number, not what's
entered in from the user prompt. Don't understand what values are
used to "store"
mara.aelene@gmail.com - 24 Sep 2007 03:27 GMT
I got it figured out! Thank you very much for your assistance.
Ben Phillips - 24 Sep 2007 03:32 GMT
> I got it figured out! Thank you very much for your assistance.
You're welcome.
> I can't figure out why the mathematical calculations are not working
> in this program. It should be taking the duracion (number of days)
> times the cost of the unit. This is for a university class and I
> could really use the help.... please!
The English word is `duration', not `duracion'. Furthermore, refrain
from asking homework questions on Usenet.
> import java.util.Scanner;
>
[quoted text clipped - 3 lines]
> public static void main (String[] args)
> {
Don't use tabs in Usenet posts.
> String titlePage = "\tWelcome to Yellowstone National " +
> "Park's Lodging Reservation System.\n\n" +
> "To complete your reservation, pleae answer the following
> questions.\n" +
> "(After each entry, press the ENTER key. Enter only one value per
> question.\n\n";
Try to watch what you post so that you do not hit GG's 80-character
line-width limit.
> Scanner dosInput = new Scanner(System.in);
>
[quoted text clipped - 3 lines]
> String customerDateString;
> int customerDate = 99/99/9999;
I doubt that your initialization of customerDate is what you want it to
be. Its value will be 0.
In addition, it is generally preferred in the Java world to declare
variables at the point of initialization and not at the beginnings of
functions.
> String customerDuracionString;
> int customerDuracion = 9;
[quoted text clipped - 19 lines]
> System.out.print("What is the duracion of your stay?");
> customerDuracionString = dosInput.next();
java.util.Scanner provides nextDouble(), nextInt(), etc. methods to
immediately parse at input time to the correct data type. Prefer those
over running the {Type}.parse{Type}() methods later on.
> System.out.print("What is the cost of per-night rental?");
> customerCostString = dosInput.next();
[quoted text clipped - 4 lines]
> //Calculations
> customerTotal = Math.round(customerCost * customerDuracion);
I find that people learn best when guided towards the answer and not
told the exact problem. This line contains the first error that I found.
You should be able to find this error by following one of the two points
I made above:
1. Do not declare your variables until they are initialized.
2. Use the nextDouble(), etc. methods instead of next() + parseDouble(),
etc.
Other methods to solve your error:
3. Don't pre-initialize your declared variables.
4. Step through each line of code with a debugger that displays the
value of every single local variable.
My personal preference is that you use both steps 1 + 2 to solve your
answer.

Signature
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Matt Humphrey - 24 Sep 2007 12:08 GMT
| > I can't figure out why the mathematical calculations are not working
| > in this program. It should be taking the duracion (number of days)
[quoted text clipped - 3 lines]
| The English word is `duration', not `duracion'. Furthermore, refrain
| from asking homework questions on Usenet.
It is perfectly reasonable to ask homework questions on this group (although
comp.lang.java.help is a better choice) provided that the poster has not
simply posted the homework assignment or asked the group to do the homework
for him/her and has made an attempt at solving the problem.
http://mindprod.com/jgloss/homework.html
http://mindprod.com/jgloss/newsgroups.html#RESPONSES (homework section)
Matt Humphrey http://www.iviz.com/
>customerTotal = Math.round(customerCost * customerDuracion);
Here is a strategy to solve this.
1. Verify that the problem is truly where you think it is. Do this by
using System.out.println to dump the values of the input to the
calculation.
2. read up on the docs for any methods you use. Don't just assume
they behave the way they "should". See
http://mindprod.com/jgloss/round.html
Pay particular attention to the types of the parameters and the
results.
P.S. the spelling is "duration" not "duracion".

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com