Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2004, 11:41 AM
Registered User
 
Join Date: Jan 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default ch4 wrong output?

For CarBean.java and for carPage2.jsp on page 85, my output is:

Using a JavaBean
I have a Ford
My car costs $20000.175

On page 86 the book's output is:

Using a JavaBean
I have a Ford
My car costs $11750.0

Can someone please verify if the book is right or wrong and/or lmk your output?

Thanks!

Pete
 
Old January 23rd, 2004, 12:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Pete,

The book is right.

private double cost = 10000.00;
private double taxRate = 17.5;

public double getPrice(double p)
{
    return (p + (p * (taxRate/100)));
}


The above method will return 11750.0


I'm guessing that you have added the cost to the tax percentage rather than multiplied by it. i.e.

(p + (p + (taxRate/100)));

Which will return 20000.175, which is wrong. Replace the second + with a * and you should get the expected result.


Cheers

Martyn
 
Old January 23rd, 2004, 09:33 PM
Registered User
 
Join Date: Jan 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're correct! Sorry for such a trivial posting all........ I thought it was another error in the book.....

Thanks for the help Martyn!

Pete

Quote:
quote:Originally posted by Martyn
 Pete,

The book is right.

private double cost = 10000.00;
private double taxRate = 17.5;

public double getPrice(double p)
{
    return (p + (p * (taxRate/100)));
}


The above method will return 11750.0


I'm guessing that you have added the cost to the tax percentage rather than multiplied by it. i.e.

(p + (p + (taxRate/100)));

Which will return 20000.175, which is wrong. Replace the second + with a * and you should get the expected result.


Cheers

Martyn
 
Old January 24th, 2004, 09:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Pete,

Glad to be able to help. If you haven't already done so, you might want to download the source code for the book, that way you will have something to compare your own code to.

Cheers

Martyn


Cheers

Martyn





Similar Threads
Thread Thread Starter Forum Replies Last Post
VB: Ch4 p123 How It Works (Personalisation) Rich57 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 October 19th, 2007 07:23 AM
VB: Ch4 p132 Security Try It Out Rich57 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 October 19th, 2007 05:05 AM
Ch4 Problem daivos03 JSP Basics 9 January 30th, 2006 01:57 AM
Problems in Ch3 and Ch4 Maram BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 August 4th, 2005 09:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.