Computer Science. 4. Input and Output. 4. Input and Output. Computer Science. Standard input and output. Standard drawing Fractal drawings Animation

Size: px
Start display at page:

Download "Computer Science. 4. Input and Output. 4. Input and Output. Computer Science. Standard input and output. Standard drawing Fractal drawings Animation"

Transcription

1 Computer Science 4. Input and Output Standard input and output 4. Input and Output Computer Science Standard drawing Fractal drawings Animation An Interdisciplinary Approach.5 ROBERT SEDGEWICK K E V I N WAY N E CS.4.A.IO.Standard Basic building blocks for programming Input and output Goal: Write s that interact with the outside world via input and output devices. any program you might want to write Typical INPUT devices objects functions and modules Keyboard Trackpad Storage Camera Network Microphone graphics, sound, and image I/O Typical OUTPUT devices arrays conditionals and loops Math primitive data types Ability to interact with the outside world Storage text I/O Network Printer Speakers Display Our approach. assignment statements Define input and output abstractions. Use operating system (OS) functionality to connect our s to actual devices. 3 4

2 Abstraction Quick review plays an essential role in understanding computation. Interested in thinking more deeply about this concept? Consider taking a philosophy course. Terminal. An abstraction for providing input and output to a program. An abstraction is something that exists only as an idea. Example: "Printing" is the idea of a program producing text as output. Input from command line % java DrawCards Good abstractions simplify our view of the world, by unifying diverse real-world artifacts. 7 Q A Q Q 6 5 Output to standard output stream Virtual VT- terminal This lecture. Abstractions for delivering input to or receiving output from our programs. 5 Input-output abstraction (so far) 6 Review: command-line input Command-line input. An abstraction for providing arguments (strings) to a program. A mental model of what a does. command-line arguments Basic properties Strings you type after the program name are available as args[], args[],... at run time. Arguments are available when the program begins execution. Need to call system conversion methods to convert the strings to other types of data. public class RandomInt int N = Integer.parseInt(args[]); double r = Math.random(); int t = (int) (r * N); System.out.println(t); standard output stream 7 % java RandomInt 6 3 % java RandomInt 384 8

3 Review: standard output Improved input-output abstraction Infinity. An abstraction describing something having no limit. Add an infinite input stream. Standard output stream. An abstraction for an infinite output sequence. command-line arguments standard input stream Basic properties Strings from System.out.println() are added to the end of the standard output stream. Standard output stream is sent to terminal application by default. public class RandomSeq int N = Integer.parseInt(args[]); for (int i = ; i < N; i++) System.out.println(Math.random()); % java RandomSeq No limit on amount of output % java RandomSeq standard output stream 9 Standard input StdIn library Developed for this course, but broadly useful Implement abstractions invented for UNIX in the 97s. Available for download at booksite. Included in introcs software you downloaded at the beginning of the course. Standard input stream. An abstraction for an infinite input sequence. Computer Science Infinity. An abstraction describing something having no limit. Computer Science An Interdisciplinary Approach ROBERT SEDGEWICK K E V I N WAY N E standard input stream public class StdIn boolean isempty() int readint() double readdouble() long readlong() boolean readboolean() Advantages over command-line input Can provide new arguments while the program is executing. char readchar() No limit on the amount of data we can input to a program. Conversion to primitive types is explicitly handled (stay tuned). true iff no more values read a value of type int read a value of type double standard input stream read a value of type long read a value of type boolean read a value of type char String readstring() read a value of type String String readall() read the rest of the text

