aspose file tools
The moose likes Beginning Java and the fly likes Problem regarding a field of type Bigdecimal Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Problem regarding a field of type Bigdecimal" Watch "Problem regarding a field of type Bigdecimal" New topic
Author

Problem regarding a field of type Bigdecimal

nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Hi all,

I don't know if this is the right forum to post my question. If it is not, then move to the right place. I have three conditions. I have three fields of type BigDecimal.
1. If I enter $100.00 in one field, then it should show $100.00 in the second field and $75 in the third field which is working fine.
2. If I enter $0.00 in one field, then it should show $0.00 amounts in other fields which is working fine too.
3. If I enter nothing or blank, then it should show blank for all the fields based on my condition but this is not working for second and the third fields and it reads the value from the first field.

I have the following code, so please guide me in this regard.



Thank you so much for your time.

Naveen Katoch
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

authAssessedAmount is an BigInteger and comparing it to a String doesn't work.

You should really reconsider renaming the class and method. Because what is a LITI_AutoPopEsStHghEsStLOnAssdAmnt?
You can't derive that from the name. And what does action do?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
You might also consider an enum for the type of Action. Or maybe putting action types into a Map. Those multiple ||s are potentially error-prone. What happens if you add "Employment" as a potential type of dispute? What happens if your dispute is about a "Company car"?
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Thank you so much Wouter and Campbell for your inputs. I will workaround. If I could not resolve this issue, then I will ask this in SCJP forum.

Thanks again,

Naveen Katoch
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

nav katoch wrote:If I could not resolve this issue, then I will ask this in SCJP forum.

Why? This does not look like it has anything to do with the SCJP certification exam. Please stay in this topic with regard to this issue.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
You're welcome
nav katoch wrote:. . . I will workaround. . . .
I am sure that by "workaround" you mean you will create a good solid solution, but workaround often means a Heath Robinson sort of solution which can be brittle and introduce more errors.
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Hi Campbell,

I have resolved the issue with the following code and set my operator to Not Populated in my rule:-



Thanks for your time. I appreciate you all.

Naveen Katoch

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I've got some more remarks:

(Still) the class name
Line 11: TCLog.getRuleLogger().debug((new StringBuilder("In action() method Current User is ::--> ")).append(currentUser).toString()); Why not just concatenate with +?
Line 16: Why not use this object through out the method instead of getting it constantly with dispute.getDetailForKey("LITI");
Line 18: Why declare it there when it only gets used in the if-block and gets assigned there?
Line 19: Why declare it there when it only gets used on line 36?
Line 20: Why declare it there when it only gets used on line 36?
Line 30 & 33 in if and else part are the same.
Line 34: didn't you just set that?
Line 36: you're multiplying it with 75 and then 100? Why not multiply it with 7500?
Line 42: why not chain the exceptions and retain the stacktrace?
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Hi Wouter,

Thank you so much for bringing these points in my notice. I highly appreciate your time and suggestion. I will modify it accordingly.

Naveen Katoch
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You're welcome.

I just thought of another remark: line 18 & 25 can be modified to use BigDecimal.ZERO.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

Wouter Oet wrote:Line 36: you're multiplying it with 75 and then 100? Why not multiply it with 7500?

He's not multiplying by 75 and 100, but multiplying by 75 and dividing by 100.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

So multiplying by a new BigDecimal("0.75") would work just as well.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Rob Spoor wrote:So multiplying by a new BigDecimal("0.75") would work just as well.
It wouldn't work as well at all. It would work better because there is only one new BigDecimal object created.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Problem regarding a field of type Bigdecimal
 
Similar Threads
JSF Request Processing Lifecycle Basics
problem in name and password fields validation
Returning A List Of Variables From A Folder Of Documents And Returning Them Into A New Document
There is no Action mapped for action name prePaymentManager
Jsp is not displaying in Struts2