Skip to content

Instantly share code, notes, and snippets.

@golenishchev
Last active November 27, 2015 15:54
Show Gist options
  • Save golenishchev/8ea5ed9bb434974857d1 to your computer and use it in GitHub Desktop.
Save golenishchev/8ea5ed9bb434974857d1 to your computer and use it in GitHub Desktop.
Lesson 8. Math class. Sqrt, sin methods
class Calculator {
private int firstNumber;
private int secondNumber;
private int resultValue;
private double wowSoSquare;
private double numberBeforeSquareRootExtraction;
private double squareRootCalcResult;
private double angleBeforeSineCalc;
private double sineCalcResult;
public int getSum(int firstNumber, int secondNumber) {
return resultValue = firstNumber + secondNumber;
}
public void printResult(int resultValue) {
System.out.println("Result value: " + resultValue);
}
/* BEGIN methods of Math class */
public double getSqrt(double wowSoSquare) {
numberBeforeSquareRootExtraction = wowSoSquare; //without "this."
return squareRootCalcResult = Math.sqrt(wowSoSquare);
}
public double getSine (double angleBeforeSineCalc) {
this.angleBeforeSineCalc = angleBeforeSineCalc;
return sineCalcResult = Math.sin(angleBeforeSineCalc);
}
public static void main(String[] args) {
Calculator myCalc = new Calculator();
int resultValue = myCalc.getSum(10, 5);
myCalc.printResult(resultValue);
myCalc.getSqrt(100.0);
myCalc.getSine(30.0);
System.out.println("The square root of \"" + myCalc.numberBeforeSquareRootExtraction + "\" is: " + myCalc.squareRootCalcResult);
System.out.println("The sine of \"" + myCalc.angleBeforeSineCalc + "\" is: " + myCalc.sineCalcResult);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment