HANGMAN Project by Lori Kraus 12/3/03. WWWWe’ve played the game, now let’s see what goes on behind the scenes…. O \ | / | d b …but first, a few new.

Slides:



Advertisements
Similar presentations
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
Advertisements

Lecture 15: I/O and Parsing
Simple Programs Simple Strings Writing some programs Only in Parameters? I/O Gadget.
SPIM and MIPS programming
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
1 Various Methods of Populating Arrays Randomly generated integers.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
Geoff Holmes Overview IO Zoo Stream I/O File I/O Buffering Random-Access Text Streams Examples Serialization Java IO – programs that start with import.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
CS 106 Introduction to Computer Science I 02 / 22 / 2008 Instructor: Michael Eckmann.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
1 Array, Pointer and Reference ( I ) Ying Wu Electrical Engineering and Computer Science Northwestern University EECS 230 Lectures.
CS102--Object Oriented Programming Lecture 14: – File I/O BufferedReader The File class Write to /read from Binary files Copyright © 2008 Xiaoyan Li.
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
CS 106 Introduction to Computer Science I 02 / 19 / 2007 Instructor: Michael Eckmann.
INTRODUCTION TO PYTHON PART 2 INPUT AND OUTPUT CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
C Programming Day 2 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
1 Course Lectures Available on line:
Two Ways to Store Data in a File Text format Binary format.
Input & Output: Console
Java for Beginners University Greenwich Computing At School DASCO
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved.1 Chapter 4 Mathematical Functions, Characters, and Strings.
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
Overloading There is another aspect to polymorphism: Overloading Overloading is not overriding. In Turkish: Overridding: eskisini (geçersiz kılmak) Overloading:
Math Class Part of the Java.lang package. This package is from object so you do not have to import the lang package. Static: Math Class is static.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
Recursive Problem 1 Write a java class named my_WordReverse using recursion. It takes a sentence and returns the sentence in reverse order. Note: Space.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 3 Console Output Keyboard Input Numerical.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
Basics and arrays Operators:  Arithmetic: +, -, *, /, %  Relational:, >=, ==, !=  Logical: &&, ||, ! Primitive data types Byte(8), short(16), int(32),
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
1 Chapter 2: Java Fundamentals cont’d Spring Lory Al Moakar.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Jeopardy Print Me Which loop? Call Me Name Me My Mistake Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
Computer Programming with Java Chapter 2 Primitive Types, Assignment, and Expressions.
CSCI 1100/1202 January 23, Class Methods Some methods can be invoked through the class name, instead of through an object of the class These methods.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
GCSE Computing: Programming GCSE Programming Remembering Python.
HANGMAN- Software/ Hardware Integration Project Idea was to design a working C++ program to play a Hangman word guessing game Idea was to design a working.
Java Input and Output. Java Input  Input is any information needed by your program to complete its execution  So far we have been using InputBox for.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
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.
1 Arrays Chapter 8. Objectives You will be able to Use arrays in your Java programs to hold a large number of data items of the same type. Initialize.
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
Introduction to programming in java Lecture 21 Arrays – Part 1.
Using the Console.
CSC 1051 – Data Structures and Algorithms I
I/O Basics.
Use proper case (ie Caps for the beginnings of words)
Value returning Functions
Input and Output with FILES
Java: Variables, Input and Arrays
Presentation transcript:

HANGMAN Project by Lori Kraus 12/3/03

WWWWe’ve played the game, now let’s see what goes on behind the scenes…. O \ | / | d b …but first, a few new things

Creating an Array  2 ways: type[ ] arrayName = new type[length]; type[ ] arrayName = new type[length]; arrayName[0] = item1; arrayName[0] = item1; arrayName[1] = item2; arrayName[1] = item2; type[ ] arrayName = {item0, item1, …, itemN}; type[ ] arrayName = {item0, item1, …, itemN};  Here’s what I did: private String[ ] wordBank = {"computer", "science", "project", "object", "binary", "application", "applet", "website", "method", "variable"}; private String[ ] wordBank = {"computer", "science", "project", "object", "binary", "application", "applet", "website", "method", "variable"};

Generating a Random Number  class Math Random numbers Random numbers Math.random( ) produces a double value betweenMath.random( ) produces a double value between 0 and 1 0 and 1 Max and min Max and min Exponents Exponents Square roots, etc. Square roots, etc.  Here’s what I did: randomNum = randomNum = (int)((Math.random( ) * 1000) % 10); (int)((Math.random( ) * 1000) % 10);

Other Useful Methods  int length; String word; char[ ] wordArray;  length = word.length( ); assigns the value of the length of the word to int length assigns the value of the length of the word to int length  wordArray = new char[length]; creates character array wordArray same length as word creates character array wordArray same length as word  word.getChars(0, length, wordArray, 0); puts characters from 0 to length of String word into wordArray, starting at index 0 puts characters from 0 to length of String word into wordArray, starting at index 0

System.out.println  Suppose int answer = 5  We know System.out.println(“answer = ” + answer); System.out.println(“answer = ” + answer); will look like: answer = 5 will look like: answer = 5  There are also ways to print things on new lines (/n), at the tabs (/t), etc.  For example: System.out.println(“answer = /n” + answer); System.out.println(“answer = /n” + answer); will look like: answer = will look like: answer = 5

 Here’s what I did: System.out.println("\n***You win!***\n"); System.out.println("\n***You win!***\n"); It looks like: It looks like: ***You win!*** ***You win!***  Also, in order to print a backslash ( \ ), you have to type: System.out.println(“\\”); System.out.println(“\\”);

Getting Input From the Console  class System System.in is the stream corresponding to the keyboard input System.in is the stream corresponding to the keyboard input  class InputStreamReader Reads bytes and translates them into characters according to a specified character encoding Reads bytes and translates them into characters according to a specified character encoding  class BufferedReader Reads text from a character-input stream, buffering characters so as to provide for more efficient reading Reads text from a character-input stream, buffering characters so as to provide for more efficient reading Method readLine( ) returns a String containing the contents of the particular line Method readLine( ) returns a String containing the contents of the particular line

Common Example:  BufferedReader inputGuess = new BufferedReader ( new InputStreamReader (System.in)); System.out.print("\nGuess a letter:"); System.out.print("\nGuess a letter:"); String guess = inputGuess.readLine( ); String guess = inputGuess.readLine( );  This takes whatever letter the user types in and stores it into the String guess

Now let’s look at the code!