Class 17 - Types and Expressions 1 Goals for Today n n Use...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Types and Expressions 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Goals for Today n Use variables and constants n Understand the difference between Java’s fundamental and class types 2 MGMT 29000-002
Background image of page 2
Types and Expressions n Alice and Java allow you to send messages to objects n Java uses the double type to represent real numbers n Some topics to cover ¨ Declaring variables and constants ¨ Constructing expressions ¨ Additional capabilities of printf() ¨ Methods libraries provided by Java 3 MGMT 29000-002
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introductory Example: Months from Month Numbers n Elements of the user story ¨ Prompt the user for a month number (1-12) ¨ Read the number from the keyboard ¨ Compute the corresponding month name ¨ Display the month abbreviation, with descriptive labels n Derive objects from noun phrases in the user story n Derive methods from verb phrases in the user story n Features of a String object useful to this program ¨ Each character in a String has a numerical index ¨ A single character or substring is accessed by index 4 MGMT 29000-002
Background image of page 4
Introductory Example: Months from Month Numbers (continued) n Create your algorithm and flowchart on separate pieces of paper 5 MGMT 29000-002
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introductory Example: Months from Month Numbers (continued) n Strategy for computing monthAbbrev from a number ¨ Build a String ( monthTable ) to store abbreviations ¨ Access the month abbreviation using String index n Method used: aString.substring(start,stop) ¨ start = (monthNumber - 1) * 3; stop = start + 3 ¨ Example: monthTable.substring(0,3) “Jan” n Every variable in a Java program has a type ¨ Primitive types: 8 types that store numbers; e.g., int ¨ Reference types: refer to objects; e.g., String 6 MGMT 29000-002
Background image of page 6
Introductory Example: Months from Month Numbers (continued) 7 MGMT 29000-002
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introductory Example: Months from Month Numbers (continued) 8 MGMT 29000-002
Background image of page 8
Introductory Example: Months from Month Numbers (continued) 9 MGMT 29000-002
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java’s Primitive Types n When a type is declared, memory is allocated
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/04/2012 for the course MGMT 290 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 29

Class 17 - Types and Expressions 1 Goals for Today n n Use...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online