Classwork 7: Craps. N. Duong & R. Rodriguez, Java Crash Course January 6, 2015

Size: px
Start display at page:

Download "Classwork 7: Craps. N. Duong & R. Rodriguez, Java Crash Course January 6, 2015"

Transcription

1 Classwork 7: Craps N. Duong & R. Rodriguez, Java Crash Course January 6, 2015 For this classwork, you will be writing code for the game Craps. For those of you who do not know, Craps is a dice-rolling game. How this game is played is by having a single player roll two dice. If the sum of the numbers on the dice is either 7 or 11 and this is the player s first roll of the game, the players automatically wins. If the sum of the numbers on the dice is either 2, 3, or 12 and this is the player s first roll of the game, the player loses. Otherwise, the sum of the numbers on the dice is the new winning number and the player continues to roll the dice until he wins the game. If the player is not on his first roll of the game and he rolls a 7, the player loses. However, if the player is not on his first roll of the game and he rolls the new winning number (the sum of the numbers on the dice on the first roll of the game), he wins. Otherwise, he will continue to roll until he either wins or loses the game. When the player wins or loses the game, his new winning number is no longer applicable meaning he will not win if he rolls on the "new winning number" (this is put in quotes because it s technically no longer a new winning number). To download the game files, please CLICK ON HERE! 1 The Program Explained You may feel a bit overwhelmed by the amount of files we need in order to create and run this simple dice-rolling game, and that s fine! However you should also realize that this is the amount of work that is required to be done in order to have a simple and properly functioning game. And with more complex games, there will be more files! This is just to give you a little bit of taste into actually programming something bigger than what we have done previously in this class. For this classwork, the only file you will be editing in will be CrapsGame.java. While you are welcome to look into the other files, please do not make any changes in the other files because it may break the program. In addition to this, it is OK if you do not understand a lot of the code in the other files. A lot of the ideas, and concepts written in the other files are well beyond this simple crash course. The biggest idea you need to understand is that CrapsGame.java does not require a main() method! Instead, we will be trying to write code for the method inside of CrapsGame.java abstractly. And in order for you to be able to write a method abstractly, you must know how Classwork 7 Page 1

