![Page 1: Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with](https://reader036.vdocument.in/reader036/viewer/2022083005/56649f185503460f94c2ec50/html5/thumbnails/1.jpg)
CalculationsChapter 11
Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp
Constants .PI, .EUse care with type of variables or literals as parameters
Example: cos can only be passed a double
![Page 2: Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with](https://reader036.vdocument.in/reader036/viewer/2022083005/56649f185503460f94c2ec50/html5/thumbnails/2.jpg)
Formatting numbers
• Create an instances of class DecimalFormat (supply a desired pattern call method ‘format’) – int i = 123;– DecimalFormat formatter = new
DecimalFormat (“###”);– textField.setText(formatter.format(i));– // gives 123 in textField
![Page 3: Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with](https://reader036.vdocument.in/reader036/viewer/2022083005/56649f185503460f94c2ec50/html5/thumbnails/3.jpg)
DecimalFormat (“0000”); …
• Produces 0123// given int i = 123• int i = 123456; … (“###,##);• produces 123,456• double i= 12.34; … (“###.##); …• Produces 12.34• double number = 12300000; … (“0.###E0”)
Produces 123E7• double money = 12.34; …(“$###.##”) Produces
$12.34
![Page 4: Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with](https://reader036.vdocument.in/reader036/viewer/2022083005/56649f185503460f94c2ec50/html5/thumbnails/4.jpg)
Chart page 211 shows types of data sample values, patterns,
formatted strings
• Characters: # 0 , E $ all possible
• Insert digits or specified characters
![Page 5: Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with](https://reader036.vdocument.in/reader036/viewer/2022083005/56649f185503460f94c2ec50/html5/thumbnails/5.jpg)
“Money” page 212
• Calculates compound interest. User enters integer amount and interest rate, program calculates interest over a period of year.
• Class “Interest” page 214-215
• Case Study “Iteration” loops that search for a solution until found to sufficient accuracy.
![Page 6: Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with](https://reader036.vdocument.in/reader036/viewer/2022083005/56649f185503460f94c2ec50/html5/thumbnails/6.jpg)
The sin method page 216
• sin method returns the result of the absolute value of parameter x.
![Page 7: Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with](https://reader036.vdocument.in/reader036/viewer/2022083005/56649f185503460f94c2ec50/html5/thumbnails/7.jpg)
Graphics pages 217-218-219
• y = ax3 + bx2 + cx + d
• a,b,c and d input via slider
• Output scaled to fit within a panel 200 x 200 pixels ( -5.0 to +5.0) One unit x or y is 20 pixels
• Program calculates x value from x pixel value, y value, the value of the function
• y pixel value from the y value
![Page 8: Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with](https://reader036.vdocument.in/reader036/viewer/2022083005/56649f185503460f94c2ec50/html5/thumbnails/8.jpg)
Exceptions
• Overflow of ints (how to handel exceptions see chapter 16 for detail)
• Avoid exceptions by checking for them– if ( length > 1000 ) {
• answerTextField.setText (“value too large”);