4 StdOut library StdIn/StdOut warmup Implement abstractions invented for UNIX in the 97s. Available for download at booksite. Included in introcs software you downloaded at the beginning of the course. Computer Science Developed for this course, but broadly useful Interactive input Prompt user to type inputs on standard input stream. Computer Science Mix input stream with output stream. An Interdisciplinary Approach ROBERT SEDGEWICK K E V I N WAY N E public class AddTwo StdOut.print("Type the first integer: "); int x = StdIn.readInt(); StdOut.print("Type the second integer: "); int y = StdIn.readInt(); int sum = x + y; StdOut.println("Their sum is " + sum); public class StdOut void print(string s) put s on the output stream void println() put a newline on the output stream void println(string s) put s, then a newline on the stream void printf(string f,...) formatted output standard output stream Q. These are the same as System.out. Why not just use System.out? A. We provide a consistent set of simple I/O abstractions in one place. use StdOut from now on % java AddTwo Type the first integer: Type the second integer: Their sum is 3 A. We can make output independent of system, language, and locale. 3 StdIn application: average the numbers on the standard input stream Average Read a stream of numbers. Compute their average. Q. How do I specify the end of the stream? A. <Ctrl-d> (standard for decades). A. <Ctrl-z> (Windows). Key points No limit on the size of the input stream. Input and output can be interleaved. 4 Summary: prototypical applications of standard output and standard input StdOut: Generate a stream of random numbers public class Average double sum =.; // cumulative total int n = ; // number of values while (!StdIn.isEmpty()) double x = StdIn.readDouble(); sum = sum + x; n++; StdOut.println(sum / n); public class RandomSeq int N = Integer.parseInt(args[]); for (int i = ; i < N; i++) StdOut.println(Math.random()); StdIn: Compute the average of a stream of numbers public class Average double sum =.; // cumulative total int n = ; // number of values while (!StdIn.isEmpty()) double x = StdIn.readDouble(); sum = sum + x; n++; StdOut.println(sum / n); Both streams are infinite (no limit on their size). % java Average <Ctrl-d>.5 Q. Do I always have to type in my input data and print my output? A. No! Keep data and results in files on your computer, or use piping to connect programs. 5 6

5 Redirection: keep data in files on your computer Piping: entirely avoid saving data Redirect standard output to a file % java RandomSeq > data.txt % more data.txt "redirect standard output to" Redirect from a file to standard input % java Average < data.txt "take standard input from" Q. There's no room for a huge file on my computer. Now what? A. No problem! Use piping. Piping. Connect standard output of one program to standard input of another. % java RandomSeq java Average % java RandomSeq java Average set up a pipe RandomSeq RandomSeq standard output stream standard input stream Average standard output stream file standard input stream Slight problem. Still limited by maximum file size. Average 7 Critical point. No limit within programs on the amount of data they can handle. It is the job of the system to collect data on standard output and provide it to standard input. 8 Streaming algorithms Early computing Amount of available memory was much smaller than amount of data to be processed. But dramatic increases happened every year. Redirection and piping enabled programs to handle much more data than computers could store. Image sources PART I: PROGRAMMING IN JAVA Modern computing Amount of available memory is much smaller than amount of data to be processed. Dramatic increases still happen every year. Streaming algorithms enable our programs to handle much more data than our computers can store. Lesson. Avoid limits within your program whenever possible. 9 CS.4.A.IO.Standard

6 Further improvements to our I/O abstraction Add the ability to create a drawing. command-line arguments standard input stream 4. Input and Output Standard input and output Standard drawing Fractal drawings standard output stream standard drawing Computer Science Animation StdDraw library Computer Science An Interdisciplinary Approach ROBERT SEDGEWICK K E V I N WAY N E Developed for this course, but broadly useful. Available for download at booksite. Included in introcs software. CS.4.B.IO.Drawing StdDraw library Hello, World for StdDraw public class StdDraw public class Triangle double c = Math.sqrt(3.) /.; StdDraw.setPenRadius(.); StdDraw.line(.,.,.,.); StdDraw.line(.,.,.5, c); StdDraw.line(.5, c,.,.); StdDraw.point(.5, c/3.); StdDraw.text(.5,.5, "Hello, World"); void line(double x, double y, double x, double y) void point(double x, double y) void text(double x, double y, String s) void circle(double x, double y, double r) also filledcircle(), filledsquare(), and filledpolygon() void square(double x, double y, double r) void polygon(double x, double y, double r) void picture(double x, double y, String filename) place.gif,.jpg or.png file void setpenradius(double r) void setpencolor(color c) void setxscale(double x, double x) reset x range to [x, x) void setyscale(double y, double y) reset y range to [y, y) void show(int dt) show all; pause dt millisecs Trace of drawing (.5, ) Hello, World (, ) (, ) standard drawing 3 4

