CS 241 – Computer Programming II Lab Kalpa Gunaratna –
Contact Contact by 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 Variable declarations : Method declarations ( : ) :
Java class and equivalent UML Class Example : Public Class MyClass { Private int x; Public String y; Private void setVal(int z) { x = z; } Public String getName() { return y; } MyClass - x : int + y : String + setVal(z : int) + getName() :String
Comments // - single line comment /* */ - multiple line comments /** */ - javadoc comments Example JavaDoc commnet /** 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 y input integer returns calculated value */ Public int calcValue(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 : tml tml