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”

Slides:



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

IT151: Introduction to Programming
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
2.2 Information on Program Appearance and Printing.
Introduction to Python
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Lecture 7 Instructor: Craig Duckett “OUTPUT”. Lecture 7 Annoucements this ASSIGNMENT 2 is due this Thursday, October 22 nd, uploaded to StudentTracker.
Chapter 2: Java Fundamentals
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
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.
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.
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
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.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
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”
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Output THE BASICS. What is Output? Output is the information that comes FROM a computer OUT to a user Sometimes this information is feedback to an action.
Lecture 4 – Scanner & Style
BIT115: Introduction to Programming
BIT 115: Introduction To Programming
C++ First Steps.
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
BIT 115: Introduction To Programming
BIT 115: Introduction To Programming
CSC201: Computer Programming
Chapter 3 GC 101 Java Fundamentals.
Chapter 2: Java Fundamentals by Tony Gaddis and Godfrey Muganda
Chapter 2: Java Fundamentals by Tony Gaddis and Godfrey Muganda
Console Output, Variables, Literals, and Introduction to Type
Chapter 2, Part I Introduction to C Programming
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Variables, Expressions, and IO
BIT 115: Introduction To Programming
String Input ICS 111: Introduction to Computer Science I
Chapter 2: Java Fundamentals
Number and String Operations
Introduction to C++ Programming
Chapter 2: Java Fundamentals
Introduction to Primitive Data types
The keyboard is the standard input device.
CSE 142, Spring 2012 Building Java Programs Chapter 1
Review of Previous Lesson
Chapter 2: Java Fundamentals
Unit 3: Variables in Java
Output Manipulation.
Chapter 2: Java Fundamentals
CSE 142, Winter 2014 Building Java Programs Chapter 1
Computer Programming-1 CSC 111
Chapter 1 c++ structure C++ Input / Output
Introduction to Primitive Data types
Presentation transcript:

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”

Lecture 8 Log into Canvas Put your name sticker on your computer Announcement: Java Code Critic Feedback Quiz08 Printing to output ICE08 Returning Quiz04

Java Code Critic Feedback A1 and ICE07 critiques of Java code are done So you can start work on A1 revisions! Lots of red comments doesn't necessarily mean your code is worse Generally your grade and overall comments indicates how well you did For ICE07 you got 10 points if you simply turned it in on time, so look for a Java Code Critic grade of “Well Done!” to indicate you have very little to worry about Often I’m commenting on coding techniques I have not lectured on yet (and thus might not be relevant to the midterm) Many critiques are about code conventions They are very important because they help you and other programmers understand and maintain your code but they usually don’t affect how computers will run your application Ask questions about requirements (even during exams)! It is better to get critiques about your coding Critiques about you not following instructions are not as useful toward helping you to learn coding BIT 115: Introduction To Programming3

And Now… Quiz08 Access Code:bw Time Limit:10 minutes

And Now… Sit Next To Each Other

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 after the midterm 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

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 in the Run I/O tab In Eclipse, this output is displayed in the Console tab 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!”

The Console Window 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.

The Console Window The print and println methods actually perform the task of sending characters to the output device. 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.");

The Console Window 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. 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.

The Console Window 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") \n newlineAdvances the cursor to the next line for subsequent printing \t tabCauses the cursor to skip over to the next tab stop \b backspaceCauses 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 \\ backslashCauses a backslash to be printed \'\' single quoteCauses a single quotation mark to be printed \"\" double quoteCauses a double quotation mark to be printed

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. Java Escape Sequences ("Special Characters")

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: System.out.println("The value is" + ": \n" + 5); The value is: 5 The + Operator

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

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 = " "."); 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 Demo: Two Points: 1) ‘+’ for concatenation 2) spaces in “ ”double-quotes

In-Class Exercises ICE08: Output (Printing Text Messages To The Screen)

Get Quiz04 back BIT 115: Introduction To Programming20