OK, so I'm trying to make a program where you input a number and the program takes its square root. Yes, I realize I could do all this on a main but where is the fun in that? I know I'm close, but I'm just not seeing my error! Result shows no errors on either program, but whatever number I input the answer is 0.0
SUB
public class FunMath { public FunMath() { double number = 0; } public void enterNumber(double amount){ factor = number + amount; } public double giveResult(){ double result = Math.sqrt(factor); return result; } private double factor; private double number; }
Main
import java.util.*; public class FunMathTester { public static void main(String[] args) { Scanner in = new Scanner(System.in); FunMath squareroot = new FunMath(); System.out.print("Enter the number you wish to take a square root of: "); double number = in.nextDouble(); System.out.println(squareroot.giveResult()); } }