60 likes | 150 Views
CSE115: Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall 645-4739 alphonce@buffalo.edu. Agenda. Announcements Cell phones / laptops off & away / Name signs out Last time floating point representations Today type conversions green UML class diagram tool demo.
E N D
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 645-4739 alphonce@buffalo.edu
Agenda • Announcements • Cell phones / laptops off & away / Name signs out • Last time • floating point representations • Today • type conversions • green UML class diagram tool demo
mixing types in expressions • Operators such as +, -, * and / are overloaded: the same name has many different values + overloaded as String concatenation too! “Good” + “ ” + “morning!” “Good morning!” • What happens in an expression which mixes values of different types? 5 + 2.5 = ???? 5 is coerced to its equivalent double value, 5.0: 5.0 + 2.5 = 7.5 • Type coercion happens only from “smaller” type to “larger” type (e.g. int double, not double int)
type casting • a type cast is a function which maps from a value in one type to a corresponding value in another type (i.e. it performs a type conversion) • form: (<type>) <value> • semantics: <value> mapped to <type> • example: (int) 2.1 maps to 2 • example: (int) 2.9 maps to 2
type coercion • a coercion is an implicit type conversion • example • 3.5 + 4 evaluates to 7.5: • 4 is coerced to 4.0, then double addition takes place
green UML demo • we did a short demo of the green UML tool • green • is a UML class diagram tool • does live round-tripping between code and diagram • is a plug-in to Eclipse • was developed by UB students (mostly undergrads) • e-mail me if you want to be part of green’s development team starting in the spring semester