welcome to iit and cs115!. cs 115 - sec. jon hanrath - 214 sb office hours: –tbd. [email protected]...

56
Welcome to IIT and cs115!

Upload: jasper-pitts

Post on 27-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Welcome to IIT and cs115!

Page 2: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

CS 115 - Sec.

• Jon Hanrath - 214 SB

• Office Hours: – TBD.

[email protected]

• www.cs.iit.edu/~cs115hanrath

Page 3: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Lecture: TBD

• Lab: TBD

Lab assignments are due by the end of class in lab each week

Page 4: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

CS Intro Courses

• CS 105: 1-Semester Requiring Little or No Previous Programming Experience, Programming in C++

• CS 115-116: 2-Semester Sequence Assuming Previous Programming Experience, Programming in JAVA, Primarily CS Majors

• CS 201: 1-Semester Sequence Equivalent of CS105-CS106, Requires Previous Programming Experience, Programming in JAVA

Page 5: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

CS 115 – Required Textbook and Lab Manual

• “Java 6 Illuminated: An Active Learning Approach” Anderson and Franceschi

• Second (Orange) OR Third (Purple) Edition

Page 6: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

CS 115 - Quizzes/Exams & Grading• 2 Quizzes – Each 5% of Grade• 2 Exams:

– Exam I - Lecture Exam - 10%– Exam II – Lecture - 20%

• Final Exam - 30%• Labs - 20%• Project - 10%• Must Take Final to Pass Course• Final Grade:

– A > 90%– B 80-89.99%– C 70 –79.99%– D 60 – 69.99%– E < 60%

Page 7: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

CS115 Labs• Labs Assigned in Handout; on Website• Lab Exercises Comprised of Exercises and Programming

Exercises (Located at End of Each Chapter in Textbook)• Student Expected to Complete Labs *BEFORE* Lab

Section Meets• Labs Graded Either 10 (fully completed), 5 (partially

completed), or 0 (not completed)• TA Will Cover Labs/Questions/Other Topics in Lab Session• Save .java File(s) to flash drive, or send to yourself in email

and Bring to Lab Section for Discussion and Questions• Hand in assignments by end of lab to TA

Page 8: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Expectations

• Attendance in Lectures and Labs

• Completion of Quizzes and Exams

• Four to Six Hours per Week on Homework

• Outside Help If Necessary

• No Cheating

• Have fun!!

Page 9: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Rules

• No Swearing or Other Inconsiderate Behavior

• Turn Off Cell Phones, iPads, Laptops

• Questions, Discussion, Ideas Welcome

Page 10: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Excuses

• If You Will Miss an Exam or Quiz, Make Arrangements **BEFORE** the Exam or Quiz Date

• Exam, Quiz Dates Already Posted

• If Emergency:– Doctor/Hospital Note– Family Problem: Contact Info for Parents

Page 11: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Unacceptable Excuses

• Slept Late• Felt Sick• I’m Just a Freshman• Roommate Ate My Alarm

Clock/Textbook/Underwear• Missed Bus• Had a Game/Match/Practice• Didn’t Know When Exam/Quiz Was• If Any of Above Happen, Get to Class As SOON as

Possible!!!

Page 12: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

CS 115 - Ethics

• Exams:– Closed Book, Closed Notes, Closed Everything– Nothing in Ears (mp3 players, cell phones,

etc.)

• Labs Should Be Done Independently

Page 13: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

CS 115 – Where to Get Help

• www.cs.iit.edu/~cs115hanrath

• Internet: Search for “JAVA tutorial”, or “JAVA help”

• GET HELP EARLY RATHER THAN LATER!!!

Page 14: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

CS 115 – Web Page

• http://www.cs.iit.edu/~cs115hanrath

• Click on Syllabus– Weekly Assignments– Quiz and Exam Dates– Lecture Slides– Other Course Information

Page 15: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Course Philosophy

• Computer Science Side– Problem Solving– Logical Thought– Programming in JAVA