7 Hello, World for StdDraw window for standard drawing public class Triangle double c = Math.sqrt(3.) /.; StdDraw.setPenRadius(.); StdDraw.line(.,.,.,.); StdDraw.line(.,.,.5, c); StdDraw.line(.5, c,.,.); StdDraw.point(.5, c/3.); StdDraw.text(.5,.5, "Hello, World"); % % javac Triangle.java % java Triangle virtual terminal for editor read coords of bounding box StdDraw application: data visualization public class PlotFilter double xmin = StdIn.readDouble(); rescale read and plot a point double ymin = StdIn.readDouble(); double xmax = StdIn.readDouble(); double ymax = StdIn.readDouble(); StdDraw.setXscale(xmin, xmax); StdDraw.setYscale(ymin, ymax); while (!StdIn.isEmpty()) double x = StdIn.readDouble(); double y = StdIn.readDouble(); StdDraw.point(x, y); % more < USA.txt % java PlotFilter < USA.txt bounding box coords sequence of point coordinates (3,59 cities) virtual terminal for OS commands 5 6 StdDraw application: plotting a function Goal. Plot y =sin(4x)+sin(x) in the interval (, π). Method. Take N samples, regularly spaced. % java PlotFunctionEx PART I: PROGRAMMING IN JAVA public class PlotFunctionEx int N = Integer.parseInt(args[]); double[] x = new double[n+]; double[] y = new double[n+]; for (int i = ; i <= N; i++) x[i] = Math.PI * i / N; y[i] = Math.sin(4*x[i]) + Math.sin(*x[i]); StdDraw.setXscale(, Math.PI); StdDraw.setYscale(-., +.); for (int i = ; i < N; i++) StdDraw.line(x[i], y[i], x[i+], y[i+]); Lesson : Plotting is easy. % java PlotFunctionEx Lesson : Take a sufficiently large sample otherwise you might miss something! 7 CS.4.B.IO.Drawing

8 StdDraw application: a random game Draw an equilateral triangle, number the vertices,, and make the current point Pick a vertex at random. Draw a point halfway between that vertex and the current point. 4. Input and Output Repeat. Standard input and output Standard drawing Fractal drawings vertex ID probability new x new y (, ) /3.5x.5y Animation (, ) /3.5x +.5.5y (.5, 3/) /3.5x +.5.5y CS.4.C.IO.Fractals 3 StdDraw application: a random game public class Chaos int trials = Integer.parseInt(args[]); Sierpinski triangles in the wild % java Chaos double c = Math.sqrt(3.) /.; double[] cx =.,.,.5 ; double[] cy =.,., c ; StdDraw.setPenRadius(.); double x =., y =.; for (int t = ; t < trials; t++) int r = (int) (Math.random() * 3); x = (x + cx[r]) /.; y = (y + cy[r]) /.; StdDraw.point(x, y); odd numbers Pascal's triangle 3 3

9 Iterated function systems Iterated function systems What happens when we change the rules? probability new x Another example of changing the rules % java IFS < coral.txt new y probability new x %.5 4%.3x.53y x.9y +. 5%.3x.8y +..5x.45y %.69x.y %.7x 7%.78x +.3y +. 45%.55y +. IFS.java (Program..3) is a data-driven program that takes the coefficients from standard input. % more coral.txt x +.6y +.57.y +.4 % java IFS < barnsley.txt new y.7y.5x +.y -.4.x +.8y +.9.3x +.74y +.7 % more barnsley.txt Iterated function systems Simple iterative computations yield patterns that are remarkably similar to those found in the natural world. Image sources Q. What does computation tell us about nature? an IFS fern a real fern Q. What does nature tell us about computation? cb777/jamescameronsavatar/images/e/e/avatar_concept_art-3.jpg th century sciences. Formulas. st century sciences. Algorithms? a real plant an IFS plant Note. You have seen many practical applications of integrated function systems, in movies and games. 35 CS.4.C.IO.Fractals

