Lecture 7. Instructor: Craig Duckett OUTPUT

Similar documents
Lecture 6. Instructor: Craig Duckett

CHAPTER 2 Java Fundamentals

BIT 115: Introduction To Programming LECTURE 3. Instructor: Craig Duckett

Chapter 2: Java Fundamentals

8/23/2014. Chapter Topics. Chapter Topics (2) Parts of a Java Program. Parts of a Java Program. Analyzing The Example. Chapter 2: Java Fundamentals

Lecture 8 " INPUT " Instructor: Craig Duckett

Lecture 17. Instructor: Craig Duckett. Passing & Returning Arrays

Lecture 10. Instructor: Craig Duckett

Lecture 12. Instructor: Craig Duckett

CSE 142. Lecture 1 Course Introduction; Basic Java. Portions Copyright 2008 by Pearson Education

Lecture 11. Instructor: Craig Duckett. Instance Variables

Asking For Help. BIT 115: Introduction To Programming 1

First Java Program - Output to the Screen

Combo Lecture Lecture 14/15. Instructor: Craig Duckett

Week 2: Data and Output

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Instructor: Craig Duckett

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

Outline. CIS 110: Introduction to Computer Programming. What is Computer Science? What is computer programming? What is computer science?

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

What did we talk about last time? Examples switch statements

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Instructor: Craig Duckett. Lecture 02: Thursday, March 29 th, 2018 SQL Basics and SELECT, FROM, WHERE

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

Variables and Classes. In which we over-ride the super class, work with multiple classes, and move towards non-robot based programming

Full file at

ASSIGNMENT 4 Classes and Objects

Table of Contents Date(s) Title/Topic Page #s. Abstraction

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

CS 302: Introduction to Programming

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Lecture 3: Variables and assignment

CSE 113 A. Announcements - Lab

Lab # 2. For today s lab:

St. Edmund Preparatory High School Brooklyn, NY

Laboratory 1: Eclipse and Karel the Robot

Lecture 13. Instructor: Craig Duckett. Boolean Expressions, Logical Operators, and Return Values

Chapter 2: Data and Expressions

Java Basics. SP17 ICS 111 Ed Meyer

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

Robots. Byron Weber Becker. chapter 6

4. Java Project Design, Input Methods

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

CS 106 Introduction to Computer Science I

Fundamentals of Programming Session 4

AP Computer Science A

Lecture 2 Announcements

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Tips from the experts: How to waste a lot of time on this assignment

CIS*1500 Introduction to Programming

Computer Science 210: Data Structures

Building Java Programs. Chapter 1: Introduction to Java Programming

COMP 110 Project 1 Programming Project Warm-Up Exercise

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

Object-Oriented Programming

SDKs - Eclipse. SENG 403, Tutorial 2

Full file at

Introduction to Java Applications

B. Subject-specific skills B1. Problem solving skills: Supply the student with the ability to solve different problems related to the topics

Robots. Byron Weber Becker. chapter 6

Chapter 2: Data and Expressions

CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O)

AP Computer Science A Summer Assignment 2017

CMPT 125: Lecture 3 Data and Expressions

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Java Camp Daily Schedule

Why do some students find programming in C, so difficult? It involves thinking. We have been programmed by our respective school boards not to think.

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Claremont McKenna College Computer Science

Fundamentals of Structured Programming

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

Information Science 1

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

Tips from the experts: How to waste a lot of time on this assignment

Topic 4 Expressions and variables

Mobile App:IT. Methods & Classes

Chapter 2 Basic Elements of C++

Week 3: Objects, Input and Processing

Introduction to Computer Science I

ASSIGNMENT 1 First Java Assignment

SCRATCH MODULE 3: NUMBER CONVERSIONS

Principles of Computer Science I

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Slide 1 CS 170 Java Programming 1

LAB 1: FAMILIARITY WITH NETBEANS IDE ENVIRONMENT

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

Lecture 5. Defining Functions

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

COMP String and Console I/O. Yi Hong May 18, 2015

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

SOS 2009 User Manual. Student Basics. Alpha Omega Publications

1. The programming language C is more than 30 years old. True or False? (Circle your choice.)

Transcription:

Lecture 7 Instructor: Craig Duckett OUTPUT

Lecture 7 Announcements ASSIGNMENT 2 is due LECTURE 8 NEXT LECTURE uploaded to StudentTracker by midnight Assignment 2!!!

Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) Section 1: Wednesday, January 31 st The Fickle Finger of Fate Assignment 1 Revision (LECTURE 10) Section 1: Wednesday, February 7 th Assignment 2 Revision (LECTURE 12) Section 1: Wednesday, February 14 th Assignment 3 (LECTURE 13) Section 1: Wednesday, February 21 st Assignment 3 Revision (LECTURE 16) Section 1: Monday, March 5 th Assignment 4 (LECTURE 18) NO REVISION AVAILABLE! Section 1: Monday, March 12 th 3

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 by 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!) 5

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 to walk you throw the process as described in the A2 Directions and A2 Rubric.

1. Create a new 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. It is highly recommended that you use MrRoboto.java from Lecture 3 as a reference (don t forget to add a fifth slot in the constructor to hold things, see example below). Also, don t forget to change extends Object to extends Robot (see example below). 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); }

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

3. Create a turnright() and turnaround() method, which you will use with three other methods (which I'll talk about one at a time). If you used MrRoboto.java as a reference (copy paste tweak) then you already have these made for you. 4. Create a movetowall() method which moves while the front is clear

5. Create a doeverything() method which will do the following: Declare and 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 Turn left Increment the counter by 1 This is all in one while loop //second part of doeverything continued on next slide

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

7. [doeverything continued] Finally, call the returntostart() method to go back to where the robot start (see #8 below) [end of doeverything] 8. The returntostart() method will do the following: turn around Call movetowall() Turn right 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 print 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") \n 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

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