CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

34
CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010

Transcript of CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Page 1: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

CIS 234: Project 1 Issues

Dr. Ralph D. WestfallApril, 2010

Page 2: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

What Is Feedback? comments and suggestions

designed to help you improve your skills

much of the information in this presentation should be relevant to Project 2

What is feed-forward?

Page 3: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Specifications Are King always do projects based on what

requirements say if disagree with requirements,

discuss with client client may agree to change if she

understands that what you want to do is better

Page 4: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

General Requirements put statement that code is own work,

AND that you have protected security of code at top, followed by S-signature

only one zip file, only one Word file don't put zip files inside zip files .java files shouldn’t be submitted as .txt

Word and zip files must be named with last name before 1st name

Page 5: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Missing Parts many students didn't do the Excel

file will be in Project 2 and will cost 5

points if missing UML diagram also missing in many

projects not in Project 2, but may be in Project 3

output missing in a few projects

Page 6: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Documentation in Code comment anything unusual or "tricky"

don't need to comment very obvious things I look for comments on complicated things

don't repeat comments for same thing avoid "wordy" comments

incomplete sentences, bad grammar ok comments should relate to code

get rid of "instructional" comments

Page 7: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Documentation in Code - 2 use multiple line comment feature for

long comments, and at start of program/*

*/ use line breaks to improve readability

to separate self-contained blocks (similar to paragraphs in an essay)

Page 8: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Identifier Naming Convention variables, methods, classes and

objects Class name starts with a capital letter all others have a lower case 1st letter,

upper case for other words ("camel case"), as in iPhone, iPod, iMac, eBay (others?)

capitalize initial letter of each added word in all identifiers e.g., SpeechFormatter, joeThePlumber kangasPerYear, calcPrintResults()

Page 9: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Other Naming Issues use all capitals for constants

use underscores (_) in constants, not in other identifiers

use meaningful variable and object names shoesQuantity is better than shoes subtotal1 is NOT meaningful

Class name needs to be same as its java filename (won't run if it isn't)

Page 10: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

More Naming Issues capitalization is important:

ownerwages != ownerWages

Page 11: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Output Format include formatting required in

specifications (can add if not specified but makes sense) title, line labels ---------- (underlining?) column alignment (#s right justified) sub- and grand totals aligned

appropriately spelling correct

Page 12: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Declarations declare all variables at the start of

their methods don't bury declarations below among

action statements use appropriate data types

don't use integers for dollar amounts don't use double or float for quantities

(e.g., # of items) or counts

Page 13: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Declarations - 2 declare (and initialize) first, calculate

laterint shoesPerYear;// other declarations

// imperative ("action") codeshoesPerYear =

yearDays*shoesPerDay;

Page 14: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Declarations - 3 whenever possible, declare objects

first, then instantiate them later in imperative code

Employee daBoss;// other declarations

// imperative ("action") codedaBoss = new

Employee(Inputs.getBossWages);

Page 15: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Getters and Setters represent the implementation of

the concept of encapsulation ("data hiding")

purpose of a set (and often a constructor) is to allow another class to store a value in an object

purpose of a get is to allow another class to read the value of a variable in an object

Page 16: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Get and Set a get should always return a value a set should always store a value

usually don't have a return statement in a set method, except possibly when a boolean is returned to show it worked OK

declare variables at top of class, not in their own set or get methods

Page 17: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

All Data in Inputs.java File almost every data item used in

StoreApplication.java needs to be declared in Inputs.java also need getter methods there to

return each value to StoreApplication.java

except could put private final int YEAR_MONTHS =

12; in StoreApplication.java

Page 18: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Calculations in StoreApplication.java Inputs.java file is designed to just

be used for supplying data put calculations in

StoreApplication.java file instead

Page 19: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Practice what is wrong with the following

code?

public void setNumber(int num){ int number = num; }

what is the scope of number? (where is its value available?)

Page 20: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Access to Variables variables used by another class

need to be (explicitly) private never read or change their values

directly from outside, use get and set instead

always access them directly inside class don't use class's own get or set

methods inside the class

Page 21: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Access to Variables - 2private int number;public void setNumber(int num){ number = num; }

note that this set method directly writes values to this variable in its class

other methods in this class can directly write values to this variable in its class also

other classes must use its set method

Page 22: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Coding Issues don't "hard code" values in code that

came from outside of your code or were calculated outside of your code use variables instead example: multiply by a price variable

instead of by the literal priceshoesPerYear=

yearDays*shoesPerDay; //OKshoesPerYear=362*shoesPerDay; //not OK

Page 23: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Coding Issues - 2 avoid "dead code"

dead code is a method that is never called by another method in the project

or code that is "commented out" ok if set or get are not called,

because they may be used in future

Page 24: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Coding Issues - 3 avoid unnecessary gets

example: a method may use a set method to store a value in an object

don't have to then use a get method if already have this value in the class that called the set method

Page 25: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Coding Issues - 4 mortgage payment calculations

monthly payment must be annualized interest rate must be decimal, not

percent (0.065 rather than 6.50%)

Page 26: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Coding Issues - 5 recycle previously calculated values

rather than repeating calculationskangaPerYear = Inputs.getKangas()

*Inputs.getDaysPerYear;kangaIncome = kangaPerYear *

Inputs.getKangaPrice();kangaCost = kangaPerYear * … rather

than repeating calculation

Page 27: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Coding Issues - 6 don’t do calculations in a println

statement makes code hard to debug or update

System.out.println("total: " + (totalIncome - totalExpenses))

Page 28: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Appendix following slides don't really apply

to the Project 1 we used in this class

Page 29: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Constructor don't forget to include a

constructor in a class that will be used to create objects

use a constructor method to set individual values that the objects will have instead of initializing these values in

declarations

Page 30: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Constructor - 2private int numHanboks = 2; // OK in a class just used for its variables,

where other classes will use same valuesprivate double wages;

Employee(double wage){ this.wages = wages;} // use a constructor if will create objects

Page 31: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Access to Variables - 3 storing calculated values in an object

if a value changes, anything derived from it almost always should recalculate it

example: if a total is stored as a variable, it should change any time any variable that is part of the total changes

a value's set method could call a calculate method to update values derived from the value

Page 32: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Coding Issues don't use too many methods if doing same thing often, make one

generic method that can be used again e.g., calculating withholding for

different salary levels should always make method private

except if methods in other classes will use it

Page 33: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Coding Issues - 4 if a data adjustment is only

necessary in some situations, make adjustments in the code where the problem occurs (interface), not in a general class

store good data in variables rather than fixing bad data in a get

Page 34: CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.

Software Development Analyses an analysis is different from a plan need most detail on critical issues

for calculations, need to indicate formulas

for output, need to provide information on layout

identify anything unusual less detail on minor issues long write-ups are not good in

business