Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Map;

public class Main {
    /**
     * Returns the value for key in dictionary as a float or 0 if no value is
     * defined for the key.
     * 
     * @param dict
     *            Dictionary that contains the key, value pairs.
     * @param key
     *            Key whose value should be returned.
     * @return Returns the float value for key in dict.
     */
    public static float getFloat(Map<String, Object> dict, String key) {
        return getFloat(dict, key, 0);
    }

    /**
     * Returns the value for key in dictionary as a float or the given default
     * value if no value is defined for the key.
     * 
     * @param dict
     *            Dictionary that contains the key, value pairs.
     * @param key
     *            Key whose value should be returned.
     * @param defaultValue
     *            Default value to return if the key is undefined.
     * @return Returns the float value for key in dict.
     */
    public static float getFloat(Map<String, Object> dict, String key, float defaultValue) {
        Object value = dict.get(key);

        if (value == null) {
            return defaultValue;
        } else {
            return Float.parseFloat(value.toString());
        }
    }
}