10 PART I: PROGRAMMING IN JAVA Animation To create animation with StdDraw. rx+vx Repeat the following: 4. Input and Output Standard input and output Standard drawing Fractal drawings Animation Clear the screen. Move the object. Draw the object. Display and pause briefly. When display time is much greater than the screen-clear time, we have the illusion of motion. Bouncing ball. Ball has position (rx, ry) and constant velocity (vx, vy). To move the ball, update position to (rx+vx, ry+vy). ry rx vy vx ry+vy If the ball hits a vertical wall, set vx to -vx. If the ball hits a horizontal wall, set vy to -vy. CS.4.D.IO.Animation 38 Bouncing ball Pop quiz on animation public class BouncingBall double rx =.48, ry =.86; double vx =.5, vy =.3; double radius =.5; StdDraw.setXscale(-., +.); StdDraw.setYscale(-., +.); while(true) StdDraw.setPenColor(StdDraw.LIGHT_GRAY); StdDraw.filledSquare(.,.,.); if (Math.abs(rx + vx) + radius >.) vx = -vx; if (Math.abs(ry + vy) + radius >.) vy = -vy; rx = rx + vx; ry = ry + vy; StdDraw.setPenColor(StdDraw.BLACK); StdDraw.filledCircle(rx, ry, radius); StdDraw.show(); % java BouncingBall Q. What happens if we move clear the screen out of the loop? public class BouncingBall double rx =.48, ry =.86; double vx =.5, vy =.3; double radius =.5; StdDraw.setXscale(-., +.); StdDraw.setYscale(-., +.); while(true) StdDraw.setPenColor(StdDraw. LIGHT_GRAY); StdDraw.filledSquare(.,.,.); if (Math.abs(rx + vx) + radius >.) vx = -vx; if (Math.abs(ry + vy) + radius >.) vy = -vy; rx = rx + vx; ry = ry + vy; StdDraw.setPenColor(StdDraw.BLACK); StdDraw.filledCircle(rx, ry, sz); StdDraw.show(); 39 4

11 Pop quiz on animation Deluxe bouncing ball Q. What happens if we move clear the screen out of the loop? public class BouncingBall double rx =.48, ry =.86; double vx =.5, vy =.3; double radius =.5; StdDraw.setXscale(-., +.); StdDraw.setYscale(-., +.); StdDraw.setPenColor(StdDraw. LIGHT_GRAY); StdDraw.filledSquare(.,.,.); while(true) if (Math.abs(rx + vx) + radius >.) vx = -vx; if (Math.abs(ry + vy) + radius >.) vy = -vy; rx = rx + vx; ry = ry + vy; StdDraw.setPenColor(StdDraw.BLACK); StdDraw.filledCircle(rx, ry, radius); StdDraw.show(); public class BouncingBallDeluxe double rx =.48, ry =.86; double vx =.5, vy =.3; double radius =.5; StdDraw.setXscale(-., +.); StdDraw.setYscale(-., +.); while(true) StdDraw.setPenColor(StdDraw. LIGHT_GRAY); StdDraw.filledSquare(.,.,.); if (Math.abs(rx + vx) + radius >.) StdAudio.play("pipebang.wav"); vx = -vx; if (Math.abs(ry + vy) + radius >.) StdAudio.play("pipebang.wav"); vy = -vy; rx = rx + vx; ry = ry + vy; StdDraw.picture(rx, ry, "TennisBall.png"); StdDraw.show(); A. We see the ball s entire path. % java BouncingBallDeluxe Stay tuned to next lecture for full description of StdAudio. 4 4 A set of I/O abstractions for Java StdIn, StdOut, StdDraw, and StdAudio. Available for download at booksite (and included in introcs software). Computer Science Developed for this course, but broadly useful Computer Science An Interdisciplinary Approach ROBERT SEDGEWICK K E V I N WAY N E command-line arguments standard input stream standard output stream standard drawing standard audio 43 CS.4.D.IO.Animation

