Java for Beginners University Greenwich Computing At School DASCO

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

Chapter 4 Computation Bjarne Stroustrup
Computer Science 209 Software Development Equality and Comparisons.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Java Programming Strings Chapter 7.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Constants A constant is a variable whose value is expected to remain the same throughout a program It is considered “good programming style” to use constants.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Introduction to Computer Programming Decisions If/Else Booleans.
Some basic I/O.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Week #2 Java Programming. Enable Line Numbering in Eclipse Open Eclipse, then go to: Window -> Preferences -> General -> Editors -> Text Editors -> Check.
Java for Beginners University Greenwich Computing At School DASCO
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
Chapter 4 Selection Structures: Making Decisions.
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
From C++ to Java A whirlwind tour of Java for C++ programmers.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
Chapter 05 (Part III) Control Statements: Part II.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
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.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
JAVA 1.COMPARISON: JAVA AND C++ 2.KEYBOARD INPUT 3.OUTPUT 4.CONVERSION FROM STRING 5.OPERATORS AND EXPRESSIONS 6.DIALOG BOX – USER PROMPT January
(Dreaded) Quiz 2 Next Monday.
Java String Methods - Codehs
7 - Programming 7J, K, L, M, N, O – Handling Data.
Python Basics.
Key Words / Reserved Words
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Agenda Warmup Lesson 1.4 (double precision, String methods, etc)
Java for Beginners University Greenwich Computing At School DASCO
Java for Beginners Level 6 University Greenwich Computing At School
Java for Beginners University Greenwich Computing At School DASCO
Building Java Programs
Java for Beginners University Greenwich Computing At School DASCO
Java for Beginners.
The Selection Structure
Computer Science 3 Hobart College
SELECTION STATEMENTS (1)
Primitive Types Vs. Reference Types, Strings, Enumerations
Trainings 11/4 Intro to Java.
Building Java Programs
I Know What I Want to Do – Now What??
Java for Beginners University Greenwich Computing At School DASCO
Multiple Choice -answer the easiest question 1st
Java for Beginners University Greenwich Computing At School DASCO
Java for Teachers Intermediate
Building Java Programs
IFS410 Advanced Analysis and Design
Topic 1: Problem Solving
Java for Beginners University Greenwich Computing At School DASCO
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Chapter 3: Selection Structures: Making Decisions
Java: Variables, Input and Arrays
COMPUTING.
Pre-AP® Computer Science Quiz
Presentation transcript:

Java for Beginners University Greenwich Computing At School DASCO Chris Coetzee

What do you learn last time? Wordle.org

Levels of Java coding 1: Syntax, laws, variables, output 2: Input, calculations, String manipulation 3: Selection (IF-ELSE) 4: Iteration/Loops (FOR/WHILE) 5: Complex algorithms 6: Arrays 7: File management 8: Methods 9: Objects and classes 10: Graphical user interface elements

Four and ½ steps to keyboard input Import java.util.* BEFORE main() Declare a Scanner Declare a String variable to catch input Use the Scanner to assign input from keyboard to variable Convert to int/char/double (if necessary) import Scanner (String) variable readLine()

Keyboard input

Calculations in Java Operator Function Example Result + Add int i = 10 + 2; 12 - Subtract int j = i – 3; 9 / Divide double k = j / 3; 3.00 * Multiply int product = i * j; 108 ++ Add 1 i++; 13 -- Subtract 1 j--; 8 % Modulus int m = 12 % 5; 2

String methods There are many functions we can use to manipulate Strings. They are called the ‘String methods’ Method Function Example .charAt(x) returns the char from a specified index String colour = “blue”; char letter = colour.charAt(0); .toUpperCase() returns the String in UPPER CASE String name = “bob”; bob = bob.toUpperCase(); .toLowerCase() returns the String in lower case String pet = “DOG”; pet = pet.toLowerCase(); .subString(x,y) returns String portion between two indexes String s = “I love hats”; String snip = s.substring(2,6); .length() returns how many characters there are in a String String h = “radar”; int size = h.length();

IF (condition) Used to change the flow of an algorithm, dependent on a condition.

Condition is a logic check something OPERATOR something Example: if(condition) Condition is a logic check something OPERATOR something Example: if(num == 3)

Logic operators in Java Function Example = = equals (int, double, char, boolean) if(num==3) .equals() equals (String) if(name.equals(“Chris”) ) > greater than if(num>20) < less than if(num<15) >= greater than or equal to if(age>=18) <= less than or equal to if(age<=12) != not equal to if(married!=true) Warning! = does not mean ==

IF example (int comparison)

IF example (String comparison)

What students struggle with = and == .equals(“xx”) for Strings Putting a ; at the end of if( xx) if(num > 3);  if(num > 3) 

IF/ELSE (2 outcomes)

IF/ELSE (int example)

Only IF gets a condition Note conditions if (condition) { something } else something else if (condition) { something } else if (condition) something else else third option Only IF gets a condition ELSE does not

AND/OR AND in Java: && OR in Java: || Used between conditions if(num>3&&<12)  if(num>3)&&(num<12)

IF/ELSE (int example with AND)

Switch/Case (IF alternative)