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

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Neal Stublen C# Data Types Built-in Types  Integer Types byte, sbyte, short, ushort, int, uint, long, ulong  Floating Point Types.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Datalogi A 3: 26/9. Java Concepts chapter 4 Fundamental Data Types int (long and short) double (and float) boolean char String.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types CSE 115 Spring 2006 April 3 &
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Fundamental data types Horstmann Chapter 4. Constants Variables change, constants don't final = ; final double PI = ; … areaOfCircle = radius *
String Escape Sequences
Chapter 2: Introducing Data Types and Operators.  Know Java’s primitive types  Use literals  Initialize variables  Know the scope rules of variables.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
BPJ444: Business Programming using Java Java basics Tim McKenna
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
Chapter 2: Using Data.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
CHAPTER 4 GC 101 Data types. DATA TYPES  For all data, assign a name (identifier) and a data type  Data type tells compiler:  How much memory to allocate.
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
C# - variablesBjørk Busch1 Variables Basic types (also defined as classes with methods) : Integer-types Int, long, byte, sbyte, short, ushort, uint, ulong.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
1.2 Primitive Data Types and Variables
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Basic Introduction to C#
Chapter 2 Variables.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Escape Sequences What if we wanted to print the quote character?
Computers & Programming Languages
Escape Sequences Some Java escape sequences: See Roses.java (page 68)
An overview of Java, Data types and variables
Objects and Primitive Data
Chapter 2 Variables.
Unit 3: Variables in Java
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 2 Variables.
Presentation transcript:

ITK 168 – More Variables 10/13/05

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

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

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

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

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

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

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

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;

Mathematical functions

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

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

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’

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

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

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”)

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

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

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

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

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 income 758 income = ; income = 5; 157 bob null int income;

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