Results 1 to 2 of 2
Thread: urgent requirement
- 08-25-2010, 05:43 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 6
- Rep Power
- 0
urgent requirement
I have class Person
public class Person{
private String firstName;
private String lastName;
private String type;
................
................
}
type variable can contain employee,self employee,businessman,farmer etc.
Now my requirement is to calculate tax based on type variable.
How can I do this without using clumsy if conditions.
- 08-25-2010, 07:04 AM #2
what if you created an enum, that would be a switch statement then.
or perhaps define a type object base class where it defines abstract methods for getTaxPercent(), which child classes of this would implement to return their specific percentage, where the code then becomes
TypeObj type;
.......
typeobj.getTaxPercentage();
}
and there is no switch or if..else block there at all.
but you can also combine this with enum, have custom enum property. usually tax rates change from time to time, probalby better to not model a tax rate inside an enum field anyway.
I would also say, use a database, where you can model
employee_type,
tax_rate,
effective_from,
effective_to
This gives you the ability to have a point in time rate. consider computing a tax rate for an employee for today. then next month the tax rate changes. if you had to recompute the report for this month in the next month, we would want to have the result be consistent with the point in time the first report was ran.
so for example, we would query this table with JDBC , maybe something like :
select tax_rate from rate_table where employee_type = ? and effective_from <= ? and effective_to >= ?
Similar Threads
-
Urgent Requirement for Senior Technical Consultant @Bangalore
By CVLakshmi in forum Jobs OfferedReplies: 0Last Post: 06-15-2010, 05:29 PM -
Urgent Requirement for Senior Application Engineer in Bangalore
By CVLakshmi in forum Jobs OfferedReplies: 0Last Post: 06-15-2010, 05:22 PM -
urgent requirement...regarding process
By LakshmiSireesha in forum New To JavaReplies: 2Last Post: 01-15-2009, 03:55 PM -
Urgent Requirement for Java/J2ee
By anushareddy7480 in forum Java SoftwareReplies: 1Last Post: 07-23-2007, 01:35 PM -
Urgent Requirement for Java/J2ee
By anushareddy7480 in forum New To JavaReplies: 0Last Post: 07-23-2007, 11:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks