Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2011 Pearson Education, publishing as Addison-Wesley Tuesday 9-2-14 After answering the questions after logging in, open BlueJ and the Formula class.

Similar presentations


Presentation on theme: "© 2011 Pearson Education, publishing as Addison-Wesley Tuesday 9-2-14 After answering the questions after logging in, open BlueJ and the Formula class."— Presentation transcript:

1 © 2011 Pearson Education, publishing as Addison-Wesley Tuesday 9-2-14 After answering the questions after logging in, open BlueJ and the Formula class. Check the schedule Identifier Rules and Conventions Constants Static Methods JavaDoc Requirements

2 © 2011 Pearson Education, publishing as Addison-Wesley 2 Java Program Structure  A Java application always contains a method called main  Our Point and Formula classes do not contain a main method. They are classes but they are not applications.  Our aMain class is an application, it has a main method.  We could put a main method in the Point and Formula Class.

3 © 2011 Pearson Education, publishing as Addison-Wesley 3 Three Types of Comments // this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */ /** * this is a javadoc comment * */

4 © 2011 Pearson Education, publishing as Addison-Wesley 4 What is an identifier?  Identifiers are variables, constants, and methods the programmer creates and uses in a program.  Rules for creating identifiers must be followed or the code will NOT compile.  Conventions are adopted programming practices. The code will still compile if the convention is not followed.

5 © 2011 Pearson Education, publishing as Addison-Wesley 5 2 Rules for Creating Identifiers  Rule 1 : An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign  Rule 2 : Identifiers cannot begin with a digit  Java is case sensitive - Total, total, and TOTAL are different identifiers  Identifiers should be meaningful, not too short or long.

6 © 2011 Pearson Education, publishing as Addison-Wesley 6 Conventions – Class Names  The First letter in each word is capitalized. Point Formula Math HelloWorld ArrayList

7 © 2011 Pearson Education, publishing as Addison-Wesley 7 Conventions – Variable and Method Names  The first word is all lowercase. The first letter of following words are capitalized. name average lastName xCoord getX public double CylinderVolumewithRadiusandHeight (double R, double H) {return Math.PI*(R*R)*H;} public double CubeVolumewithSide (double X) {return X*X*X;}

8 © 2011 Pearson Education, publishing as Addison-Wesley 8 Conventions – Constants  Constants are special identifiers that can NOT be changed.  Constants are all UPPERCASE. MAX PI  Multiple word constants are separated by an underscore _ TAX_RATE FT_MILE

9 © 2011 Pearson Education, publishing as Addison-Wesley JavaDoc Requirements  Class JavaDoc Description of the class @author followed by your name without parentheses  @author Larry Kedigh //correct  @author (Larry Kedigh) //incorrect @version followed by the date the class was created.  Method JavaDoc Description of the method @param description of the variable @return description of what is returned. 9

10 © 2011 Pearson Education, publishing as Addison-Wesley public double areaHexagon1 (double x) { return 2.598076211*Math.pow(x,2) ; } Example 1 – Constants 10

11 © 2011 Pearson Education, publishing as Addison-Wesley Example 1 11 public double areaHexagon1 (double x) { return 2.598076211*Math.pow(x,2) ; } Magic Number

12 © 2011 Pearson Education, publishing as Addison-Wesley public double areaHexagon2 (double x) { final double CON_FACTOR = 3*Math.pow(3,.5)/2; //hexagon formula return CON_FACTOR*Math.pow(x,2) ; }//end aHex Example 1 – Constants 12 public double areaHexagon3 (double x) { // conversion factor in area of hexagon formula // (3 * sqrt(3))/2 return 2.598076211*Math.pow(x,2) ; } //end aHex

13 © 2011 Pearson Education, publishing as Addison-Wesley /** * Calculates the area of a Hexagon * * @param x Length of a side * @return The area in square units */ public double areaHexagon2 (double x) { final double CON_FACTOR = 3*Math.pow(3,.5)/2;//hexagon formula return CON_FACTOR*Math.pow(x,2) ; } Example 1 – JavaDoc 13

14 © 2011 Pearson Education, publishing as Addison-Wesley Formula Class Assignment  Edit your Formula class so that The identifier naming convention is followed JavaDoc for each method Magic numbers removed  Link to submission form – will be on the site after class Link to submission form 14 Grading - 80 pts possible The identifier naming convention is followed in all methods(10 pts) JavaDoc for 10 of the 20 method (3 pts/method, 30 total) Magic number / Constants are appropriate in all methods(10 pts) Style and consistency (10 pts) All methods are static (10 pts) Class compiles and works appropriately (10 pts) This due midnight tonight (Tuesday 9-2) One day late -15% or 12 pts. More than one day late - 50% or 40 pts

15 © 2011 Pearson Education, publishing as Addison-Wesley EXTRAS 15

16 © 2011 Pearson Education, publishing as Addison-Wesley /** * Calculates the area of a Hexagon * @param x Length of a side * @return The area in square units * * @see info */ public double areaHexagon2 (double x) { final double CON_FACTOR = 3*Math.pow(3,.5)/2;//hexagon formula return CON_FACTOR*Math.pow(x,2) ; } Insert Images and References in JavaDoc 16


Download ppt "© 2011 Pearson Education, publishing as Addison-Wesley Tuesday 9-2-14 After answering the questions after logging in, open BlueJ and the Formula class."

Similar presentations


Ads by Google