Android Open Source - Mero-Bhada-Meter Fare






From Project

Back to project page Mero-Bhada-Meter.

License

The source code is released under:

GNU General Public License

If you think the Android project Mero-Bhada-Meter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nirab.merobhadameter;
//www .  ja v  a 2  s .  c om
import android.app.AlertDialog;
import android.content.Context;
import android.text.format.Time;


public class Fare {

  double totalfare, distance_road, rateperkm, waitingcharge, maxrate,
      flagdown;
  String vehicle_type;
  Context context;

  public Fare(Context c, Double distance, String type) {
    context = c;
    distance_road = distance;
    vehicle_type = type;
    totalfare = 0.0;

    flagdown = getFlagdownRate();
    rateperkm = getRatePerKm();
    waitingcharge = getWaitingCharge();

  }

  public double calculate() {
    totalfare = (rateperkm * distance_road) + flagdown;
    return totalfare;
  }

  public int getRupees() {
    int rupees = (int) totalfare;
    return rupees;

  }

  public int getPaisa() {
    int paisa = (int) ((totalfare % 1) * 100);
    return paisa;
  }

  public static double getFlagdownRate() {
    Time now = new Time();
    now.setToNow();
    if (now.hour > 06 && now.hour < 20) {
      return 14.0;
    } else {
      return 21.0;
    }
  }

  public static double getRatePerKm() {
    Time now = new Time();
    now.setToNow();
    if (now.hour > 06 && now.hour < 20) {
      return 37.0;
    } else {
      return 55.5;
    }
  }

  public static double getWaitingCharge() {
    Time now = new Time();
    now.setToNow();
    if (now.hour > 06 && now.hour < 20) {
      return 7.40;
    } else {
      return 11.10;
    }
  }

  public void show() {

    AlertDialog.Builder dialogBuilder =

    new AlertDialog.Builder(context);
    dialogBuilder.setTitle("Fare Summary");
    int rupees = (int) totalfare;
    int paisa = (int) ((totalfare % 1) * 100);

    dialogBuilder
        .setMessage(String
            .format("Total distance: %.02f Kilometers \n Total Fare: %d Rupees and %d Paisa",
                distance_road, rupees, paisa));
    dialogBuilder.setPositiveButton("Ok", null);
    dialogBuilder.show(); // display the dialog
  }

}




Java Source Code List

com.nirab.merobhadameter.AsyncTaskCompleteListener.java
com.nirab.merobhadameter.DownloadOfflineData.java
com.nirab.merobhadameter.Fare.java
com.nirab.merobhadameter.MainActivity.java
com.nirab.merobhadameter.MapActivity.java
com.nirab.merobhadameter.MenuActivity.java
com.nirab.merobhadameter.MyPreferencesActivity.java
com.nirab.merobhadameter.OfflineMapActivity.java
com.nirab.merobhadameter.OfflineRoute.java
com.nirab.merobhadameter.SamplesApplication.java
com.nirab.merobhadameter.Utils.java
com.nirab.merobhadameter.ViaPointInfoWindow.java