Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7920343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:10:54+00:00 2026-06-03T16:10:54+00:00

I am working on a function where I am calculating meter units to amount.

  • 0

I am working on a function where I am calculating meter units to amount. Rules for meter calcualtions are :

  • Minimum fare on 1.6km amt – 12/-
  • Subsequent 1 km amt – 7/-
  • 25% additional fare for journey for midnight

The function I have written is :

public static void CalculateAutoFare(int kmIndex) {
    double fare = 12.00;
    double night = 15.00;
    double subseIncre = 1.50;
    double nightIncre = 0.25;
    int j=0;

    for (int i=1; i <= kmIndex; i++) {

        if (i == 3 || j == 4) {
            fare += 1.00f;
            j =0;
        } 
        else {
            fare += subseIncre;
            j++;
        }
        fare = Math.round(fare*2f)/2f;
        double extra = ((double) fare * nightIncre);
        night = fare + extra;
        night = Math.round(night*2f)/2f;

        System.out.println("I = " + i + " Fare = " + fare + " Night = " + night + " 25%Extra = " + extra);
    }

    System.out.println("Day = " + fare + " Night = " + night);
}   

kmIndex is the index of km. Meter readings are as 1.00, 1.10, 1.20, 1.30…1.90, 2.00…. Thus kmIndex for 1.00 = 0, 1.10 = 1, 1.20 – 3 and so on.

Results that I get as per code and should be is mentioned below :

enter image description here

I have worked till 4.00 and where the results are not right are declared undet Should Be of relevant to Day or Night.

I worked a lot on this but couldn’t get results as expected. If I try to correct 1 thing then other gets wrong or doesn’t give expected results. Can anyone help me out with this. Have spent almost whole day trying to solve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:10:58+00:00Added an answer on June 3, 2026 at 4:10 pm

    I’ve analyzed the worksheet and I haven’t found a formula that gives the results shown there. It seems that some values have some rounding differences. I’ve realized that only the values with 25 or 75 cents were different. For example, you calculated 18,5 and it should be 19 (the result was 18,75 and you rounded down to 18,5, but it should be rounded up to 19).
    So, if you don’t have the original formula that was used to create the table, I think the only way to be sure that the results will match the worksheet is to hardcode it. It’s not an elegant solution, but it guarantees the correct result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function working <script type=text/javascript> $(window).scroll(function() { if ($(window).scrollTop() == $(document).height() -
I'm having a lot of difficulty getting strophe's 'attach()' function working. I am working
the second function isnt working? $('.edit_hover').live('hover', function(e){ $(this).stop(); var half_width = ($(this).css('width').slice(0, -2))/2; var
I'm working on a function that handles events from a number of buttons and
I am working on a function that will essentially see which of two ints
Does anyone have a working class or function to create the hashed email that
i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
I really need some help in Regular Expressions, i'm working on a function like
The function associated with the selector stops working when I replace it's contents using
Original Working VB_Code Private Declare Function ConnectReader Lib rfidhid.dll () As Integer Private Declare

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.