Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITK 168 – More Variables 10/13/05. Another example of using instance variables and constants  Go through SimpleBot  Modify SimpleBot to “teleport”

Similar presentations


Presentation on theme: "ITK 168 – More Variables 10/13/05. Another example of using instance variables and constants  Go through SimpleBot  Modify SimpleBot to “teleport”"— Presentation transcript:

1 ITK 168 – More Variables 10/13/05

2 Another example of using instance variables and constants  Go through SimpleBot  Modify SimpleBot to “teleport”

3 Accessor Methods  get >()  Robot examples getStreet() getAvenue()  Do BasketballPlayer example

4 Using accessors to test  Creating a test harness main methods  Using Becker’s testing scheme  BasketballPlayer example

5 Primitive Types  Classes Robot, Thing, BasketballPlayer, String Often custom instantiated with new  Primitive types int, double, boolean, char, … Fixed Fundamental types native to the programming language

6 Integer types  byte1 byte -128 to 127 8 bit  short 2 bytes -32,768 to 32767 16 bit  int 4 bytes -2,147,483,648 to 2,147,483,647 32 bit  long 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 64 bit

7 Floating point types  float ±1.40238946E-45 to ± 3.40282347E+38 7 significant digits float f = 0.5f; 32 bit  double 4.94065645841246544E-308 to ± 1.79769313486231570E+308 16 significant digits double d = 56.5E22; 64 bit

8 Operators  6 + 6  12 – 10  600 * 2  10 / 5  10 / 8  10 / 3.0  6.6 + 6  10 % 8  + Add  – Subtract  * Multiply  / Divide  % Modulus

9 Converting between types  It’s called “casting” int i = 6; double d = i; double d = 55.89; int i = d; ?? int i = (int)d; int i = (int) d / 3.7;

10 Mathematical functions

11 Formatting NumberFormat currency = NumberFormat.getCurrancyInstance(); System.out.printf() for printing in columns see java.util.Formatter for use

12 boolean  true or false  boolean b = true;  boolean b =false;  No conversions

13 char  char ‘Я’ or any unicode character Escape sequences  \b backspace  \f next page  \n next line  \r carriage return  \t tab  \\ backslash  \’single quote  \” double quote  \u010E unicode character (®) char c = ‘a’ char registeredTrademark = ‘\u00AE’

14 String  Declaration and assignment String name = “bob”; String name = new String(“bob”);  Concatenation String fullName = name + “ “ + “Vila”;  BasketballPlayer example

15 String ELCOWME 156 Welcome 0123456 Index String welcome = “WELCOME”;

16 String Methods  welcome.length(); //returns 7  welcome.charAt(2); //returns ‘l’  welcome.toLowerCase(); //returns “welcome”  welcome.indexOf(“ME”); //returns 5  welcome.equals(“WELCOME”); //returns true DON’T use if(welcome == “welcome”)

17 toString  Robot bob = new Robot(…);  System.out.println(bob);  BasketballPlayer?

18 Some examples  toUpperCase()  indexOf()  substring  equals

19 Strings are immutable  They can’t be changed. You can only create a new one from an old one

20 Data Types and Literals  Boolean true or false  Primitive Integral – has no decimal point  byte  short  int 25484  long 18131891125484L  char ‘a’ Floating point – has a decimal point  float 12.5 (1.25E1)  double 2.87231651651561E200D  Reference Objects “Welcome to ITK 168” 25484 156 Welcome to MIS 222 156 684 Memory address memory

21 Primitive vs. Reference Assignment String welcome = “Welcome to ITK 168”; String bob = “Welcome to geekdom”; welcome = bob; bob = null; 156 “Welcome to ITK 168” 156 “Welcome to geekdom” 157 welcome 0 684 income 758 income = 254848; income = 5; 157 bob 758 157 null int income; 2548485

22 Interface  Defines how a class should look so it can do specific things.  Runnable public void run()  public class > implements >  Show the ComboLock interface


Download ppt "ITK 168 – More Variables 10/13/05. Another example of using instance variables and constants  Go through SimpleBot  Modify SimpleBot to “teleport”"

Similar presentations


Ads by Google