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

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
1 Chapter 3 Arithmetic Expressions. 2 Chapter 3 Topics l Overview of Java Data Types l Numeric Data Types l Declarations for Numeric Expressions l Simple.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Some basic I/O.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
Expressions, Data Conversion, and Input
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Practice.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
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.
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.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
HARDWARE INPUT DEVICES GETTING DATA INTO THE COMPUTER.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Dialog Boxes.
ENUMERATED DATATYPES. USER DEFINED DATA TYPES  Data Type Defined By Programmer  Allows Use Of More Complex Data  Typically Defined Globally So Variables.
Java Variables, Types, and Math Getting Started Complete and Turn in Address/Poem.
2016 N5 Prelim Revision. HTML Absolute/Relative addressing in HTML.
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?
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
C OMMON M ISTAKES CSC Java Program Structure  String Methods.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Keyboard and Screen I/O (Input/Output). Screen Output  System.out is an object that is part of the Java language. (Don’t worry yet about why there is.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
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.
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
For Friday Read No quiz Program 6 due. Program 6 Any questions?
Chapter 1: Introduction to Computers and Programming.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Java for Beginners University Greenwich Computing At School DASCO
Chapter 2 Basic Computation
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
Java for Beginners University Greenwich Computing At School DASCO
Java for Beginners.
Computer Science 3 Hobart College
Computer Programming Methodology Input and While Loop
Java for Beginners University Greenwich Computing At School DASCO
Java for Beginners University Greenwich Computing At School DASCO
Java for Teachers Intermediate
Java for Beginners University Greenwich Computing At School DASCO
See requirements for practice program on next slide.
Java: Variables, Input and Arrays
Data Types and Maths Programming Guides.
Input, Variables, and Mathematical Expressions
COMPUTING.
Python Creating a calculator.
Chapter 1: Introduction to Computers and Programming
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

5 types of variables double boolean int char String

Combining values and variables int num1 = 5; int num2 = 10; System.out.println(num1+num2); System.out.println(num1+” + ”+num2); Output 15 5 + 10

Input From keyboard? From mouse? From microphone? From scanner? Links to 2.1.2 (Hardware)

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

Important notes: Input is best received as a String We use: String anything = kb.nextLine(); “Green cow” anything

Converting String to int To convert String to int, we use a function called Integer.parseInt( ); Example: String snumber = kb.nextLine(); int num = Integer.parseInt(snumber); “123” 123 snumber num

Output

Converting String to double To convert String to double, we use a function called Double.parseDouble( ); Example: String snumber = kb.nextLine(); double price = Double.parseDouble(snumber); “2.95” 2.95 snumber price

Output

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

Good practice Don’t do calculations and output in the same line: Work out the answer first THEN display the answer

What students struggle with int x = 1; int y = 3; x = 3; int total = x + y; Answer: 6 int h = 4; h++; Answer: 5 int k = 7; k = k + 2; Answer: 9

r a d i o More about Strings String device = “radio”; 1 2 3 4 1 2 3 4 To get a specific character from a String, we use the .charAt( ) function char letter = device.charAt(2); “radio” ‘d’ device letter

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();