This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Data Manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Data Manipulation" Watch "Data Manipulation" New topic
Author

Data Manipulation

Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
I am doing a data manipulation as below:

Requirement 1:
• Aspect ratios can range from 20 to 85 in increments of 5.
• Round to the nearest 5. Examples: >72.5 and < 77.5, round to 75. >77.5 and < 82.5, round to 80. Valid values include: 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85.
Requirement 2:
o Tire widths can range from 145 mm to 395 mm, in increments of 10 mm; e.g., 145, 155, 165, 175, … 395.
o Round to the nearest value ending in a 5. Examples: if >150 and <160, round to 155. If >220 and <230, round to 225.

For the Requirement 1 I am using the following function and it is working fine. But for the Requirement 2 this function is not working. I would appreciate if someone can help to write a function for the Requirement 2.

Here is the Function for Requirement 1 which is working perfectly. I want to implement a similar function for the requirement 2 for the incremental of 10 instead of 5.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

What did you try for #2, and in exactly what manner is it "not working"?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If your code for Requirement 1 is working perfectly, then the code you posted cannot be the actual code. Or at least if it is the actual code, lines 7 to 9 of your posted code are redundant and could be removed.
Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
I tried this way but I am not getting correct values(10 intervals).


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Okay, so you're not getting the correct values. What values ARE you getting? The more relevant details you provide, the more likely it is that somebody will be willing and able to help you.

ItDoesntWorkIsUseless(←click).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Your requirements are written incorrectly. What do you do for a tyre exactly 160mm wide? You need to check for ≤ and ≥ symbols.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Data Manipulation
 
Similar Threads
SCJD passed 145/155
passed SCJD 145/155
Thanks Ranchers Am Through with 145/155
Math.random()
Passed SCJD 155/155