12 Computer Science Computer Science An Interdisciplinary Approach.5 ROBERT SEDGEWICK K E V I N WAY N E 4. Input and Output

1.3 Conditionals and Loops

1.3 Conditionals and Loops A Foundation for Programming 1.3 Conditionals and Loops any program you might want to write objects functions and modules graphics, sound, and image I/O arrays conditionals and loops Math primitive data

More information

1. Writing Simple Classes:

1. Writing Simple Classes: The University of Melbourne Department of Computer Science and Software Engineering 433-254 Software Design Semester 2, 2003 Answers for Lab 2 Week 3 1. Writing Simple Classes: a) In Java systems, there

More information

1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM!

1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM! 1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM! A Foundation for Programming any program you might want

More information

University of Pennsylvania. Electrical & Systems Engineering Undergraduate Laboratories. ESE 112: Introduction to Electrical & Systems Engineering

University of Pennsylvania. Electrical & Systems Engineering Undergraduate Laboratories. ESE 112: Introduction to Electrical & Systems Engineering University of Pennsylvania Electrical & Systems Engineering Undergraduate Laboratories ESE 112: Introduction to Electrical & Systems Engineering Lab 6: Digital Signal Processing Original Assignment by

More information

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

Using Files as Input/Output in Java 5.0 Applications

Using Files as Input/Output in Java 5.0 Applications Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead

More information

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION 2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION A world-coordinate area selected for display is called a window. An area on a display device to which a window is mapped is called a viewport. The window

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print

More information

WAYNESBORO AREA SCHOOL DISTRICT CURRICULUM INTRODUCTION TO COMPUTER SCIENCE (June 2014)

WAYNESBORO AREA SCHOOL DISTRICT CURRICULUM INTRODUCTION TO COMPUTER SCIENCE (June 2014) UNIT: Programming with Karel NO. OF DAYS: ~18 KEY LEARNING(S): Focus on problem-solving and what it means to program. UNIT : How do I program Karel to do a specific task? Introduction to Programming with

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Directions: In mobile Applications the Control Model View model works to divide the work within an application.

More information

1.1 Your First Program

1.1 Your First Program Why Programming? 1.1 Your First Program Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of N heavenly bodies, subject

More information

Java Programming Fundamentals

Java Programming Fundamentals Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few

More information

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing.

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing. Computers An Introduction to Programming with Python CCHSG Visit June 2014 Dr.-Ing. Norbert Völker Many computing devices are embedded Can you think of computers/ computing devices you may have in your

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

13 File Output and Input

13 File Output and Input SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to

More information

ANIMATED FRACTALS. osler@rowan.edu. nature very complex. In the classroom, it can be very instructive to watch the fractal image

ANIMATED FRACTALS. osler@rowan.edu. nature very complex. In the classroom, it can be very instructive to watch the fractal image 7/15/98 1 ANIMATED FRACTALS Mathematics and Computer Education,Vol.33 (1999),pp.236-243. 1. Introduction Thomas J. Osler Mathematics Department Rowan University Glassboro, NJ 08028 osler@rowan.edu In this

More information

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab. Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Chapter 1 Java Program Design and Development

Chapter 1 Java Program Design and Development presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

http://algs4.cs.princeton.edu dictionary find definition word definition book index find relevant pages term list of page numbers

