Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 type of variables or literals as parameters Example: cos can only be passed a double

2 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

3 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

4 Chart page 211 shows types of data sample values, patterns, formatted strings Characters: # 0, E $ all possible Insert digits or specified characters

5 “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.

6 The sin method page 216 sin method returns the result of the absolute value of parameter x.

7 Graphics pages 217-218-219 y = ax 3 + bx 2 + 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

8 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”);


Download ppt "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."

Similar presentations


Ads by Google