Question: Hi, new to java and need some help on coding homework. Trying to do code for Linear Interpolation. See code below: My if statements for
Hi, new to java and need some help on coding homework. Trying to do code for Linear Interpolation. See code below: My if statements for assigning x == x0 if x < x0 is wrong and so are my other else statements for what I want to do with x. Can someone help me in figuring out why they are not working and why it would not be a statement? Also, a review to see if everything else in calculateLerp just to see if it is all good would be great! Thank you! Homework prompt will be attached and code is below. (Have not finished working on my main function, but any suggestions there would help too, thanks!)
package linearinterpolation;
import java.util.Scanner;
public class LinearInterpolation { public static float calculateLerp (double x0, double x1, double y0, double y1, double x){ float lerp = (float) (((y1-y0/x1-x0)*(x - x0))+ y0); if ( x < x0) { x == x0; } else if (x0 <= x <= x1); continue else { x == x1; }
if ( x1 < x0) { System.out.println("x1 value must be greater than x0 value."); } else continue if ( y1 < y0) { System.out.println("y1 value must be greater than y0 value."); } else continue return lerp; }
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double value1; System.out.println("Enter Xmin, Xmax, Ymin, Ymax, and an input value to test, separated by spaces."); value1 = scanner.nextDouble(); //if (x1 < x0, then x1 == x0 //if x0 > x1, then x0 == x1 //source range: x0 < x1 //target range y0 < y1 } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