• “Real World” Side– Human Nature– Corporate World– Surviving during and after College

Page 16: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Problem Solving

• CS 115 Develops Logic Skills to Solve Problems by Writing a Program

• A Program is a Problem Solving Tool

• Computers Follow Instructions Given to Them

• Computers Do Not Have “Intuition”

• Computers Do Not Make Decisions “on Their Own”

Page 17: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Problem Solving

• Arrange a Deck of Cards by Suit and Rank

• How Would You Do This?

• How Would You Tell a Child to Do This?

• How Would You Tell a Computer to Do This?

Page 18: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Why Use a Program?

• Computers Perform Tasks Many Times Faster than a Person

• Computers Are More Consistent than a Person

• Computers Can Work 24-7

Page 19: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Terminology• Source Code: the Original Problem-Solving, Logical

Solution Written in a Programming Language (e.g. JAVA, .java file)

• Interpretation: Converting source code into common language (.class file)

• Compiling: the Action of Turning the Source Code into a Format the Computer Can Use

• Linking: the Action of Bringing in Already Written Code (Libraries) for Use in a New Program

• Executable: the Result of Compiling and Linking a Source Program; the “.exe” file that the Computer Can Run

Page 20: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

JAVA Required Elements

• Every JAVA Program Must Have:public class MyProgram

{ public static void main( String [ ] args)

{

}

}

Page 21: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Your First Program// Jon Hanrath

// CS115

// Section 042public class MyProgram

{ public static void main( String [ ] args)

{ System.out.println(“Hello World!!”); System.exit(0);

}

}

// End lect01

Page 22: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

If You Missed Monday

• Go to Course Website:– http://www.cs.iit.edu/~cs115hanrath– Click on Syllabus, Click on Lecture Notes

• Email TA to Complete Lab 0

Page 23: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Customer/Client/Organization Produces Specification (i.e., problem to be solved)

• Design Team Creates Solution Code– Pseudocode (“Fake Code”)

– Design takes ~75% of Total Program/Solution Time

• Design Team hands Solution to Programmers (Coders) • Programmers hand Program to Testers

Real Life Programs

Page 24: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Every Programmer’s Way of Writing Down Steps in Solving a Problem

• Steps in Creating Pseudocode:– Understand the Problem– Decide How to Solve the Problem– Write the Solution Using a Logical Sequence of

Statements

• Design Issues Apply to almost ANY Vocation

What Is Pseudocode?

Page 25: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Compiler

• Converts Source Code into an Object File or Machine Code

• Each Change to Source File Requires a Recompilation

• Compiler Detects Syntax Errors• Syntax Error: a Non-Proper, Not

Allowable, Sequence of Characters or Words Given a Particular Language

Page 26: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Syntax Errors

• Spelling Errors Examples:– Undefined Variable Name– Unrecognized Keyword

• Punctuation Errors Examples:– Missing Curly Braces– Missing Semicolons– Malformed Comments

• Syntax Errors Are Listed at Bottom of Screen When Compilation Is Complete

Page 27: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Syntax Errors (Cont)

• Syntax Errors Are Listed at Bottom of Screen When Compilation Is Completed

• First Error in Program May “Cause” Other Errors to Show Up

• General Rule: Fix First Error (and Any Obvious Errors); Then Recompile

Page 28: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Logic Errors – “Bugs”

• Also Called Semantic or Run-Time Errors• Program Compiles, but Doesn’t Produce the Expected

Results• Examples:

– Program Keeps Running Forever (Infinite Loop)– Nothing Happens– Program Output Is Incorrect– Error Message at Run Time (e.g. Dividing by 0)– Errors May Be Intermittent

• May Be Able to Find Semantic Problems with Debugger

Page 29: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Detecting “Bugs”

• Running Program Should Be Tested Several Times with Different Inputs

• Test Plan – Series of tests (e.g., inputs) that have predetermined expected outputs.

