80 likes | 202 Views
CS 241 – Computer Programming II Lab . Kalpa Gunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/. Contact . Contact by e-mail kalpa@knoesis.org Office hours 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm. UML class diagram tips…. Basic class structure .
E N D
CS 241 – Computer Programming IILab KalpaGunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/
Contact • Contact by e-mail • kalpa@knoesis.org • Office hours • 376 Joshi • Mondays & Wednesday 3:00 pm – 4:00 pm
UML class diagram tips…. • Basic class structure. • Access modifiers • + public, - private, # protected Class name <name> Variable declarations <access modifier>< <name> : <type> Method declarations <access modifier><name> (<name> : <type>) : <type>
Java class and equivalent UML Class • Example : MyClass Public Class MyClass { Private int x; Public String y; Private void setVal(int z) { x = z; } Public String getName() { return y; } } - x : int + y : String + setVal(z : int) + getName() :String
Comments • // - single line comment • /* */ - multiple line comments • /** */ - javadoc comments • Example JavaDoccommnet /** Takes input value y and calculates fixed amount and returns the calculated value. Pre-condition: value should be an integer of the range 1 – 9 Post-condition: value is equal to the expected amount @param y input integer value @return returns calculated value */ Public intcalcValue(int y) { return 5; }
In lab • Draw UML class diagram and explain during the lab. • Put your method signature only into java class and should compile without any error. • All methods should have JavaDoc comment and inline comments or comment blocks. • UML and class should have all the methods listed in the assignment page.
Post lab • Implement your stubbed java class. • Must have javadocs and comments as in in lab. • Call your methods and test whether they are working as mentioned in javadocs.
enum • You can type enum with whatever name you want to use, lets say you need days of week to be represent in constants, enum Days{MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY}; • When you want to access MONDAY, use Days.MONDAY • See example in assignment. • More information and how to use enum: http://download.oracle.com/javase/tutorial/java/javaOO/enum.html