2 a method is constructed well. Below this will be a short explanation on understanding what a method is suppose to do. 1 public static int iseven(int num) { } 4 Listing 1: Understanding Methods 5 / ** Everything below this is considered a comment -- which will not 6 * be read by the program. 7 * 8 * You may notice that the method inside of CrapsGame.java may not 9 * have static -- this is fine, static has to do with the way objects 10 * work. It is OK if static does not exist in the method declaration. 11 * 12 * What does it return? "int" -- how do we know this? Because after 13 * public and before the method s name is the type "int." Now we know 14 * what TYPE to return. 15 * 16 * Now what kind of argument(s) -- if any does it take in? You 17 * figure this out by looking between the parenthesis (...). If 18 * there are nothing inside of it, the program has no arguments, 19 * meaning it does not take in anything. However, in this specific 20 * case, we see that it takes in "int num". What this means, the 21 * program will take in "a variable called num with the type int". 22 * Now we know what arguments this method takes in. 23 * / At the moment, all you really need to know is that somewhere in the other files, there is a line of code that uses the method processroll(...), which you will be required to write the logic for. And since the current processroll(...) does not have actual logic to it, it does not return the correct value. Therefore, currently, our program is not working as it is supposed to. Now in order to fix this, we will need to write the logic out for the method processroll(...). 2 Understanding processroll(...) First thing you need to understand is that methods use the idea of abstraction. Meaning processroll(...) uses the idea of abstraction too! Therefore do not think of the game; instead, think of what processroll(...) is supposed to do. So here s the big question, what is processroll(...) suppose to do? Let s look at its declaration to figure it out. Listing 2: processroll() 1 public int processroll(int sumofroll) { Classwork 7 Page 2

3 2 // FIXME -- write the appropriate algorithm 3 return 0; // dummy return -- need to return an actual value later 4 } At the moment, we see that nothing is written inside the class besides a comment telling us to fix it with an appropriate algorithm. There is also a dummy return because the method demands something to be returned. So this gives us the first hint. This method needs to return something, but what? Using what we learned above, the type that comes after public but before the methodname is the type that gets returned. In this situation, it is an int. Now continue reading through the declaration, we see that something exists between the parenthesis. As mentioned above, this means that the method has an arguments (or in other words, the method takes something in). Now how do we figure out what type does it take in? By reading the variable created, which in this case is "int sumofroll". Translating this into English, it means "a variable sumofroll with the type int." Putting it all together: this method we are supposed to write will return an int. This method takes in an int called sumofroll for us to use in any manner we wish for the method to work properly. 3 What processroll(...) Does Now that you know the little details of the what processroll(...) expects from its declaration, we will move onto what is the "appropriate algorithm" for processroll(...) is. And what I mean by this is what the method processroll(...) is suppose to do. We know what it returns and takes in, but what does it do? processroll(...) is suppose to take its given argument, sumofroll, to return -1, 0, or 1. In this situation, -1, 0, 1 is lose, continue-playing, and win respectively. You will have to write an algorithm that will appropriate return either -1, 0, or 1 depending on whether or not the sumofroll is a winning number, losing number, or otherwise a number that does not affect the game and will let the player keep rolling the dice. You will be expected to figure out this algorithm by the description of the game given above and/or using the pseudocode we will be providing you in the next section. For those of you who do not know what pseudocode is, it is a guide/reference for an algorithm based on code to guide you on which paths/ideas/directions you should be taking in order to code the specific algorithm. Classwork 7 Page 3

4 4 processroll(...) Pseudocode The following is only a guide or reference on paths/ideas/directions you can take in order to create a functioning algorithm for the method processroll(...). You will need to translate this into actual Java code/syntax. While the following code may look like actual Java code, it is using the idea of abstraction such that some of the statements/commands we call inside the pseudocode may not actually exist inside of Java but when a human person read the pseudocode, they get understand what the pseudocode is trying to do and then the human person will translate it to the Java language. Again, do not copy this into your file. It will not work! Listing 3: processroll(...) pseudocode 1 processroll(int sumofroll) { 2 if (firstround) { 3 if (sumofroll is 7 or 11) { 4 WIN(); 5 } else if (sumofroll is 2 or 3 or 12) { 6 LOSE(); 7 } else { 8 SAVE_CURRENT_ROLL_SUM(); 9 CONTINUE_GAME(); 10 } 11 } else { // if it s not firstround, it s any other rounds else! 12 if (sumofroll is 7) { 13 RESET_WINNING_NUMBER(); 14 LOSE(); 15 } else if (sumofroll is winningnumber) { 16 RESET_WINNING_NUMBER(); 17 WIN(); 18 } else { 19 CONTINUE_GAME(); 20 } 21 } 22 } To see the pseudocode s commands defined, look onto the next page. Classwork 7 Page 4

5 firstround sumofroll winningnumber WIN() LOSE() CONTINUE_GAME() SAVE_CURRENT_ROLL_SUM() RESET_WINNING_NUMBER() The boolean representing whether or not this is the Player s first round in rolling the dice The variable representing the sum of the numbers on the dice after rolling. The variable representing the sum of the numbers on the dice that will be considered as the "winning number" after the first roll. Because this variable is to be remembered even after processroll(...) is called again, its declaration or creation should be outside of the processroll(...) scope the Player has won the game the Player has lost the game the Player has lost the game This will record/save/store the current sumofroll into winningnumber This will method will change the variable winningnumber to 0 so that a winning number will not exist anymore since the game will restart after the Player loses or wins 5 Disclaimer This program was originally created by Michael Ferraro for his APCS class. Some revisions were made by R. Rodriguez and N. Duong. We have his permission to use his code for this class assignment. Classwork 7 Page 5

Lesson 2.4 Arraylist

Lesson 2.4 Arraylist Lesson 24 Arraylist Mimi Duong Rosalba Rodriguez Java Crash Course January 6th, 2015 Data Structure ArrayLists Live Coding Methods Searching Through ArrayLists Classwork Storing Items in Java How have

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 18 November 7, 2016 CPSC 427, Lecture 18 1/19 Demo: Craps Game Polymorphic Derivation (continued) Name Visibility CPSC 427, Lecture 18 2/19

More information

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous Assignment 3 Methods Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required. Notes:

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab CSC 111 Fall 2005 Lab 6: Methods and Debugging Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab Documented GameMethods file and Corrected HighLow game: Uploaded by midnight of lab

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 18 Switch Statement (Contd.) And Introduction to

More information

Java Outline (Upto Exam 2)

Java Outline (Upto Exam 2) Java Outline (Upto Exam 2) Part 4 IF s (Branches) and Loops Chapter 12/13 (The if Statement) Hand in Program Assignment#1 (12 marks): Create a program called Ifs that will do the following: 1. Ask the

More information

COMP 110 Programming Exercise: Simulation of the Game of Craps

COMP 110 Programming Exercise: Simulation of the Game of Craps COMP 110 Programming Exercise: Simulation of the Game of Craps Craps is a game of chance played by rolling two dice for a series of rolls and placing bets on the outcomes. The background on probability,

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Tic Tac Toe Game! Day 8

Tic Tac Toe Game! Day 8 Tic Tac Toe Game! Day 8 Game Description We will be working on an implementation of a Tic-Tac-Toe Game. This is designed as a two-player game. As you get more involved in programming, you might learn how

More information

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Outline 12.1 Test-Driving the Craps Game Application 12.2 Random Number Generation 12.3 Using an enum in the Craps

More information

STUDENT LESSON A14 Boolean Algebra and Loop Boundaries

STUDENT LESSON A14 Boolean Algebra and Loop Boundaries STUDENT LESSON A14 Boolean Algebra and Loop Boundaries Java Curriculum for AP Computer Science, Student Lesson A14 1 STUDENT LESSON A14 Boolean Algebra and Loop Boundaries INTRODUCTION: Conditional loops

More information

Program #7: Let s Play Craps!

Program #7: Let s Play Craps! Program #7: Let s Play Craps! Due Date: July 18, 2000 1 The Problem Craps is a game played with a pair of dice. In the game of craps, the shooter (the player with the dice) rolls a pair of dice and the

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #29 Arrays in C (Refer Slide Time: 00:08) This session will learn about arrays in C. Now, what is the word array

More information

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

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to A PROGRAM IS A SEQUENCE of instructions that a computer can execute to perform some task. A simple enough idea, but for the computer to make any use of the instructions, they must be written in a form

More information

Singly linked lists in C.

Singly linked lists in C. Singly linked lists in C http://www.cprogramming.com/tutorial/c/lesson15.html By Alex Allain Linked lists are a way to store data with structures so that the programmer can automatically create a new place

More information

The for Loop. Lesson 11

The for Loop. Lesson 11 The for Loop Lesson 11 Have you ever played Tetris? You know that the game never truly ends. Blocks continue to fall one at a time, increasing in speed as you go up in levels, until the game breaks from

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Mat 2170 Week 9. Spring Mat 2170 Week 9. Objects and Classes. Week 9. Review. Random. Overloading. Craps. Clients. Packages. Randomness.

Mat 2170 Week 9. Spring Mat 2170 Week 9. Objects and Classes. Week 9. Review. Random. Overloading. Craps. Clients. Packages. Randomness. Spring 2014 Student Responsibilities Reading: Textbook, Sections 6.1 6.3 Attendance Recall: Writing Methods Decomposition: break a problem down into smaller subproblems Use methods whenever you can in

More information

Static Methods. Why use methods?

Static Methods. Why use methods? Static Methods A method is just a collection of code. They are also called functions or procedures. It provides a way to break a larger program up into smaller, reusable chunks. This also has the benefit

More information

BEGINNER PHP Table of Contents

BEGINNER PHP Table of Contents Table of Contents 4 5 6 7 8 9 0 Introduction Getting Setup Your first PHP webpage Working with text Talking to the user Comparison & If statements If & Else Cleaning up the game Remembering values Finishing

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 31 / 2014 Instructor: Michael Eckmann Today s Topics Comments and/or Questions? Pseudocode Programming exercise to determine projected homeruns How Java determines

More information

Student Responsibilities. Mat 2170 Week 9. Notes About Using Methods. Recall: Writing Methods. Chapter Six: Objects and Classes

Student Responsibilities. Mat 2170 Week 9. Notes About Using Methods. Recall: Writing Methods. Chapter Six: Objects and Classes Student Responsibilities Mat 2170 Week 9 Objects and Classes Spring 2014 Reading: Textbook, Sections 6.1 6.3 Lab 9 Attendance 1 2 Recall: Writing Methods 3 Decomposition: break a problem down into smaller

More information

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

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

Arrays. myints = new int[15];

Arrays. myints = new int[15]; Arrays As you know from COMP 202 (or equivalent), an array is a data structure that holds a set of elements that are of the same type. Each element in the array can be accessed or indexed by a unique number

More information

Basics of Programming with Python

Basics of Programming with Python Basics of Programming with Python A gentle guide to writing simple programs Robert Montante 1 Topics Part 3 Obtaining Python Interactive use Variables Programs in files Data types Decision-making Functions

More information

Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras

Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras Module 12B Lecture - 41 Brief introduction to C++ Hello, welcome

More information

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 17 March 31, 2016 CPSC 427, Lecture 17 1/29 Name Visibility Demo: Craps Game CPSC 427, Lecture 17 2/29 Name Visibility CPSC 427, Lecture

More information

C Pointers 2013 Author Riko H i

C Pointers 2013 Author Riko H i http:/cdorm.net/understanding C Pointers 2013 Author Riko H i Copyright 2013 CDorm.net All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form

More information

COMP 110/L Lecture 4. Kyle Dewey

COMP 110/L Lecture 4. Kyle Dewey COMP 110/L Lecture 4 Kyle Dewey Outline New types: long and double Reading in with Scanner Performing operations on them How they interact with each other and other types Exponentiation with Math.pow()

More information

do fifty two: Language Reference Manual

do fifty two: Language Reference Manual do fifty two: Language Reference Manual Sinclair Target Jayson Ng Josephine Tirtanata Yichi Liu Yunfei Wang 1. Introduction We propose a card game language targeted not at proficient programmers but at

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

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

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world! 6.S189 Homework 1 http://web.mit.edu/6.189/www/materials.html What to turn in Do the warm-up problems for Days 1 & 2 on the online tutor. Complete the problems below on your computer and get a checkoff

More information

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is

More information

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section:

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section: 7 Arrays 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

More information

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved. Functions In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create

More information

Civil Engineering Computation

Civil Engineering Computation Civil Engineering Computation First Steps in VBA Homework Evaluation 2 1 Homework Evaluation 3 Based on this rubric, you may resubmit Homework 1 and Homework 2 (along with today s homework) by next Monday

More information

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist In Handout 28, the Guide to Inductive Proofs, we outlined a number of specifc issues and concepts to be mindful about when

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Last Time: Rolling a Weighted Die

Last Time: Rolling a Weighted Die Last Time: Rolling a Weighted Die import math/rand func DieRoll() int { return rand.intn(6) + 1 Multiple Rolls When we run this program 100 times, we get the same outcome! func main() int { fmt.println(dieroll())

More information

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 I. Logic 101 In logic, a statement or proposition is a sentence that can either be true or false. A predicate is a sentence in

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

Function Call Stack and Activation Records

Function Call Stack and Activation Records 71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students

More information

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.

More information

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x );

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x ); Chapter 5 Methods Sections Pages Review Questions Programming Exercises 5.1 5.11 142 166 1 18 2 22 (evens), 30 Method Example 1. This is of a main() method using a another method, f. public class FirstMethod

More information

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) Late deadline: Friday, September 28, 11:59 pm Com S 227 Spring 2018 Assignment 2 200 points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm (Remember that Exam 1 is MONDAY, October 1.) General

More information

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

SPRITES Moving Two At the Same Using Game State

SPRITES Moving Two At the Same Using Game State If you recall our collision detection lesson, you ll likely remember that you couldn t move both sprites at the same time unless you hit a movement key for each at exactly the same time. Why was that?

More information

CONTENTS: Arrays Strings. COMP-202 Unit 5: Loops in Practice

CONTENTS: Arrays Strings. COMP-202 Unit 5: Loops in Practice CONTENTS: Arrays Strings COMP-202 Unit 5: Loops in Practice Computing the mean of several numbers Suppose we want to write a program which asks the user to enter several numbers and then computes the average

More information

Programming assignment A

Programming assignment A Programming assignment A ASCII Minesweeper Official release on Feb 14 th at 1pm (Document may change before then without notice) Due 5pm Feb 25 th Minesweeper is computer game that was first written in

More information

Stepwise Refinement. Lecture 12 COP 3014 Spring February 2, 2017

Stepwise Refinement. Lecture 12 COP 3014 Spring February 2, 2017 Stepwise Refinement Lecture 12 COP 3014 Spring 2017 February 2, 2017 Top-Down Stepwise Refinement Top down stepwise refinement is a useful problem-solving technique that is good for coming up with an algorithm.

More information

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing

More information

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

Note. The above image and many others are courtesy of   - this is a wonderful resource for designing circuits. Robotics and Electronics Unit 2. Arduino Objectives. Students will understand the basic characteristics of an Arduino Uno microcontroller. understand the basic structure of an Arduino program. know how

More information

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

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want

More information

static String usersname; public static int numberofplayers; private static double velocity, time;

static String usersname; public static int numberofplayers; private static double velocity, time; A class can include other things besides subroutines. In particular, it can also include variable declarations. Of course, you can declare variables inside subroutines. Those are called local variables.

More information

do fifty-two: An Introductory Programming Language

do fifty-two: An Introductory Programming Language do fifty-two: An Introductory Programming Language Sinclair Target Yichi Liu Josephine Tirtanata Jayson K Ng Yunfei Wang September 23, 2014 Project Group Sinclair Target / wst2109 / Language Guru Yichi

More information

CMPSCI 187 / Spring 2015 Hangman

CMPSCI 187 / Spring 2015 Hangman CMPSCI 187 / Spring 2015 Hangman Due on February 12, 2015, 8:30 a.m. Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1 CMPSCI 187 / Spring 2015 Hangman Contents Overview

More information

Introduction to Java Programs for Packet #4: Classes and Objects

Introduction to Java Programs for Packet #4: Classes and Objects Introduction to Java Programs for Packet #4: Classes and Objects Note. All of these programs involve writing and using more than one class file. 1. Copy the Box class and compile it. But you won t be able

More information

Lab 1 Implementing a Simon Says Game

Lab 1 Implementing a Simon Says Game ECE2049 Embedded Computing in Engineering Design Lab 1 Implementing a Simon Says Game In the late 1970s and early 1980s, one of the first and most popular electronic games was Simon by Milton Bradley.

More information

Introduction to Computer Science Unit 3. Programs

Introduction to Computer Science Unit 3. Programs Introduction to Computer Science Unit 3. Programs This section must be updated to work with repl.it Programs 1 to 4 require you to use the mod, %, operator. 1. Let the user enter an integer. Your program

More information

MA 1128: Lecture 02 1/22/2018

MA 1128: Lecture 02 1/22/2018 MA 1128: Lecture 02 1/22/2018 Exponents Scientific Notation 1 Exponents Exponents are used to indicate how many copies of a number are to be multiplied together. For example, I like to deal with the signs

More information

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

Lab 1 Implementing a Simon Says Game

Lab 1 Implementing a Simon Says Game ECE2049 Embedded Computing in Engineering Design Lab 1 Implementing a Simon Says Game In the late 1970s and early 1980s, one of the first and most popular electronic games was Simon by Milton Bradley.

More information

int j = 0, sum = 0; for (j = 3; j <= 79; j++) { sum = sum + j; System.out.println(sum); //Show the progress as we iterate thru the loop.

int j = 0, sum = 0; for (j = 3; j <= 79; j++) { sum = sum + j; System.out.println(sum); //Show the progress as we iterate thru the loop. 11-1 One of the most important structures in Java is the -loop. A loop is basically a block of code that is with certain rules about how to start and how to end the process. Suppose we want to sum up all

More information

Part II Composition of Functions

Part II Composition of Functions Part II Composition of Functions The big idea in this part of the book is deceptively simple. It s that we can take the value returned by one function and use it as an argument to another function. By

More information

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to: Get JAVA To compile programs you need the JDK (Java Development Kit). To RUN programs you need the JRE (Java Runtime Environment). This download will get BOTH of them, so that you will be able to both

More information

How To Think Like A Computer Scientist, chapter 3; chapter 6, sections

How To Think Like A Computer Scientist, chapter 3; chapter 6, sections 6.189 Day 3 Today there are no written exercises. Turn in your code tomorrow, stapled together, with your name and the file name in comments at the top as detailed in the Day 1 exercises. Readings How

More information

Out for Shopping-Understanding Linear Data Structures English

Out for Shopping-Understanding Linear Data Structures English Out for Shopping-Understanding Linear Data Structures English [MUSIC PLAYING] [MUSIC PLAYING] TANZEELA ALI: Hi, it's Tanzeela Ali. I'm a software engineer, and also a teacher at Superior University, which

More information

COMP-202 More Complex OOP

COMP-202 More Complex OOP COMP-202 More Complex OOP Defining your own types: Remember that we can define our own types/classes. These classes are objects and have attributes and behaviors You create an object or an instance of

More information

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

More information

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module

More information

Arrays in C++ Instructor: Andy Abreu

Arrays in C++ Instructor: Andy Abreu Arrays in C++ Instructor: Andy Abreu Reason behind the idea When we are programming, often we have to process a large amount of information. We can do so by creating a lot of variables to keep track of

More information

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1 ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1 Due to CMS by Tuesday, February 14. Social networking has caused a return of the dot-com madness. You want in on the easy money, so you have decided to make

More information

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently. The Science of Computing I Lesson 4: Introduction to Data Structures Living with Cyber Pillar: Data Structures The need for data structures The algorithms we design to solve problems rarely do so without

More information

Programming Lab 1 (JS Hwk 3) Due Thursday, April 28

Programming Lab 1 (JS Hwk 3) Due Thursday, April 28 Programming Lab 1 (JS Hwk 3) Due Thursday, April 28 Lab You may work with partners for these problems. Make sure you put BOTH names on the problems. Create a folder named JSLab3, and place all of the web

More information

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

More information

COMP 250 Winter generic types, doubly linked lists Jan. 28, 2016

COMP 250 Winter generic types, doubly linked lists Jan. 28, 2016 COMP 250 Winter 2016 5 generic types, doubly linked lists Jan. 28, 2016 Java generics In our discussion of linked lists, we concentrated on how to add or remove a node from the front or back of a list.

More information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 02 Lecture - 45 Memoization

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 02 Lecture - 45 Memoization Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Module 02 Lecture - 45 Memoization Let us continue our discussion of inductive definitions. (Refer Slide Time: 00:05)

More information

PROFESSOR: Well, now that we've given you some power to make independent local state and to model objects,

PROFESSOR: Well, now that we've given you some power to make independent local state and to model objects, MITOCW Lecture 5B PROFESSOR: Well, now that we've given you some power to make independent local state and to model objects, I thought we'd do a bit of programming of a very complicated kind, just to illustrate

More information

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM Let s get some practice creating programs that repeat commands inside of a loop in order to accomplish a particular task. You may

More information

LAB: WHILE LOOPS IN C++

LAB: WHILE LOOPS IN C++ LAB: WHILE LOOPS IN C++ MODULE 2 JEFFREY A. STONE and TRICIA K. CLARK COPYRIGHT 2014 VERSION 4.0 PALMS MODULE 2 LAB: WHILE LOOPS IN C++ 2 Introduction This lab will provide students with an introduction

More information

Control, Quick Overview. Selection. Selection 7/6/2017. Chapter 2. Control

Control, Quick Overview. Selection. Selection 7/6/2017. Chapter 2. Control Chapter 2 Control, Quick Overview Control Selection Selection Selection is how programs make choices, and it is the process of making choices that provides a lot of the power of computing 1 Python if statement

More information

Game keystrokes or Calculates how fast and moves a cartoon Joystick movements how far to move a cartoon figure on screen figure on screen

Game keystrokes or Calculates how fast and moves a cartoon Joystick movements how far to move a cartoon figure on screen figure on screen Computer Programming Computers can t do anything without being told what to do. To make the computer do something useful, you must give it instructions. You can give a computer instructions in two ways:

More information

Haskell Refresher Informatics 2D

Haskell Refresher Informatics 2D Haskell Purely functional! : Everything is a function Haskell Refresher Informatics 2D Kobby. K.A. Nuamah 30 January 2015 Main topics: Recursion Currying Higher-order functions List processing functions

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle Boggle If you are not familiar with the game Boggle, the game is played with 16 dice that have letters on all faces. The dice are randomly deposited into a four-by-four grid so that the players see the

More information

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

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

Core Competency DOO (Design Object-Oriented)

Core Competency DOO (Design Object-Oriented) Here is the documentation for the rest of the semester. This document includes specification of the remaining Core Competencies, specifications for the final two Core Labs, and specifications for a number

More information

How to approach a computational problem

How to approach a computational problem How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to

More information

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18 Assignment Lecture 9 Logical Operations Formatted Print Printf Increment and decrement Read through 3.9, 3.10 Read 4.1. 4.2, 4.3 Go through checkpoint exercise 4.1 Logical Operations - Motivation Logical

More information

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

COMP-202: Foundations of Programming. Lecture 6: Conditionals Jackie Cheung, Winter 2016

COMP-202: Foundations of Programming. Lecture 6: Conditionals Jackie Cheung, Winter 2016 COMP-202: Foundations of Programming Lecture 6: Conditionals Jackie Cheung, Winter 2016 This Lecture Finish data types and order of operations Conditionals 2 Review Questions What is the difference between

More information

Initial Coding Guidelines

Initial Coding Guidelines Initial Coding Guidelines ITK 168 (Lim) This handout specifies coding guidelines for programs in ITK 168. You are expected to follow these guidelines precisely for all lecture programs, and for lab programs.

More information

Functions and Recursion

Functions and Recursion Functions and Recursion 1 Outline Introduction Program Components in C++ Math Library Functions Functions Function Definitions Function Prototypes Header Files Random Number Generation Example: A Game

More information

Linked Lists. What is a Linked List?

Linked Lists. What is a Linked List? Linked Lists Along with arrays, linked lists form the basis for pretty much every other data stucture out there. This makes learning and understand linked lists very important. They are also usually the

More information

EAS230: Programming for Engineers Lab 1 Fall 2004

EAS230: Programming for Engineers Lab 1 Fall 2004 Lab1: Introduction Visual C++ Objective The objective of this lab is to teach students: To work with the Microsoft Visual C++ 6.0 environment (referred to as VC++). C++ program structure and basic input

More information