• Running Program Should Be Tested Several Times under All Potential Conditions

• When Errors Detected: Analysis Needed: Debugging Mechanism

Page 30: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Test Plan

• What should the Test Plan contain for a program that accepts numerical input from a user, and outputs the square of the input?

Page 31: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

JAVA Packages/Libraries

• Over 2000 Libraries Exist

• Sometimes Called “Packages”

• Java.lang Package Automatically Imported

• Import Statements Above First Class

• Import Others with import statement

import java.util.* //import all classes

Page 32: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Comments• Comments: Describe a Program• // Comment to end of line• /* Comment until first occurrence of star slash */

• Difficult to Understate Importance of Good Comments• Should Be at Beginning of Program (Overall Summary)• Should Be Next to Variable Declaration Briefly

Describing Uses of Variable• Should Be Anywhere in Program Where Unobvious

Coding Is Performed

Page 33: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Program Format

• White Space:– Not Recognized by Compiler– Indent (e.g. 3 Spaces) for Each New Function,

Selection, or Loop

Page 34: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Identifiers Used to Store Values that May Change• Every Variable Has a Type : What Kind of Value

(e.g., Integer, Floating Point Number, Character) Is Begin Stored

• Every Variable Has a Value which Is Assigned and Can Be Changed

• Every Variable Must Be Declared, which Sets Aside Memory for the Storage Location

Variables

Page 35: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Declaration Normally Comes after a Function Definition Opening Curly Brace:

