Agenda Warmup Lesson 2.4 (String concatenation, primitive types, etc)

Slides:



Advertisements
Similar presentations
1 CSE 331 Enumerated types ( enum ) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Advertisements

Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
22-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Lecture 2: Topics Bits and Bytes Primitive Types Casting Strings Boolean expressions.
Lecture 8 Using casts, Strings and WordUtil. Agenda Generating random numbers Casts – Casting a double into an int – Casting an int into a char – Casting.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Creating and Using Class Methods. Definition Class Object.
Chapter 5 Defining Classes II Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Information and Computer Sciences University of Hawaii, Manoa
More About Objects and Methods
Agenda Warmup Lesson 1.4 (double precision, String methods, etc)
Chapter 2 Basic Computation
Introduction to Computer Science / Procedural – 67130
Agenda Warmup Finish 2.4 Assignments
Agenda Warmup AP Exam Review: Litvin A2
Selenium WebDriver Web Test Tool Training
Section 2 – CSE341 Patrick Larson, Spring 2013.
Computer Science 3 Hobart College
Type Conversion, Constants, and the String Object
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2 Basic Computation
An Introduction to Java – Part I
Methods and Parameters
INPUT STATEMENTS GC 201.
CMSC 202 Static Methods.
Introduction to Programming in Java
Object Oriented Programming (OOP) LAB # 8
Section 2 – CSE341 Konstantin Weitz.
Nicholas Shahan Spring 2016
Wrapper Classes The java.lang package contains wrapper classes that correspond to each primitive type: Primitive Type Wrapper Class byte Byte short Short.
IFS410 Advanced Analysis and Design
CSE 341 Section 2 Winter 2018 Adapted from slides by Nick Mooney, Nicholas Shahan, Patrick Larson, and Dan Grossman.
CSE 341 PL Section 2 Justin Harjanto.
Unit 3 Test: Friday.
More About Objects and Methods
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Spencer Pearson Spring 2017
CSE 341 Section 2 Nick Mooney Spring 2017
Programs and Classes A program is made up from classes
CS 200 Primitives and Expressions
Conditional Logic Presentation Name Course Name
Implementing a simple class
Agenda Warmup Lesson 2.6 (Constructors, Encapsulation)
Introduction to Primitives
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Introduction to Primitives
Agenda Warmup Lesson 1.6 (Do-while loops, sentinels, etc)
Agenda Warmup Lesson 1.4 (double precision, String methods, etc)
In this class, we will cover:
Java’s Central Casting
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Chapter 6.
Agenda Warmup Lesson 2.2 (parameters, etc)
Agenda Warmup Lesson 1.6 (Do-while loops, sentinels, etc)
Happy October Exam Review 10/01/2014.
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Agenda Warmup Lesson 2.8 (Overloading constructors, etc)
Variables and Constants
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Getting Started in Python
Presentation transcript:

Agenda Warmup Lesson 2.4 (String concatenation, primitive types, etc) Independent Practice (2.4 Assignments) Closure Activity Students will be able to: Understand what String concatenation is Understand what a primitive type is, and how it contrasts with an object of a class Understand how to return a value to the client See how today's lesson fits into the unit and the course as a whole

Warmup Is this a valid method? public int getNum(int x) { return 7; } 2) Declare a constant that is equal to the smallest possible int value. 3) What is the result of this code? int x = 0; for ( ; x<2; x+=1) System.out.print(x); 4) What are you most proud of in life?

Unit 2 Quiz: Tues 3/19

String concatenation is the process of joining two or more Strings together. Using the + sign, Strings can be joined together, or chars can be added onto a String. demo: StringConcat

Primitive types String variables are actually objects, which are created to instantiate (or “connect to”) the String class. Most variables do not connect to any class, so these variables are not objects. These types of variables are called primitive types. There are 8 primitive types: int, double, char, boolean, short, long, float, byte.

The String class has methods, such as length( ) The String class has methods, such as length( ). Notice that primitive types do not have methods. For example, there is no such thing as: int x = 0; System.out.print( x.length( ) );

Converting an int to a String If you want to convert an int into a String, it is slightly more complex than simple type casting. This code converts the int x into a String y: int x = 0; x = 23; String y = “ ”; y = Integer.toString(x); You might want to do this for today’s 1st assn.

Static Methods A static method is a method that can be called by using the name of the class itself. You do not need to create an object in order to call the method. We have been using static methods for a long time: Math.pow( ), Math.random( ), etc. This explains why you don’t have to instantiate (“connect to,” create an object of) the Math class in order to use it. Open: StaticMethodClass, StaticMethodClient

But what is the point of a static method? Why would you create one? Static methods are often called utility methods: they are meant to be used without objects, because they are never going to change from one object to another. Static methods do not use instance variables. Static methods often (but not always) receive parameters, perform some action on them, and return the result.

Assignments P. 244 # 6 (call the files Card and CardClient) When you create the Card class, it should have 2 methods -- one returns (doesn’t display) a card’s value (2, 3, 4, …. J, Q, K, A) and one returns (doesn’t display) a card’s suit (hearts, diamonds, spades, or clubs). Think about it – there is a way to write the Card class without using a ton of if statements (some are necessary, yes, but not a ton!) CODE EFFICIENTLY! When the instructions say “Create a program that deals 20 random cards,” you should create a client called CardClient. CardClient should call both methods, 20 times…each time you should display something like: “You have been dealt the King of Diamonds” “You have been dealt the 8 of Hearts” etc… More on next slide

P. 241-243: (*for these assignments, only use one class, then create one client to test the methods. Call them P241Class and P241Client): # 6–9, 11, 12, 20-22