BIT115: Introduction to Programming

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
BIT 115: Introduction To Programming1 Sit in front of a computer Log in –Username: 230class –password: –domain: student Bring up the course web.
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Tuesday, October 13 th I will double dog try to.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Lecture 7 Instructor: Craig Duckett “OUTPUT”. Lecture 7 Annoucements this ASSIGNMENT 2 is due this Thursday, October 22 nd, uploaded to StudentTracker.
Lecture 6 Instructor: Craig Duckett. Assignment 1, 2, and A1 Revision Assignment 1 I have finished correcting and have already returned the Assignment.
Chapter 2: Java Fundamentals
BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Lecture 4 – Scanner & Style. Console Output The console that starts a Java application is typically known as the standard output device. The standard.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Lecture 5 Instructor: Craig Duckett “Ooga-Chaka Ooga-Ooga”
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Java Fundamentals Part Topics –Simple java program –The print and println Methods –Java API –Variables and Literals –Primitive Data Types –Arithmetic.
Chapter 2 print / println String Literals Escape Characters Variables / data types.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
CSC 110 – Intro to Computing - Programming
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
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.
17-Mar-16 Characters and Strings. 2 Characters In Java, a char is a primitive type that can hold one single character A character can be: A letter or.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
BIT 115: Introduction To Programming L ECTURE 3 Instructor: Craig Duckett
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Lecture 4 – Scanner & Style
Development Environment
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Lecture 2a- Java Fundamentals
Topics Designing a Program Input, Processing, and Output
User-Written Functions
CSC201: Computer Programming
BIT115: Introduction to Programming
Loops BIS1523 – Lecture 10.
Console Output, Variables, Literals, and Introduction to Type
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
BIT 115: Introduction To Programming
Variables and Primative Types
Variables, Expressions, and IO
Intro to PHP & Variables
CS190/295 Programming in Python for Life Sciences: Lecture 1
BIT115: Introduction to Programming
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
String Input ICS 111: Introduction to Computer Science I
Functions BIS1523 – Lecture 17.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Number and String Operations
CISC101 Reminders All assignments are now posted.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
BIT 115: Introduction To Programming
CSE 142, Spring 2012 Building Java Programs Chapter 1
BIT116: Scripting Lecture 6 Part 1
Review of Previous Lesson
Unit 3: Variables in Java
Output Manipulation.
CSE 142, Winter 2014 Building Java Programs Chapter 1
CSC 1051 – Data Structures and Algorithms I
Chapter 1 c++ structure C++ Input / Output
Instructor: Alexander Stoytchev
Presentation transcript:

BIT115: Introduction to Programming Lecture 7 Instructor: Craig Duckett “OUTPUT”

ASSIGNMENT 2 is due LECTURE 9 uploaded to StudentTracker by midnight Lecture 7 Annoucements ASSIGNMENT 2 is due LECTURE 9 uploaded to StudentTracker by midnight Assignment 2!!!

Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) Section 1: Wednesday, October 11th Section 3: Thursday, October 12th Assignment 2 (LECTURE 9) Section 1: Wednesday, October 25th Section 3: Thursday, October 26th Assignment 1 Revision (LECTURE 11) Section 1: Monday, November 6th Section 3: Thursday, November 2nd Assignment 2 Revision (LECTURE 13) Section 1: Monday, November 13th Section 3: Thursday, November 9h Assignment 3 (LECTURE 15) Section 1: Monday, November 20th Section 3: Thursday, November 16th Assignment 3 Revision (LECTURE 18) Section 1: Wednesday, November 29th Section 3: Thursday, November 30th Assignment 4 (LECTURE 21) NO REVISION AVAILABLE! Section 1: Monday, December 11th Section 3: Tuesday, December 12th The Fickle Finger of Fate

REMINDER: ICE Solutions Are Available  "Possible" solutions to ICEs are now available for the previous lecture starting with Lecture 4 (located at the bottom of the Lecture "slider" areas). Solutions will be made available two (2) days after the current lecture.

How Much Outside Work/Time Per Week for a 5-Credit Class? The Short Answer: It depends on the class (math vs humanities vs science vs development, etc.) Rule of Thumb: Absolute Bare Minimum: 5 Hours Average: 10 Hours Technical/Developer Classes: 10-15 (occasionally) Upper-Level Classes: 15-20 Looking Ahead: Graduate School: 20+ This is College. The amount of time you spend on schoolwork also goes up with every class level you advance. If you are pursuing a degree, and if you have a job, and if you want to do well, then don't expect to have any free time except for the occasional Saturday or Sunday, and the between-quarter breaks (then make the most of them!)

