Last active
November 27, 2015 15:54
-
-
Save golenishchev/8ea5ed9bb434974857d1 to your computer and use it in GitHub Desktop.
Lesson 8. Math class. Sqrt, sin methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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