Brief Outline of Contents This Course Is Designed to Familiarize The
Total Page:16
File Type:pdf, Size:1020Kb
Brief Outline of Contents This course is designed to familiarize the student with the advanced concepts and techniques in Java programming. Topics include: Comprehensive coverage of object-oriented programming with cooperating classes; Implementation of polymorphism with inheritance and interfaces; Programming with generics and Java collections; Programming with exceptions, stream input/output and graphical AWT and Swing Prerequisites Programming in Java or its equivalent. Learning Goals Understand the following. The relationships between classes Specification vs. implementation Be able to ... Specify programs Implement many of the features of Java, Standard Edition Test Java programs Required Textbook Y. Daniel Liang, "Introduction to Java Programming," Comprehensive Version, 7th Ed., Prentice Hall, 2007. ISBN-10: 0136012671 ISBN-13: 978-0136012672 Software Required JRE: Java Runtime Environment JDK Any version >= 1.5 (J2SE JDK is fine) IDE: Eclipse is fine (or any other JDK you are comfortable with, like JCreator, NetBeans) Evaluation of Student Work Rev2 Student work will be evaluated as follows. Assignments: 60% Quizzes: 10% Final: 30% 1 There will be an assignment approximately every two weeks; possibly one week at times. Quizzes will be introduced as needed with approximately a week's notice. They will count for 10% of the grade. One quiz does not count, allowing you one absence from class. Otherwise: All pass: A 80-89% passed: B 70-79% passed: C 60-69% passed: D Late homework will not be accepted unless there is a reason why it was not reasonably possible to perform the work in time given work and emergency conditions. In that case, e- mail the written reason should be attached to the homework, which will be graded on a pass/fail basis if the reason is accepted by me. Please see http://csmet.bu.edu/ebraude/GradePolicy.htm for generic information on how grades are allocated and averaged in all of my classes. 2 Warning Concerning Plagiarism The College has serious penalties for plagiarism, including expulsion from the degree program. Please be very careful not to use the work of others without very clear and specific acknowledgement. e-mail, see or call me if you have any doubts. In any case, clearly acknowledge all sources in the context they are used, including code, of course. Please see plagiarism policies http://csmet.bu.edu/ebraude/plagiarism.htm (my hints on this) and here http://www.bu.edu/met/metropolitan_college_people/student/resources/conduct/code.html (MET College) for examples and a full explanation. Schedule of Classes, Topics, and Reading v2 11June2009 The following schedule of classes is subject to small changes, which will be announced in advance. Class # Topic(s) Reading (see Assignment calendar for dates) 1 Introduction. Reviews of Java Chapters 1- Syntax, Control Flows, Arrays 6 2 Objects and Classes, Strings Chapter s7- 9 3 Java Inheritance, Polymorphism, Chapters Abstract class, interface 10-11 4 To be determined 5 GUI components, Swing and Event Chapters Driven Programming 13-15 6 Java Exceptions Chapters18 7 Java I/O and Recursion Chapters 19-20 8 Inner Class and Java Generics Chapters 21 9 Collections and Data Structures Chapters 22-26 10 To be determined 11 Graphs + Multi-Thread Chapters Programming 1 of 2 27-29 12 Graphs + Multi-Thread Programming 2 of 2 13 Java networking programming Chapters 30 14 Review for final 15 Final Exam 3 Contacting me; Info about me To contact me please note the infomation at: http://csmet.bu.edu/ebraude/avail.htm My Home Page: http://csmet.bu.edu/ebraude/index.html Miscellaneous Policies (including homework formats) Pleas see http://csmet.bu.edu/ebraude/PoliciesandPractices.htm . 4 Methods and Conventions for Homework v6 15June2009 Previous version 11June ClassModelTemplate.ppt (19.5 Kb) (Revisions from the previous version are in red.) 1. All homework should be accompanied by thorough JUnit tests (legal combinations, corner cases, and illegal values) 2. Sample outputs 3. Attributes should be named to end with an underscore, as in x_ (local variables, simply x) 4. All classes should show class invariants and be commented at the class level 5. All methods should be commented with INTENT / PRECONDITIONS / POSTCONDITIONS 6. Assume returnXXX is the returned value (if any) 7. Tell where in the code is that fulfills each postcondition 8. Use the notation x’ to denote the value x at the end of a method. If you want to be clear about its value at the beginning, use ‘x. 9. Classes and methods should be listed alphabetically except that test (JUnit) classes should be listed separately from non-test classes 10. Make a requirements document if you need to -- otherwise, I'll use the assignment statement as the requirements. 11. Make a design document, including a class model. 12. Make a ReadMe file with the following, as applicable: (A) instructions about execution (e.g., main() vs. JUnit), (B) improvements you made in the existing code base (including those made in response to my comments) (C) where in the code base the added parts are to be found that respond to the added assignment requirements and (D) anything else that you want me to know up front. 13. Combine all of the above -- except possibly the .java files -- in a Word file, with headings for each. Send this to me, together with a .zip file of all the .java files. 14. Leave in the "drop box", please. Apply the following principles 1. Make variables as local as possible 2. Enforce what you intend (e.g. final for variables whose value should not change) 3. Make parts usable by others (you will be rewarded for using other's past work) 4. Everyone will post their ongoing solutions (I'll explain where and how) Please use the following conventions – or explain how you have improved on them. // <Purpose for class> -- informal, avoid repeating descriptions that appear elsewhere // CONSTANTS ========================================== final int MAX_SIZE = 38; // capitals … 5 // FIELDS =============================================== int size_ = 0; // end with underscore or a convention of your choice … // CLASS INVARIANTS ===================================== // ClInv1 (Informal statement): precise specification, naming variable(s) .... // ClInv2 (Informal statement): precise specification, naming variable(s) .... … // CONSTRUCTORS ====================================== … // METHODS ============================================ // ******************************************* public xxx yyy( int aSpeed, String aBrand) { // use "a" or "an" for parameter names // // PRECONDITIONS: (may involve parameters) // Pre1 (Informal statement): precise specification, almost always naming variable(s) .... // Pre2 (Informal statement): precise specification, almost always naming variable(s) .... // // DEFINITIONS: (if needed) type name = ....; // // POSTCONDITIONS // Post1 (Informal): precise specification, almost always naming variable(s) .... // Post2 (Informal): precise specification, almost always naming variable(s) .... // When naming variables, make them expressive but distinguishable from plain English. // For example, "totl," so one can comment like: "totl is the total reciepts for ..." code (indicate clearly where the postconditions are fulfilled) } Here is an example. /* * Use of simple credit card operations to demonstrate a set of standards */ package creditCard; public class CreditCard { // CONSTANTS ========================================== private final int DEFAULT_CREDIT_LIMIT = 0; // per company policy 12094 6 private final int CREDIT_LIMIT = 100000; // per company policy 12345 // FIELDS =============================================== private int creditBalance = DEFAULT_CREDIT_LIMIT; // CLASS INVARIANTS ===================================== // ClInv1 (No overdrafts): creditBalance>=0 // CONSTRUCTORS ======================================= private CreditCard() { creditBalance = DEFAULT_CREDIT_LIMIT; } // ******************************************* public CreditCard( int aCreditLimit ) { // PRECONDITIONS: // Pre1: aCreditLimit>100 // Pre2: aCreditLimit<=CREDIT_LIMIT creditBalance = aCreditLimit; } // METHODS ============================================ // ******************************************* public int getBalance() { return creditBalance; } // ******************************************* public boolean charge( int aChargeAmount ){ // // PRECONDITION: aChargeAmount>0 // // DEFINITION: int balAfterDeduction = creditBalance-aChargeAmount; // // POSTCONDITIONS // Post1 (Deduct funds if sufficient): // balAfterDeduction<0 OR creditBalance'==balAfterDeduction // Post2 (Tell whether deducted): // (balAfterDeduction>=0) returned // ******************************************** //// Post1 (Deduct funds if sufficient): if( balAfterDeduction>=0 ) creditBalance = balAfterDeduction; //// Post2 (Tell whether deducted): return (balAfterDeduction>=0); } } 7 ====================================== = package creditCard; import junit.framework.TestCase; public class TestCredtCard extends TestCase { public void testCharge() { // Nominal Case CreditCard creditCard1 = new CreditCard( 1000 ); // initial balance assertEquals( creditCard1.charge( 1 ), true ); assertEquals( 999, creditCard1.getBalance()); // Corner Case: Too high assertEquals( creditCard1.charge( 1000 ), false ); assertEquals( 999, creditCard1.getBalance() ); // balance unchanged } } A recommended template for constructing class models is attached for you to use for clarity. You are free to use better ones. Homework Grading Criteria Criteria D C B- B+ AB A+ Passes a Passes a