Assignment 2 Part 3 Hints

Assignment 2 Part 3 - Hints If heard that some of you are still struggling with Assignment 2 Part 3 even though it is imminently due, so I thought I'd give you some 'hints".

Create a class that extends Robot and a constructor Create a class that extends Robot and a constructor. Remember if you do it all in one class (the same class that contains main, then the file name, the class name, and the constructor name all have to be the same. For example: public class A2_Part_3 extends Robot { public A2_Part_3(City theCity, int avenue, int street, Direction aDirection, int item) { super(theCity, avenue, street, aDirection, item); }

When you create a new instance of the robot down in main, then it too has to have this same name ( and not Robot). For example: A2_Part_3 rob = new A2_Part_3(wallville, 1, 2, Direction.EAST, 0);

Create a turnRight() and turnAround() method, which you will use with three other methods (which I'll talk about one at a time). Create a movetoWall() method which moves while the front is clear

Create a doEverything() method which will do the following: Initialize a counter to 0 Use the counter in a while loop four times Call movetoWall() Pick up a Thing Turn around Call moveToWall() Turn left Move Increment the counter by 1 //second part of doEverything continued on next slide

[doEverything continued] Next, use a while loop to count things in the backpack, and as long as the count is greater than zero, move and put a thing down. // third part of doEverything continued on next slide

[doEverything continued] Finally, call the returnToStart() method to go back to where the robot start [end of doEverything] The returnToStart() method will do the following: turn around Call moveToWall() Turn right

Head’s up! MID-TERM MID-TERM is LECTURE 10 Please be prompt, and bring a pencil … don’t worry, I’ll supply the paper

Mid-Term Mid-Term is scheduled for LECTURE 10 It will cover everything learned up through today, Lecture 7 It is scheduled for the entire session, so you will have enough more than enough time to work through each of the questions, however most students finish in about 90 minutes. When you are finished, you can hand it in and you are done for the day, so feel free to go home or the nearest pub for a celebratory pint ;-) It will be done entirely with pencil-and-paper (no .java files). Mid-Term Study Guide is available now on the main page of BIT115 website (located in the right-hand column) http://faculty.cascadia.edu/cduckett/bit115/index.html

Mid-Term, continued… Mid-Term is scheduled for LECTURE 10 The Mid-Term Exam will focus on three learning outcomes: • conceptualize the logical steps needed to accomplish a task, • apply structured programming techniques to accomplish a task, • test and debug a program Exam Topics: • Setting up a city with walls, things, robots • Using the robots built-in services • Extending a robot to include new services • Tracing code and pinpointing where it goes wrong • Explaining the compile/run process • Selecting when to use different programming structures like loops, decisions, and services • Writing syntax for loops, decisions, local variables, and parameters Again, the exam will be similar to the quiz format (i.e., pencil-paper, from memory, individual work).

And Now … The Quiz

Output

Output

Chapter 6.6.1: Output (Printing Text Messages To The Screen) Info we get from the user is input Either from the keyboard, mouse, or something else like a network connection or other type of cable We will be looking at input in the next Lecture Info we show to the user is output This can be a message, additional information, even a request that the user perform some kind of action These messages and information are typically “hard-coded” into the program itself, then pushed out to the screen, console, or monitor using specific print-to-the-screen mechanisms (services) that are a part of Java

Back in the Day…

Back in the Day…

Back in the Day…

Back in the Day…

Back in the Day…

The Console Window The console window that starts a Java application is typically known as the standard output device. The standard input device is typically the keyboard. Java sends information to the standard output device by using a Java class stored in the standard Java library. In jGRASP, this output is displayed as part of Compile Messages Java classes in the standard Java library are accessed using the Java Applications Programming Interface (API). The standard Java library is commonly referred to as the Java API.

“Hello World!”

String, print and println Methods

String String is the programming term for all characters that are printed to the console or screen (and the space between characters is also part of the string). In Java and other programming languages, string is represented by lines of text contained in between double quotation marks " " System.out.print("This is string"); System.out.println(" and so is this $#@*&!"); "This is a string!"

println and print Example: System.out.println("Programming is great fun!"); This line uses the System class from the standard Java library. The System class contains methods and objects that perform system level tasks. The out object, a member of the System class, contains the methods print and println.

Difference Between print and println System.out.print("Programming is great fun!"); System.out.println("Programming is great fun!"); See: print_and_println.java example

println (“Print, then drop down a line”) The print and println methods actually perform the task of sending characters to the output device. We’ll look at println first… The line: System.out.println("Programming is great fun!"); is pronounced: System dot out dot printline The value inside the parenthesis will be sent to the output device (in this case, a string). The println method places a newline character at the end of whatever is being printed out. The following lines would be printed out on separate lines since the first statement sends a newline command to the screen: System.out.println("This is being printed out"); System.out.println("on two separate lines.");

print (“Print, and stay on same line”) The print statement works very similarly to the println statement. However, the print statement does not put a newline character at the end of the output. Using print will continue going on the same line. The lines: System.out.print("These lines will be"); System.out.print("printed on"); System.out.println("the same line."); Will output: These lines will beprinted onthe same line. Notice the odd spacing? Why do some words run together?

RECAP: print vs. println Using System.out.print(“Some string.”) Continues on the SAME LINE after it’s done printing println Using System.out.println(“Some string.”) Drops down to the NEXT LINE after it’s done printing So: Think of the ln in println standing for “line next” or “line new”

Special Characters in String For all of the previous examples, we have been printing out strings of characters. Later, we will see that much more can be printed. There are some special characters that can be put into the output. System.out.print("This line will have a newline at the end.\n"); System.out.print("This doesn’t show up on the same line."); The \n in the string is an escape sequence that represents the newline character. Escape sequences allow the programmer to print characters that otherwise would be unprintable.

Java Escape Sequences ("Special Characters") newline Advances the cursor to the next line for subsequent printing \t tab Causes the cursor to skip over to the next tab stop \b backspace Causes the cursor to back up, or move left, one position \r carriage return Causes the cursor to go to the beginning of the current line, not the next line \\ backslash Causes a backslash to be printed \' single quote Causes a single quotation mark to be printed \" double quote Causes a double quotation mark to be printed

Java Escape Sequences ("Special Characters") Even though the escape sequences are comprised of two characters, they are treated by the compiler as a single character. System.out.print("These are our top sellers:\n"); System.out.print(“==========================\n"); System.out.print("\t- Computer games\n\t- Coffee\n "); System.out.println("\t- Aspirin"); Would result in the following output: These are our top sellers: ========================== - Computer games - Coffee - Aspirin With these escape sequences, complex text output can be achieved.

The + Operator The + operator can be used in two ways. (1) as a concatenation operator (2) as an addition operator If either side of the + operator is a string, the result will be a string. System.out.println("Hello " + "World!"); Hello World! System.out.println("The value is: " + 5); The value is: 5 System.out.println("The value is: " + value); The value is: <whatever value is> System.out.println("The value is" + ": \n" + 5); The value is: 5

String Concatenation Java commands that have string literals must be treated with care. A string literal value cannot span lines in a Java source code file. System.out.println("This line is too long and now it has spanned more than one line, which will cause a syntax error to be generated by the compiler. "); The String concatenation operator can be used to fix this problem. System.out.println("These lines are " + "now ok and will not " + "cause the error as before."); String concatenation can join various data types. System.out.println("We can join a string to " + "a number like this: " + 5); http://en.wikipedia.org/wiki/Concatenation

String Concatenation The concatenation operator can be used to format complex String objects. System.out.println("The following will be printed " + "in a tabbed format: " + "\n\tFirst = " + 5 * 6 + ", " + "\n\tSecond = " + (6 + 4) + "," + "\n\tThird = " + 16.7 + "."); Notice that if an addition operation is also needed, it must be put in parenthesis.

Printing as Part of Program Decision-Making int newNum = 3; if( newNum >= 5 ) { System.out.println( newNum + “ is larger than 4”); } else { System.out.println( newNum + “ is smaller than 5.”); } Basic Output Demo.java Two Points: 1) ‘+’ for concatenation 2) spaces in “ ”double-quotes Demo: Basic Output Demo.java

In-Class Exercises Lecture 7 > Output (Printing Text Messages To The Screen) Basic Output Demo.java DEMO In-Class Exercises Directions Output Trace Table Basic Output Trace.java ( Example Note )