Menu
Question Index
...


Given the mappings of the numbers and their values, write a program to estimate a value at some other number using linear interpolation.
If the given key is out of range in the map then return null.

Input (Map, double) Output (Double)
[40.0=>170.0, 80.0=>210.0, 110.0=>300.0, 90.0=>250.0, 20.0=>150.0, 10.0=>100.0, 50.0=>190.0], 95.0 262.5
[57.0=>40.0, 38.0=>10.0, 133.0=>30.0, 190.0=>25.0, 209.0=>35.0, 95.0=>15.0, 74.0=>20.0, 19.0=>5.0], 72.0 22.35294
[510.0=>105.0, 520.0=>110.0, 530.0=>115.0, 500.0=>100.0, 540.0=>120.0], 528.0 114.0
[15.0=>50.0, 30.0=>65.0, 90.0=>120.0, 45.0=>55.0, 60.0=>85.0, 150.0=>170.0, 100.0=>98.0], 45.0 55.0
[15.0=>50.0, 30.0=>65.0, 90.0=>120.0, 45.0=>55.0, 60.0=>85.0, 150.0=>170.0, 100.0=>98.0], 170.0 null

class LinearInterpolation

{    public static void main(String s[])
    {
        Map input = new HashMap();
        input.put(10.0, 100.0);
        input.put(20.0, 150.0);
        input.put(40.0, 170.0);
        input.put(50.0, 190.0);
        input.put(80.0, 210.0);
        input.put(90.0, 250.0);
        input.put(110.0, 300.0);
        System.out.println("Estimated value is :  " + estimateTheValue(input, 70.0));

    }


public static Double estimateTheValue(Map<Double, Double> input, double searchNumber) {
//Write code here to estimate the value at the given number
}
}

Doubts

Problems

Topic: Java HashMap Implementation

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App