Last active
December 5, 2015 06:21
-
-
Save golenishchev/e2623c5fe75c77acafe6 to your computer and use it in GitHub Desktop.
Lesson 10. 2D array. String + int. Object
This file contains hidden or 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 int divResultValue; | |
| private int array; | |
| private int twoDimArray; | |
| 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); | |
| } | |
| public int getDiv(int firstNumber, int secondNumber) { | |
| return divResultValue = firstNumber / secondNumber; | |
| } | |
| public void printDivResult(int divResultValue) { | |
| System.out.println("Division result value: " + divResultValue); | |
| } | |
| /* BEGIN methods of Math class */ | |
| public double getSqrt(double numberBeforeSquareRootExtraction) { | |
| this.numberBeforeSquareRootExtraction = numberBeforeSquareRootExtraction; | |
| return squareRootCalcResult = Math.sqrt(numberBeforeSquareRootExtraction); | |
| } | |
| public double getSine(double angleBeforeSineCalc) { | |
| this.angleBeforeSineCalc = angleBeforeSineCalc; | |
| return sineCalcResult = Math.sin(angleBeforeSineCalc); | |
| } | |
| /* Array */ | |
| public void findMaxInAnArray(int[] array) { | |
| int max = array[0]; | |
| for(int i = 0; i < array.length; i++){ | |
| if(max < array[i]) | |
| max = array[i]; | |
| } | |
| System.out.println("Maximum in an array: " + max); | |
| } | |
| public void storeResultInAnArray(Object[][] twoDimArray) { | |
| for(int row = 0; row < twoDimArray.length; row++) { | |
| for(int column = 0; column < twoDimArray.length; column++) { | |
| System.out.print(twoDimArray[row][column] + "\t"); | |
| } | |
| System.out.println(); | |
| } | |
| } | |
| public static void main(String[] args) { | |
| Calculator myCalc = new Calculator(); | |
| int resultValue = myCalc.getSum(10, 5); | |
| myCalc.printResult(resultValue); | |
| myCalc.getDiv(10,2); | |
| myCalc.getSqrt(100.0); | |
| myCalc.getSine(30.0); | |
| int [] array = {12,1,5,-11,7,13,-1,-5}; | |
| myCalc.findMaxInAnArray(array); | |
| Object[][] twoDimArray = new Object[2][2]; | |
| twoDimArray[0] = new String[]{"sum", "division"}; | |
| twoDimArray[1] = new Integer[]{myCalc.resultValue, myCalc.divResultValue}; | |
| myCalc.storeResultInAnArray(twoDimArray); | |
| 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