• public class MyProgram{ public static void main( String [ ] args) {

int num1; //variable declaration num1 = 10; // variable assignment // variable output below System.out.println(“num1 is:” + num1); }

}

• Declaration Includes Type and the Name of the Variable• All Variables Must Be Declared before Being Used

Declaring a Variable

Page 36: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Variables and Main Memory

int num;

num = 10;

num = 15;

<garbage>

num

10

num

Main Memory

15

num

Page 37: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Storage Location of Data in a Computer• Used When a Program Is Running• “Wiped Clean” When Computer Rebooted• Bit: A “1 or 0” representing “on or off” • Byte: Basic Unit of Storage (Can Store One Letter of the

Alphabet or Keyboard) (8 bits – 256 combinations)• Kilobyte (KB): 1000 (or 1024) Bytes (Pages of Text)• Megabyte (MB): 1,000,000 Bytes (Large Pictures)• Gigabyte (GB): 1,000,000,000 Bytes (Music Files, Video Files)

Main Memory

Page 38: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Initialization: Value Given to Variable at Declaration

• Assignment: Value Given to Variable in Execution Statement

Initialization and Assignment

Page 39: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

public class MyProgram

{

public static void main( String [ ] args)

{

int num1 = 10; //variable initialization

System.out.println(“num1 is:” + num1);

}

}

Variable Initialization

Page 40: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Announcements

• Quiz 1 Next Monday

Page 41: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• int: Integer Range of Typically –2,147,483,648 to 2,147,483,647 (machine and compiler dependent)

• float: Real Number (i.e., integer part, decimal part, and exponent part) Range of Typically (+/-) 10e-45 to 10e38

• double: Larger Real Number ((+/-) 10e-324 to 10e308)

• char: Character

Built-In (or Primitive) Data Types for Variables

Page 42: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Can Use Letters: Remember That JAVA is Case Sensitive (e.g., NumWidgets Is Not the Same as numwidgets)

• Can Use Digits 0-9, $, and Underscore

• Cannot Start with a Digit

• Cannot Contain Spaces or Other Characters

• Cannot Use JAVA Keywords

Naming Variables in JAVA: Identifiers

Page 43: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Should Use a Meaningful, Descriptive Name so that Variable’s Use Is Easily Understood:

• Examples:counter, second, minute, length, width

• Be Consistent with Case; Usually Lower Case with Upper Case for Second Part of Variable Name

• Examples:averageRainfall, totalStudentGrades, maxBuildingHeight, minPackageWeight;

Naming Variables (Cont)

Page 44: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Constant: An Identifier that Is Initialized to a Value that Cannot Change

• Usually Declared at Top of Program using Keyword final

• Standard Naming of Constants Is to Use All Upper Case Letter with or without Underscore between Words

• All Constants Should Be Initialized• Syntax: final int MAXHT = 100;

Named Constants

Page 45: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Easier to Understand• Easier to Modify• Example: Compare using Number 100 in

Program versus Constant MAXHT

Advantages of Constants

Page 46: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

public class MyProgram{ public static void main( String [ ] args) {

final int MAXHT = 100; ... currentHeight > MAXHT ... bridgeHeight == MAXHT ... bridgeHeight + newAddition >= MAXHT

... // used MAXHT 223 times in this program } }

Named Constants

Page 47: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Constants Whose values Are Already Known:Characters (Specified Inside Single Quotes):

‘A’ , ‘a’ , ’5’ , ’ ‘ , ’\n’ (newline) , ’\0’ (NULL Character)

Integers:10, 1345, -34

Float or Double:2.3, -45.18, 10.6e6

String (Specified Inside Double Quotes):“HELLO” , “What a great deal.” , “5”

Literal Constants (Values)

Page 48: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Also Known as I/O • Output : System.out.println(“Hello World!!”);

• Input (Scanner): import java.util.Scanner;Scanner scan = new Scanner(System.in);scan.nextInt(); scan.nextFloat();scan.nextDouble();scan.next(); //String to whitespacescan.nextLine(); // String to end of line• All Wait until User Inputs Particular Type

Input and Output

Page 49: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

import java.util.Scanner;public class MyProgram{

public static void main( String [ ] args){

Scanner scan = new Scanner(System.in); int numEntered; System.out.print(“Enter an integer:”); /// The following waits until user hits Enter numEntered = scan.nextInt();System.out.println(“You entered: “ + numEntered); }}

Input and Output Example

Page 50: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Strings in java.lang package

• Java.lang imported automatically

Characters and Strings

Page 51: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

• Declaration:String yourName;

• Assigning a Value to a String: yourName = “A. Goose”;

• String Constants (Values) Must Be Enclosed in Double Quotes

JAVA Strings

Page 52: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

import java.util.Scanner;public class MyProgram{

public static void main( String [ ] args){

Scanner scan = new Scanner(System.in); String lastname; System.out.print(“Enter last name:”); lastname = scan.next();System.out.println(“You entered: “ + lastname); }}

Input String Example

Page 53: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Expressions• Expression: A Sequence of One or More

Identifiers and Operators that Evaluates to a Value• Operator: A Symbol Expressing a Way to

Modify a Value or Values (e.g., + for Addition)• Operand: A Value Being Modified by an

Operator• Example Expressions:

5

currentHeight

currentHeight + 10

Page 54: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Arithmetic Expressions

• Standard Arithmetic Operations Can Be Performed: Addition, Subtraction, Multiplication, Division

• Standard Arithmetic Operators Can Be Used for These Operations: +, -, *, /

• Others: % - “Modulo (Mod)” – Remainder after Integer Division -- Decrement (Subtract 1)++ Increment (Add 1)

Page 55: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Order of Operations

• Precedence: Level of Importance of OperationsMultiplicative Operators Have Higher Precedence than

Additive Operators:*, /, % Higher+, - Lower

• Associativity: Order of Operation for Equal Level PrecedenceMost Operators Have Left-to-Right AssociativityUse Parentheses to Force Differing Precedence of

Operations

Page 56: Welcome to IIT and cs115!. CS 115 - Sec. Jon Hanrath - 214 SB Office Hours: –TBD. hanrath@iit.edu cs115hanrath

Know for the Quiz

• All Terms (Underlined Items)• Variable Declaration, Initialization, and

Assignment• Constant Declaration• Expressions• Operators• Input (Scanner) and Output (System.out)• Everything in Homework through Lab 2