Intro Programming By Trevor Decker Team 1743 By Trevor Decker Team 1743.

Slides:



Advertisements
Similar presentations
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Advertisements

Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
Loops – While, Do, For Repetition Statements Introduction to Arrays
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
CS 106 Introduction to Computer Science I 03 / 30 / 2007 Instructor: Michael Eckmann.
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Copyright © Texas Education Agency, Computer Programming For Loops.
Introduction to Java. Main() Main method is where the program execution begins. There is only one main Displaying the results: System.out.println (“Hi.
COMP More About Classes Yi Hong May 22, 2015.
Python quick start guide
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Hello AP Computer Science!. What are some of the things that you have used computers for?
Introduction to Computing Concepts Note Set 11. Other ways of interacting with Java programs There are: ▫ GUI programs ▫ Web-based applets (GUI programs.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Repetition & Loops. One of the BIG advantages of a computer: ­It can perform tasks over and over again, without getting bored or making mistakes (assuming.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
Methods We write methods in our programs for many reasons:
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
Classes and Methods. Classes Class Definition Data Fields –Variables to store data items –Differentiate multiple objects of a class –They are called.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
The Basics Input / Output, and Primitive Data Types.
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
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.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Information and Computer Sciences University of Hawaii, Manoa
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Using variables, for..loop and functions to help organize your code
Basketball Drill Programming Alternatives
An Introduction to Java – Part I, language basics
Variables ICS2O.
Sridhar Narayan Java Basics Sridhar Narayan
Module 4 Loops.
Recap Week 2 and 3.
COM-152: Computer Programming Types, Variables, Operators Part 1 of 2
Chapter 2 Programming Basics.
February , 2009 CSE 113 B.
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
Peer Instruction 4 Control Loops.
Unit 3: Variables in Java
Methods/Functions.
Presentation transcript:

Intro Programming By Trevor Decker Team 1743 By Trevor Decker Team 1743

What you must do At the end of every piece of code type a “;” – This signifies that the line of code is over All pieces of code that do something need to be in a function – You can declare variables outside a function but if you want to change a value you need it inside a function At the end of every piece of code type a “;” – This signifies that the line of code is over All pieces of code that do something need to be in a function – You can declare variables outside a function but if you want to change a value you need it inside a function

Functions Functions are pieces of code which return a value – You can call a function from another function What function returns is denoted by the code return (what you want to return); – The return has to be of a certain type Functions are pieces of code which return a value – You can call a function from another function What function returns is denoted by the code return (what you want to return); – The return has to be of a certain type

Function’s continued Form of a function Public (what to return) (function name)(variables that are being passed to the function to use){ //the code for the function goes here Return (a variable or value of the same type as above, is not needed if above is text “void”); } Form of a function Public (what to return) (function name)(variables that are being passed to the function to use){ //the code for the function goes here Return (a variable or value of the same type as above, is not needed if above is text “void”); }

Functions continued Ex function Public void write(string text){ System.out.println(text); } Ex function Public void write(string text){ System.out.println(text); }

Public, private, ? Public – is not as secure, any class can read it’s input output Private – is more secure, only this class can read its input Public – is not as secure, any class can read it’s input output Private – is more secure, only this class can read its input

classes Each class has a separate document Class can reference each other or themselves – When a class references itself, it is recursive Classes are initiated using the code – Class name = new class(); – Cat Steve = new cat(); Each class has a separate document Class can reference each other or themselves – When a class references itself, it is recursive Classes are initiated using the code – Class name = new class(); – Cat Steve = new cat();

Variables Variables are created by using a reserved word then the name of the variable then a ; Reserved words for variables are words that you can not use as the name of something since it means you are declaring something – Int declares an integer, a whole number - 2,147,483,648 and +2,147,483,647 – String declares a String of text – Double is a number with a decimal it takes up more memory then an int Variables are created by using a reserved word then the name of the variable then a ; Reserved words for variables are words that you can not use as the name of something since it means you are declaring something – Int declares an integer, a whole number - 2,147,483,648 and +2,147,483,647 – String declares a String of text – Double is a number with a decimal it takes up more memory then an int

Variables continued The value of variable can be set at any time inside a class The value of a variable can change inside a function If the variable is declared inside a function it can only be seen in that function If a variable is declared inside a class it can only be seen in that instance of that class – Functions inside the class can reference and change values of the variable The value of variable can be set at any time inside a class The value of a variable can change inside a function If the variable is declared inside a function it can only be seen in that function If a variable is declared inside a class it can only be seen in that instance of that class – Functions inside the class can reference and change values of the variable

Advanced variables Instances of classes are referenced by creating a variable Cat bob; or Cat bob= new cat(); Instances of classes are referenced by creating a variable Cat bob; or Cat bob= new cat();

Examples with variables Int a = 5; int b; b = a+1; b = a-1 String c; String c = integer.parseint(a); Int a = 5; int b; b = a+1; b = a-1 String c; String c = integer.parseint(a);

Comments There are two types of comments – Single line which is done by typing // before the text which you want the compiler to ignore Ex // this code is important Ex a= 1; //this code makes a = 1 – Paragraph comments are opened with /* and closed with */ every thing in between is ignored by the compiler. – Ex /* this is some text*/ – Ex /* this is some more text it is very long and take up 2 lines */ There are two types of comments – Single line which is done by typing // before the text which you want the compiler to ignore Ex // this code is important Ex a= 1; //this code makes a = 1 – Paragraph comments are opened with /* and closed with */ every thing in between is ignored by the compiler. – Ex /* this is some text*/ – Ex /* this is some more text it is very long and take up 2 lines */

Arrays = matrix Type [] name = new Type[]; Can be any number of dimensions String[][] anArray= new String[3][3]; Can call value by anArray[2][0]; Type [] name = new Type[]; Can be any number of dimensions String[][] anArray= new String[3][3]; Can call value by anArray[2][0];

If Test for a condition – If it is true a block of code is executed, if it is not true the code is not executed. Else – Goes after an if block and is executed if the if is false Else if – A combination of else and if, if is only tested if the above is false, can be followed by another else if or else Contends are tested with == for = and != for not = You can test multiple things by using || for or, && for and Test for a condition – If it is true a block of code is executed, if it is not true the code is not executed. Else – Goes after an if block and is executed if the if is false Else if – A combination of else and if, if is only tested if the above is false, can be followed by another else if or else Contends are tested with == for = and != for not = You can test multiple things by using || for or, && for and

Ex code: if(a == 1){ // Do something if a = 1; }else if(a == 2||a==3){ // Do something if a = 2 or a = 3; }else{ && /*Do something if a does not = 1,2 or 3; */ } if(a == 1){ // Do something if a = 1; }else if(a == 2||a==3){ // Do something if a = 2 or a = 3; }else{ && /*Do something if a does not = 1,2 or 3; */ }

Loops While- while(a<10){.... – Executes code while a value is true, no variable creation or variable changes Do while –do{.... } while(a<10); – Executes at least once, if the while statement is true then the code will execute again, else will not execute anymore For – for(int a=0;a<10;a++){.... – Quick and dirty, creates a variable and keeps running until second part is not true, last part tells program what to do at end of each loop’s run through While- while(a<10){.... – Executes code while a value is true, no variable creation or variable changes Do while –do{.... } while(a<10); – Executes at least once, if the while statement is true then the code will execute again, else will not execute anymore For – for(int a=0;a<10;a++){.... – Quick and dirty, creates a variable and keeps running until second part is not true, last part tells program what to do at end of each loop’s run through

java docs List of built in functions and classes pi/ pi/ List of built in functions and classes pi/ pi/

Example code continued hello world just like the picture type System.out.println(“hello world”); in the main function Press f11 to see your program run System.out.println(); is a function that is built into java, you passed the string “hello world” to it and the function displayed hello world in the print box just like the picture type System.out.println(“hello world”); in the main function Press f11 to see your program run System.out.println(); is a function that is built into java, you passed the string “hello world” to it and the function displayed hello world in the print box Print box

Example two- Math Homework – Write a program which can check to see if a* b = c – When you input a,b and c The next slide gives a possible solution – Write a program which can check to see if a* b = c – When you input a,b and c The next slide gives a possible solution

Math homework answer Int a = 1; Int b = 2; Int c = 3; If(a*b == c){ System.out.println(“a*b = c”); }else{ System.out.println(“a*b not = c”); } Int a = 1; Int b = 2; Int c = 3; If(a*b == c){ System.out.println(“a*b = c”); }else{ System.out.println(“a*b not = c”); }

Questions? ? ?

More examples – tick tack toe Create a tick tack toe board to look like: *|*|* Create a tick tack toe board to look like: *|*|*

tick tack toe continued //first line System.out.print(board[0][0]+”|”); System.out.print(board[0][1]+”|”); System.out.println(board[0][2]); //second line System.out.print(board[1][0]+”|”); System.out.print(board[1][1]+”|”); System.out.println(board[1][2]); //third line System.out.print(board[2][0]+”|”); System.out.print(board[2][1] +”|”); System.out.println(board[2][2]); //first line System.out.print(board[0][0]+”|”); System.out.print(board[0][1]+”|”); System.out.println(board[0][2]); //second line System.out.print(board[1][0]+”|”); System.out.print(board[1][1]+”|”); System.out.println(board[1][2]); //third line System.out.print(board[2][0]+”|”); System.out.print(board[2][1] +”|”); System.out.println(board[2][2]);