http://algs4.cs.princeton.edu dictionary find definition word definition book index find relevant pages term list of page numbers ROBERT SEDGEWICK KEVI WAYE F O U R T H E D I T I O ROBERT SEDGEWICK KEVI WAYE ROBERT SEDGEWICK KEVI WAYE Symbol tables Symbol table applications Key-value pair abstraction. Insert a value with specified.

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Lecture 5: Java Fundamentals III

Lecture 5: Java Fundamentals III Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd

More information

6.1. Example: A Tip Calculator 6-1

6.1. Example: A Tip Calculator 6-1 Chapter 6. Transition to Java Not all programming languages are created equal. Each is designed by its creator to achieve a particular purpose, which can range from highly focused languages designed for

More information

Java Crash Course Part I

Java Crash Course Part I Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux

More information

1001ICT Introduction To Programming Lecture Notes

1001ICT Introduction To Programming Lecture Notes 1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 3 A First MaSH Program In this section we will describe a very

More information

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson CS 3530 Operating Systems L02 OS Intro Part 1 Dr. Ken Hoganson Chapter 1 Basic Concepts of Operating Systems Computer Systems A computer system consists of two basic types of components: Hardware components,

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Introduction to programming

Introduction to programming Unit 1 Introduction to programming Summary Architecture of a computer Programming languages Program = objects + operations First Java program Writing, compiling, and executing a program Program errors

More information

AP Computer Science Java Mr. Clausen Program 9A, 9B

AP Computer Science Java Mr. Clausen Program 9A, 9B AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will

More information

Basics of I/O Streams and File I/O

Basics of I/O Streams and File I/O Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 21 10/16/2012 09:29 AM Java - A First Glance 2 of 21 10/16/2012 09:29 AM programming languages

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms PROG0101 FUNDAMENTALS OF PROGRAMMING Chapter 3 1 Introduction to A sequence of instructions. A procedure or formula for solving a problem. It was created mathematician, Mohammed ibn-musa al-khwarizmi.

More information

Using WINK to create custom animated tutorials

Using WINK to create custom animated tutorials Using WINK to create custom animated tutorials A great way for students and teachers alike to learn how to use new software is to see it demonstrated and to reinforce the lesson by reviewing the demonstration.

More information

Definition: A vector is a directed line segment that has and. Each vector has an initial point and a terminal point.

Definition: A vector is a directed line segment that has and. Each vector has an initial point and a terminal point. 6.1 Vectors in the Plane PreCalculus 6.1 VECTORS IN THE PLANE Learning Targets: 1. Find the component form and the magnitude of a vector.. Perform addition and scalar multiplication of two vectors. 3.

More information

2 SYSTEM DESCRIPTION TECHNIQUES

2 SYSTEM DESCRIPTION TECHNIQUES 2 SYSTEM DESCRIPTION TECHNIQUES 2.1 INTRODUCTION Graphical representation of any process is always better and more meaningful than its representation in words. Moreover, it is very difficult to arrange

More information

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files File I/O - Chapter 10 A Java stream is a sequence of bytes. An InputStream can read from a file the console (System.in) a network socket an array of bytes in memory a StringBuffer a pipe, which is an OutputStream

More information

Chapter 3. Input and output. 3.1 The System class

Chapter 3. Input and output. 3.1 The System class Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Patterns in Pascal s Triangle

Patterns in Pascal s Triangle Pascal s Triangle Pascal s Triangle is an infinite triangular array of numbers beginning with a at the top. Pascal s Triangle can be constructed starting with just the on the top by following one easy

More information

Unit 7 Quadratic Relations of the Form y = ax 2 + bx + c

Unit 7 Quadratic Relations of the Form y = ax 2 + bx + c Unit 7 Quadratic Relations of the Form y = ax 2 + bx + c Lesson Outline BIG PICTURE Students will: manipulate algebraic expressions, as needed to understand quadratic relations; identify characteristics

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

MXwendler Javascript Interface Description Version 2.3

