CS 2110 Lecture Notes - Lecture 3: Junit, Precondition

81 views5 pages
14 Jun 2017
Course
Professor

Document Summary

Lecture 3 - more objects and stuff: we"ve seen public classes, but there is so much more, we"ve seen two types of methods for classes. Functions: now we"re gonna talk bout constructors, let"s do an example: time class. In eclipse, we make a new java project. Go to the src folder, create new class. Before class header, we write a specification for the class. Then when we declare certain attributes of the class, we include their invariants as a comment next to them hr and min (fields) We do not want users to access these variables. Then we add stuff that we desire, like a tostring() method that gives us the object of time in a string of the form 03:21 . We write return hr + : + mn; But wait! hr and min are ints! Automatically casts themselves as strings: testing with junit. File > new > junit test case (use version 4)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents