reviewing for exam lecture 12. lab 1 postfix.java –hexadecimal converting ‘a’ to number...

28
Reviewing for Exam Reviewing for Exam Lecture 12 Lecture 12

Upload: georgia-blake

Post on 06-Jan-2018

232 views

Category:

Documents


1 download

DESCRIPTION

Lecture 1 Test cases for programs Documentation –Echo of input –Inline comments –Ending message –Javadocs

TRANSCRIPT

Page 1: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Reviewing for ExamReviewing for Exam

Lecture 12Lecture 12

Page 2: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 1 • Postfix.java

– Hexadecimal• Converting ‘a’ to number• Converting ‘1’ to number

– System.exit(3);• Questions?

Page 3: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 1• Test cases for programs

• Documentation – Echo of input– Inline comments– Ending message– Javadocs

Page 4: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 2• PseudoWar game

– Test cases– Stubs– Program

• Required– Constructors– Specific methods– Generation of number in range 1 to 52

Page 5: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 3• Exception

– Handlers• Try• Catch

– printStackTrace()– getMessage()– Multiple handlers

– Avoiding

Page 6: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 3• Style guidelines• Chapter12 slides

Page 7: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 4• Writing code from scratch

– Illustrating use of exception handlers – Illustrating avoidance of exceptions– Java Tutorial

– Java api

Page 8: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

• ArithmeticException• ArrayIndexOutOfBoundsException• FileNotFoundException• PatternSyntaxException• ClassNotFoundException• InputMisMatchException• NullPointerException• NumberFormatException• StringIndexOutOfBoundsException• NegativeArraySizeException• ArrayStoreException• MalformedURLException• IOException• IllegalArgumentException• ClassCastExceptionIllegal• FormatConversionException

Page 9: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 4• Common Exceptions

– That can be avoided– That can not be avoided

• Reading from Files• Compile time errors • Runtime errors

Page 10: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 5• File I/O

– PrintWriter (flush) – File– java.io package

• Use of command line arguments• Use of re-direct symbols

Page 11: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 5• Play with text examples

– Use of StringTokenizer– Use of delimiters– Use of regular expressions

• Correct use of Boolean in if and while statements

• How comments help

Page 12: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 6• Enumerated types

• Enhanced for loop (i.e. for… each)

Page 13: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 6• public enum Sessions

{ SPRING, SUMMER, FALL ; }

Page 14: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

public enum Planet { MERCURY (3.303e+23, 2.4397e6), VENUS (4.869e+24, 6.0518e6), EARTH (5.976e+24, 6.37814e6), MARS (6.421e+23, 3.3972e6), JUPITER (1.9e+27, 7.1492e7), SATURN (5.688e+26, 6.0268e7), URANUS (8.686e+25, 2.5559e7), NEPTUNE (1.024e+26, 2.4746e7);

… for (Planet p : Planet.values()) System.out.printf ("Your weight on %s is %f%n", p, p.surfaceWeight(mass));

Page 15: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 7• Enumerated types again

– Rank– Suit– Card– Deck (?)

• Order • Valid elements• Attributes

Page 16: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

for (Rank r : Rank.values()){ System.out.println ( r + " " + r.getBridgePoints() + " " + r.getAbbreviation() ); } // end for

Example for-each

Page 17: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 7• Chapter 9 – • Chapter_9_Part1.ppt slides• ClearJunk.java

Page 18: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 8• Classes

– toString methods– equals methods

• when needed• how used

– static fields

Page 19: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 8• A few things

• Chapter 9 – rest of slides

Page 20: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 9• UML diagram• Die objects

– getFaceValue– setFaceValue– toString– Roll– Math.random vs Random

Page 21: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 9• Talk about constructors

– belongs to class– do not have a visibility modifier– same name as class– may have no parameters (no-arg constructor)– may have one or more parameters (explicit

value constructor)– class may have no explicit constructor– class may have more than one constructor– doesn't return values

Page 22: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 10• Code re-use• Array of objects• Explicit value constructors• No-arg constructors• Reading carefully

Page 23: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 10• Professor Harris lecture – see

blackboard

Page 24: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 11• Designing classes• DISCUSSION

– Getters and setters are, in general, public methods. Since Fraction is immutable, shouldn’t have them.

– Fraction is 4/20 not .20– Numerator and denominator are ints

Page 25: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 11• Somewhat of a repetition of

lecture 10

Page 26: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 12• Inheritance

– Employee• SalariedWorker• HourlyWorker

Page 27: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lecture 12• Review

Page 28: Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?

Lab 13• Specialization and Inheritance• DISCUSSION

– Needed to look at javadocs – Can’t compare one ampm to another

using == because they are Strings – need .equals

– An AlarmClock is-a Clock (a Clock is NOT an AlarmClock).