MXwendler Javascript Interface Description Version 2.3 MXwendler Javascript Interface Description Version 2.3 This document describes the MXWendler (MXW) Javascript Command Interface. You will learn how to control MXwendler through the Javascript interface.

More information

System Calls and Standard I/O

System Calls and Standard I/O System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services

More information

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

7 th Grade Math Foundations for Teaching Unit One: Numbers & Operations Module One: Rational Number s

7 th Grade Math Foundations for Teaching Unit One: Numbers & Operations Module One: Rational Number s Unit One: Numbers & Operations Module One: s Day/Date TEKS Activities and Resources Essential Question Aug 25 Aug 26 Aug 27 Aug 28 Aug 29 (SS) (SS) (SS) (SS) - First Day Procedures - Math Class Student

More information

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection

More information

Stage 5 Information and Software Technology

Stage 5 Information and Software Technology Stage 5 Information and Software Technology Year: Year 9 Teacher: Topic: Option 8: Software Development and Programming Time: This option involves students undertaking a range of activities that will lead

More information

Invitation to Ezhil : A Tamil Programming Language for Early Computer-Science Education 07/10/13

Invitation to Ezhil : A Tamil Programming Language for Early Computer-Science Education 07/10/13 Invitation to Ezhil: A Tamil Programming Language for Early Computer-Science Education Abstract: Muthiah Annamalai, Ph.D. Boston, USA. Ezhil is a Tamil programming language with support for imperative

More information

Designing with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219

Designing with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Designing with Exceptions CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Testing vs. Debugging Testing Coding Does the code work properly YES NO 2 Debugging Testing

More information

Wilson Area School District Planned Course Guide

Wilson Area School District Planned Course Guide Wilson Area School District Planned Course Guide Title of planned course: Introduction to Computer Programming Subject Area: Business Grade Level: 9-12 Course Description: In this course, students are

More information

C# and Other Languages

C# and Other Languages C# and Other Languages Rob Miles Department of Computer Science Why do we have lots of Programming Languages? Different developer audiences Different application areas/target platforms Graphics, AI, List

More information

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources

More information

Stacks. Data Structures and Data Types. Collections

Stacks. Data Structures and Data Types. Collections Data Structures and Data Types Data types Set values. Set operations on those values. Some are built in to Java: int, double, char,... Most are not: Complex, Picture, Charge, Stack, Queue, Graph,... Data

More information

Mathematical Ideas that Shaped the World. Chaos and Fractals

Mathematical Ideas that Shaped the World. Chaos and Fractals Mathematical Ideas that Shaped the World Chaos and Fractals Plan for this class What is chaos? Why is the weather so hard to predict? Do lemmings really commit mass suicide? How do we measure the coastline

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

CPLEX Tutorial Handout

CPLEX Tutorial Handout CPLEX Tutorial Handout What Is ILOG CPLEX? ILOG CPLEX is a tool for solving linear optimization problems, commonly referred to as Linear Programming (LP) problems, of the form: Maximize (or Minimize) c

More information

An Introduction to Computer Science

An Introduction to Computer Science An Introduction to Computer Science Robert Sedgewick Kevin Wayne Princeton University Copyright 2003 by Robert Sedgewick and Kevin Wayne For information on obtaining permission for use of material from

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

public static void main(string[] args) { System.out.println("hello, world"); } }

public static void main(string[] args) { System.out.println(hello, world); } } Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static

More information

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m) MATLAB Functions What is a MATLAB function? A MATLAB function is a MATLAB program that performs a sequence of operations specified in a text file (called an m-file because it must be saved with a file

More information

Illustration 1: Diagram of program function and data flow

Illustration 1: Diagram of program function and data flow The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline

More information

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan DATA 301 Introduction to Data Analytics Microsoft Excel VBA Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca DATA 301: Data Analytics (2) Why Microsoft Excel Visual Basic

More information

MATH 60 NOTEBOOK CERTIFICATIONS

MATH 60 NOTEBOOK CERTIFICATIONS MATH 60 NOTEBOOK CERTIFICATIONS Chapter #1: Integers and Real Numbers 1.1a 1.1b 1.2 1.3 1.4 1.8 Chapter #2: Algebraic Expressions, Linear Equations, and Applications 2.1a 2.1b 2.1c 2.2 2.3a 2.3b 2.4 2.5

More information

How to Build a Simple Pac-Man Game

How to Build a Simple Pac-Man Game How to Build a Simple Pac-Man Game For today's program, we are going to build a simple Pac-Man game. Pac-Man was one of the very first arcade games developed around 1980. For our version of Pac-Man we

More information

INTRODUCTION TO DIGITAL SYSTEMS. IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE

INTRODUCTION TO DIGITAL SYSTEMS. IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE INTRODUCTION TO DIGITAL SYSTEMS 1 DESCRIPTION AND DESIGN OF DIGITAL SYSTEMS FORMAL BASIS: SWITCHING ALGEBRA IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE COURSE EMPHASIS:

More information

While Loops and Animations

While Loops and Animations C h a p t e r 6 While Loops and Animations In this chapter, you will learn how to use the following AutoLISP functions to World Class standards: 1. The Advantage of Using While Loops and Animation Code

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

C++ Input/Output: Streams

C++ Input/Output: Streams C++ Input/Output: Streams 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams: istream

More information

cs2010: algorithms and data structures

cs2010: algorithms and data structures cs2010: algorithms and data structures Lecture 11: Symbol Table ADT. Vasileios Koutavas 28 Oct 2015 School of Computer Science and Statistics Trinity College Dublin Algorithms ROBERT SEDGEWICK KEVIN WAYNE

More information

Marist School Computational Media. Processing Exercise 01 Bouncing Ball Animation. Description:

Marist School Computational Media. Processing Exercise 01 Bouncing Ball Animation. Description: Marist School Computational Media Processing Exercise 01 Bouncing Ball Animation Description: In this exercise we will create an animation to show shapes moving and bouncing off the edges of the screen.

More information

Creating a Simple, Multithreaded Chat System with Java

Creating a Simple, Multithreaded Chat System with Java Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate

More information

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be: Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from

More information

Computer Science III Advanced Placement G/T [AP Computer Science A] Syllabus

Computer Science III Advanced Placement G/T [AP Computer Science A] Syllabus Computer Science III Advanced Placement G/T [AP Computer Science A] Syllabus Course Overview This course is a fast-paced advanced level course that focuses on the study of the fundamental principles associated

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

In this Chapter you ll learn:

In this Chapter you ll learn: Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage Outline 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running

More information

PIC 10A. Lecture 7: Graphics II and intro to the if statement

PIC 10A. Lecture 7: Graphics II and intro to the if statement PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the

More information

Mathematics as Problem Solving The students will demonstrate the ability to gather information from a graphical representation of an equation.

Mathematics as Problem Solving The students will demonstrate the ability to gather information from a graphical representation of an equation. Title: Another Way of Factoring Brief Overview: Students will find factors for quadratic equations with a leading coefficient of one. The students will then graph these equations using a graphing calculator

More information

Euler s Method and Functions

Euler s Method and Functions Chapter 3 Euler s Method and Functions The simplest method for approximately solving a differential equation is Euler s method. One starts with a particular initial value problem of the form dx dt = f(t,

More information

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays. Arrays Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html 1 Grid in Assignment 2 How do you represent the state

More information

CMPT 183 Foundations of Computer Science I

CMPT 183 Foundations of Computer Science I Computer Science is no more about computers than astronomy is about telescopes. -Dijkstra CMPT 183 Foundations of Computer Science I Angel Gutierrez Fall 2013 A few questions Who has used a computer today?

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Input and Interaction

Input and Interaction Input and Interaction 1 Objectives Introduce basic input devices Physical Devices Logical Devices Input Modes Event-driven input Introduce double buffering for smooth animations Programming event input

More information