IT115: Introduction to Java Programming 1. IT115: Introduction to Java Programming. Tic Tac Toe Application. Trina VanderLouw

Size: px
Start display at page:

Download "IT115: Introduction to Java Programming 1. IT115: Introduction to Java Programming. Tic Tac Toe Application. Trina VanderLouw"

Transcription

1 IT115: Introduction to Java Programming 1 IT115: Introduction to Java Programming Tic Tac Toe Application Trina VanderLouw Professor Derek Peterson Colorado Technical University Online October 28, 2011 Highlights: Java, Building Applications, Creating Javadocs, Importing Libraries Programs Used: NetBeans IDE, CTU Virtual Campus Instructor Feedback: Thanks for letting me show-off your code during the chat. You did a superb job on the code. It is nicely formatted, you do that well which makes it easy to follow. Instructor Recommendation: I had the pleasure of having Trina in my introduction to java programming course. She was an exemplary student and took control of her learning. I have taught this course for CTU Online for more than 3 years and she stands with a very short list of people who truly were successful. As a part-time adjunct professor who works full-time as an IT Director/Vice President managing and hiring programmers, given the opportunity to recommend and/or hire Trina for an IT position; I would not hesitate. She displayed in the 11 weeks I worked with her the aptitude and capability to be successful. Final Grade: A

2 IT115: Introduction to Java Programming 2 Tic Tac Toe Game Code and Libraries in NetBeans IDE UML Diagrams

3 IT115: Introduction to Java Programming ACTIVITY DIAGRAMS Players move inside of the play method activity repeats until win = true then the play is over

4 IT115: Introduction to Java Programming 4 Main Class File

5 IT115: Introduction to Java Programming 5 Java File for the Public Classes

6 IT115: Introduction to Java Programming 6 Java File for Tic Tac Toe Board

7 IT115: Introduction to Java Programming 7 /* * Trina VanderLouw * October 20, 2011 * IT115: Java Programming * Professor Derek Peterson import java.util.scanner; * This reusable class is for a Tic Tac Toe Game - It constructs a game board * with three columns and three rows and sets up a Player X and a Player O - * Each player takes turns and when one person wins it will display a message - * The counts for the winners are tallied and stats are displayed at the end * of the game - If there is a tie the program will allow one more game to be * played for a tiebreaker. TrinaV public class TicTacToeGame // Creates new game board with 9 set values placed in the array private boardpiece[][] board = new boardpiece(), new boardpiece(), new boardpiece(), new boardpiece(), new boardpiece(), new boardpiece(), new boardpiece(), new boardpiece(), new boardpiece(); private int count = 0; // Counts the amount of turns - determines a draw private boolean win = false; // Sets win to false so a move can be made private char turn = 'X'; // Initializes turn to X so player X goes first private int xwon = 0; // Tallies how many games are won by Player X private int owon = 0; // Tallies how many games are won by Player O private int xlost = 0; // Tallies how many games are lost by Player X private int olost = 0; // Tallies how many games are lost by Player O * This public boolean allows the value to be passed to the test method * and determines whether or not the game will be restarted in the do_while * loop in the main method. public boolean again; // Returns true or false in the main method Scanner input = new Scanner(System.in); * This constructor is empty and allows for a new instance to be created public TicTacToeGame()

8 IT115: Introduction to Java Programming 8 * This method welcomes the players to the game public void displaywelcome() System.out.println("Welcome to Tic Tac Toe!"); System.out.print("Good Luck!!\n"); * This method checks to see if the game has been won and if not calls the * move method which initiates the next player's turn. public void play() // If the game has not been won, the next move will be initiated while (!win) // Calls the move method to start the next turn move(); // Ends play method * This method displays the current game board - Each place on the board * will have either an _X_, _O_, or. public void displayboard() // Runs a loop to display all the rows for (int i = 0; i < 3; i++) // Runs a loop to display all the columns for (int j = 0; j < 3; j++) // Prints out each space with the current value stored there System.out.print(board[i][j].piece); System.out.println(); // Ends displayboard method * This method tells the players whose turn it is and asks for their move - * the move entered will be checked using the checkmove method and if valid * will be entered onto the board - The board gets displayed and the program * checks for a winning move - If the game is not over the turn will switch * to the next player.

9 IT115: Introduction to Java Programming 9 public void move() int move = 0; // Stores the game board square the player selects String valid = " "; // Set to blank so the choice can be validated // Displays whose turn and prompts for selection System.out.print("\nPlayer " + turn + ", it's your turn!\n" + "Select a move (1-9): "); // Starts a loop for the selection and vaildation do // Stores the move so it can be passed to the checkmove method move = input.nextint(); // Sets valid to the return value in checkmove valid = checkmove(move); // If the player enters a number that is not between 1 and 9 they // will get an error prompting them to enter another number if (valid.equals("error:1")) System.out.print("Please enter a space between 1-9: "); // If the player chooses a space that is already taken they will // receive an error message prompting them to select a different one if (valid.equals("error:2")) System.out.print("Sorry, that space is not available.\n" + "Please enter another space: "); // Continues the validation loop until it returns OK while (!valid.equals("ok")); // Increments number of turns taken so game will stop after 9 turns count++; // Enters the turn into the proper place and marks the space as used board[(move - 1) / 3][(move - 1) % 3].piece = "_" + turn + "_ "; board[(move - 1) / 3][(move - 1) % 3].player = turn; board[(move - 1) / 3][(move - 1) % 3].used = true; // Calls the displayboard method to show the users the current board displayboard(); // Checks to be sure game is not over and then checks for a winning

10 IT115: Introduction to Java Programming 10 // move by calling the checkwin method if (count <= 9) // Checks to see if there are three in a row, column, or diagonal // and ends the game if there is a winning move checkwin(move); // Switches the players' turns so they alternate if (turn == 'X') turn = 'O'; else turn = 'X'; // Ends move method * This method will validate the entry by the player - If the number entered * is not between 1 and 9 it will return an Error 1 and if the space is * already taken it will return an Error 2, otherwise the number will be * validated so the move can be marked on the board. move public String checkmove(int move) // Sets validator to integers 1 through 9 or else returns Error 1 if (move < 1 move > 9) return "Error:1"; // Sets validator to check for empty spot or else returns Error 2 if (board[(move - 1) / 3][(move - 1) % 3].used) return "Error:2"; // Returns OK if value entered is validated return "OK"; // Ends checkmove * This method checks for a winning move - if there are three across, three * down, or three diagonal of the same character the current game will end * and a congratulations message will be displayed to the players - At the

11 IT115: Introduction to Java Programming 11 * end of the game the stats will be updated by players whether they won * or lost - If the game ends in a draw no stats will be incremented. move public void checkwin(int move) // Starts loop to check for winning combination of moves in rows for (int i = 0; i < 3; i++) // Checks to see if each column in the row is used and if so if // each one has the same value stored if ((board[i][0].used && board[i][1].used && board[i][2].used) && (board[i][0].player == board[i][1].player) && (board[i][1].player == board[i][2].player)) System.out.printf("\nYou WIN!!\nCongrats, Player " +turn+ "!"); // Increments the winning and losing scores if (turn == 'X') xwon++; olost++; else owon++; xlost++; // Sets win to true so the game ends win = true; return; // Starts loop to check for winning combination of moves in columns for (int j = 0; j < 3; j++) // Checks to see if each row in the column is used and if so if // each one has the same value stored if ((board[0][j].used && board[1][j].used && board[2][j].used) && (board[0][j].player == board[1][j].player) && (board[1][j].player == board[2][j].player)) System.out.printf("\nYou WIN!!\nCongrats, Player " +turn+ "!"); // Increments the winning and losing scores if (turn == 'X') xwon++; olost++;

12 IT115: Introduction to Java Programming 12 else owon++; xlost++; // Sets win to true to the game ends win = true; return; // Checks for winning combination of moves in diagonal [0][0] to [2][2] if ((board[0][0].used && board[1][1].used && board[2][2].used) && (board[0][0].player == board[1][1].player) && (board[1][1].player == board[2][2].player)) System.out.printf("\nYou WIN!!\nCongrats, Player " + turn + "!"); // Increments the winning and losing scores if (turn == 'X') xwon++; olost++; if (turn == 'O') owon++; xlost++; // Sets win to true so the game ends win = true; return; // Checks for winning combination of moves in diagonal [2][0] to [0][2] if ((board[2][0].used && board[1][1].used && board[0][2].used) && (board[2][0].player == board[1][1].player) && (board[1][1].player == board[0][2].player)) System.out.printf("\nYou WIN!!\nCongrats, Player " + turn + "!"); // Increments winning and losing scores if (turn == 'X') xwon++; olost++;

13 IT115: Introduction to Java Programming 13 if (turn == 'O') owon++; xlost++; // Sets win to true so the game ends win = true; return; // Checks to see if the count is at the maximum number of moves and // then displays message that the game was a draw with no winner if (count == 9) System.out.print("\nDRAW\nSorry, there is no winner this time!"); // Sets win to true so the game ends win = true; return; * This method initializes all the attributes so the game can continue with * a new game board - The turn is not initialized to X as it is in the first * game so that the player who lost will get the chance to start first on * the new board. public void init() // Starts a loop to initialize each piece on the game board as empty // Without resetting these a new game would think the spaces were used for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) board[i][j] = new boardpiece(); // Sets win to false so game can start over by staring another move win = false; // Resets counter to 0 so the moves can increment again to 9 // Without resetting this the game would think it is a draw

14 IT115: Introduction to Java Programming 14 count = 0; * This method allows the players to decide if they would like to play a * new game board - It returns the attribute 'again' to the main method so * the loop can continue or end depending on the value stored. public boolean again() // Prompts user to enter 1 for yes and 2 for no to restart new game System.out.print("\n\nWould you like to play again?\n" + "Enter 1 = yes, 2 = no: "); // Stores value of number entered int newgame = input.nextint(); // If user wants to play again the board will be initialized and the // value will return true to the main method if (newgame == 1) again = true; init(); return again; // If the player did not enter 1 the value will be set false and the // loop in the main method will end again = false; return again; * This method displays the results of the games played - It shows a total * for the number of games won and lost by each player - If there is a tie * it will give the players a chance to play one more game for a tiebreaker. public void stats() // Prints out the results of the players' stats System.out.printf("\nPLAYER X Won: %d Lost: %d", xwon, xlost); System.out.printf("\nPLAYER 0 Won: %d Lost: %d\n", owon, olost); // If X won a congratulations message will be printed if (xwon > owon) System.out.println("\nCongratulations, Player X!");

15 IT115: Introduction to Java Programming 15 // If O won a congratulations message will be printed if (xwon < owon) System.out.println("\nCongratulations, Player O!"); // If the games won were tied it will prompt for a tiebreaker if (xwon == owon) System.out.println("\nX and O Tied!\n" + "Would you like to play a tiebreaker?\n" + "Enter 1 = yes, 2 = no: "); int tiebreaker = input.nextint(); // If the players want one more game the board will be initialized // and the play method will start once to determine the winner if (tiebreaker == 1) init(); play(); // Ends stats method * This method displays a good-bye message to the user. public void displaygoodbye() // Calls the stats method to display stats of all games won and lost stats(); System.out.print("\n\nThanks for playing.\ngood-bye!\n"); // Ends displaygoodbye method

16 IT115: Introduction to Java Programming 16

Question 1 [20 points]

Question 1 [20 points] Question 1 [20 points] a) Write the following mathematical expression in Java. c=math.sqrt(math.pow(a,2)+math.pow(b,2)- 2*a*b*Math.cos(gamma)); b) Write the following Java expression in mathematical notation.

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

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

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable Today in CS161 Lecture #12 Arrays Learning about arrays Being able to store more than one item using a variable Examples Tic Tac Toe board as an array Graphical User interaction for the tic tac toe program

More information

RANDOM NUMBER GAME PROJECT

RANDOM NUMBER GAME PROJECT Random Number Game RANDOM NUMBER GAME - Now it is time to put all your new knowledge to the test. You are going to build a random number game. - The game needs to generate a random number between 1 and

More information

Lesson 10: Quiz #1 and Getting User Input (W03D2)

Lesson 10: Quiz #1 and Getting User Input (W03D2) Lesson 10: Quiz #1 and Getting User Input (W03D2) Balboa High School Michael Ferraro September 1, 2015 1 / 13 Do Now: Prep GitHub Repo for PS #1 You ll need to submit the 5.2 solution on the paper form

More information

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class For this assignment we will be developing a text-based Tic Tac Toe game 1. The key to this assignment is that we re going

More information

CS1 Studio Project: Connect Four

CS1 Studio Project: Connect Four CS1 Studio Project: Connect Four Due date: November 8, 2006 In this project, we will implementing a GUI version of the two-player game Connect Four. The goal of this project is to give you experience in

More information

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks: Mid Term Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Student Name: Total Marks: 50 Obtained Marks: Instructions: Do not open this exam booklet until you

More information

while (/* array size less than 1*/){ System.out.print("Number of students is invalid. Enter" + "number of students: "); /* read array size again */

while (/* array size less than 1*/){ System.out.print(Number of students is invalid. Enter + number of students: ); /* read array size again */ import java.util.scanner; public class CourseManager1 { public static void main(string[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter number of students: "); /* read the number

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

AP Computer Science Lists The Array type

AP Computer Science Lists The Array type AP Computer Science Lists There are two types of Lists in Java that are commonly used: Arrays and ArrayLists. Both types of list structures allow a user to store ordered collections of data, but there

More information

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz Senet Language Reference Manual 26 th October 2015 Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz 1. Overview Past projects for Programming Languages and Translators have

More information

Introduction to Computer Programming

Introduction to Computer Programming Introduction to Computer Programming Lecture #7 - Conditional Loops The Problem with Counting Loops Many jobs involving the computer require repetition, and that this can be implemented using loops. Counting

More information

D - Tic Tac Toe. Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9

D - Tic Tac Toe. Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9 D - Tic Tac Toe Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9 INTRODUCTION Let's use our 9 sparkles to build a tic tac toe game! Step 1 Assemble the Robot

More information

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 3- Control Statements: Part I Objectives: To use the if and if...else selection statements to choose among alternative actions. To use the

More information

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class:

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class: More on Classes tostring One special method in Java is the tostring method. The method (regardless of which class it s added to) has the following prototype: public String tostring(); The job of this method

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018 Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018 Due: Tuesday, September 18, 11:59 pm Collaboration Policy: Level 1 (review full policy for details) Group Policy: Individual This lab will give you experience

More information

Global Gomoku Lab 4 in D0010E

Global Gomoku Lab 4 in D0010E Luleå University of Technology February 20, 2012 Computer Science Håkan Jonsson Global Gomoku Lab 4 in D0010E 1 Introduction Modern forms of communication are more and more carried out over the Internet,

More information

Lab 4 Due April 18 th

Lab 4 Due April 18 th Lab 4 Due April 18 th (100 pts) You may work with a partner if you want. Turn in one version with 2 names on it. Do not forget your partner s name. Or work alone. Your choice. Problem 1 (10 pts): Create

More information

Declaring and ini,alizing 2D arrays

Declaring and ini,alizing 2D arrays Declaring and ini,alizing 2D arrays 4 2D Arrays (Savitch, Chapter 7.5) TOPICS Multidimensional Arrays 2D Array Allocation 2D Array Initialization TicTacToe Game // se2ng up a 2D array final int M=3, N=4;

More information

BOREDGAMES Language for Board Games

BOREDGAMES Language for Board Games BOREDGAMES Language for Board Games I. Team: Rujuta Karkhanis (rnk2112) Brandon Kessler (bpk2107) Kristen Wise (kew2132) II. Language Description: BoredGames is a language designed for easy implementation

More information

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 2- Arithmetic and Decision Making: Equality and Relational Operators Objectives: To use arithmetic operators. The precedence of arithmetic

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

Assignment 2.4: Loops

Assignment 2.4: Loops Writing Programs that Use the Terminal 0. Writing to the Terminal Assignment 2.4: Loops In this project, we will be sending our answers to the terminal for the user to see. To write numbers and text to

More information

ECE15: Lab #4. Problem 1. University of California San Diego

ECE15: Lab #4. Problem 1. University of California San Diego University of California San Diego ECE15: Lab #4 This lab is a cumulative wrap-up assignment for the entire course. As such, it relates to the material covered in Lecture Units 1 5 and 7 9 in class. Here

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

General Certificate of Education Advanced Subsidiary Examination June 2010

General Certificate of Education Advanced Subsidiary Examination June 2010 General Certificate of Education Advanced Subsidiary Examination June 2010 Computing COMP1/PM/JA Unit 1 Problem Solving, Programming, Data Representation and Practical Exercise Preliminary Material A copy

More information

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING INPUT AND OUTPUT Input devices Keyboard Mouse Hard drive Network Digital camera Microphone Output devices.

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

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 000 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

Object Oriented Programming. Java-Lecture 1

Object Oriented Programming. Java-Lecture 1 Object Oriented Programming Java-Lecture 1 Standard output System.out is known as the standard output object Methods to display text onto the standard output System.out.print prints text onto the screen

More information

Learning objec-ves. Declaring and ini-alizing 2D arrays. Prin-ng 2D arrays. Using 2D arrays Decomposi-on of a solu-on into objects and methods

Learning objec-ves. Declaring and ini-alizing 2D arrays. Prin-ng 2D arrays. Using 2D arrays Decomposi-on of a solu-on into objects and methods Learning objec-ves 2D Arrays (Savitch, Chapter 7.5) TOPICS Using 2D arrays Decomposi-on of a solu-on into objects and methods Multidimensional Arrays 2D Array Allocation 2D Array Initialization TicTacToe

More information

Midterm Examination (MTA)

Midterm Examination (MTA) M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and

More information

CS 211: Existing Classes in the Java Library

CS 211: Existing Classes in the Java Library CS 211: Existing Classes in the Java Library Chris Kauffman Week 3-2 Logisitics Logistics P1 Due tonight: Questions? Late policy? Lab 3 Exercises Thu/Fri Play with Scanner Introduce it today Goals Class

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

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016 First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm

More information

CS100M November 30, 2000

CS100M November 30, 2000 CS00M November 30, 2000 Makeup Solutions 7:30 PM 9:30 PM (Print last name, first name, middle initial/name) (Student ID) Statement of integrity: I did not, and will not, break the rules of academic integrity

More information

CS159 Midterm #1 Review

CS159 Midterm #1 Review Name: CS159 Midterm #1 Review 1. Choose the best answer for each of the following multiple choice questions. (a) What is the effect of declaring a class member to be static? It means that the member cannot

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

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case

More information

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

More information

CAT.woa/wa/assignments/eclipse

CAT.woa/wa/assignments/eclipse King Saud University College of Computer & Information Science CSC111 Lab10 Arrays II All Sections ------------------------------------------------------------------- Instructions Web-CAT submission URL:

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Gaddis_516907_Java 4/10/07 2:10 PM Page 51 Chapter 6 Lab Classes and Objects Objectives Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value

More information

ios Tic Tac Toe Game John Robinson at Rowan University

ios Tic Tac Toe Game John Robinson at Rowan University ios Tic Tac Toe Game John Robinson at Rowan University Agenda Day 3 Introduction to Swift and Xcode Creating the Tic Tac Toe GUI Lunch Break Writing the Tic Tac Toe Game Code RAMP Wrap up Process for Developing

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA

More information

Basic Problem solving Techniques Top Down stepwise refinement If & if else.. While.. Counter controlled and sentinel controlled repetition Usage of

Basic Problem solving Techniques Top Down stepwise refinement If & if else.. While.. Counter controlled and sentinel controlled repetition Usage of Basic Problem solving Techniques Top Down stepwise refinement If & if.. While.. Counter controlled and sentinel controlled repetition Usage of Assignment increment & decrement operators 1 ECE 161 WEEK

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Lab Objectives Chapter 6 Lab Classes and Objects Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value Be able to write instance methods that

More information

Handout 4 Conditionals. Boolean Expressions.

Handout 4 Conditionals. Boolean Expressions. Handout 4 cs180 - Programming Fundamentals Fall 17 Page 1 of 8 Handout 4 Conditionals. Boolean Expressions. Example Problem. Write a program that will calculate and print bills for the city power company.

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

Controls Structure for Repetition

Controls Structure for Repetition Controls Structure for Repetition So far we have looked at the if statement, a control structure that allows us to execute different pieces of code based on certain conditions. However, the true power

More information

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS Day Class Midterm Exam Dr. R. Khedri DURATION : 50 minutes McMaster University Midterm Exam (CAS) October 29, 2012 Please CLEARLY print: NAME:

More information

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Web-CAT submission URL:  CAT.woa/wa/assignments/eclipse King Saud University College of Computer & Information Science CSC111 Lab10 Arrays II All Sections ------------------------------------------------------------------- Instructions Web-CAT submission URL:

More information

Lecture 10: for, do, and switch

Lecture 10: for, do, and switch Lecture 10: for, do, and switch Jiajia Liu Recall the while Loop The while loop has the general form while ( boolean condition ) { The while loop is like a repeated if statement. It will repeat the statements

More information

CPSC 217 Assignment 3

CPSC 217 Assignment 3 CPSC 217 Assignment 3 Due: Monday November 23, 2015 at 12:00 noon Weight: 7% Sample Solution Length: 135 lines, including some comments (not including the provided code) Individual Work: All assignments

More information

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do: Project MindNumber Collaboration: Solo. Complete this project by yourself with optional help from section leaders. Do not work with anyone else, do not copy any code directly, do not copy code indirectly

More information

CSE 1223: Exam II Autumn 2016

CSE 1223: Exam II Autumn 2016 CSE 1223: Exam II Autumn 2016 Name: Instructions: Do not open the exam before you are told to begin. This exam is closed book, closed notes. You may not use any calculators or any other kind of computing

More information

LAB 5: SELECTION STATEMENTS

LAB 5: SELECTION STATEMENTS Statement Purpose: The purpose of this lab is to familiarize students with Conditional statements and explain how to control the sequence of statement execution, depending on the value of an expression

More information

Introduction to Computer Science Unit 4B. Programs: Classes and Objects

Introduction to Computer Science Unit 4B. Programs: Classes and Objects Introduction to Computer Science Unit 4B. Programs: Classes and Objects This section must be updated to work with repl.it 1. Copy the Box class and compile it. But you won t be able to run it because it

More information

CSC 108. Prof. Yue-Ling Wong. Lab 6: Tic-tac-toe Game

CSC 108. Prof. Yue-Ling Wong. Lab 6: Tic-tac-toe Game CSC 108 Spring 2010 Prof Yue-Ling Wong Lab 6: Tic-tac-toe Game 1 What you have for Lab06 so far two 2-D arrays to model the tic-tac-toe game board: board: to store the movieclip instance names of the cells

More information

2.8. Decision Making: Equality and Relational Operators

2.8. Decision Making: Equality and Relational Operators Page 1 of 6 [Page 56] 2.8. Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. This section introduces a simple version of Java's if statement

More information

Project 1 - Battleship Game

Project 1 - Battleship Game Project 1 - Battleship Game Minimal Submission Due: Friday, December 22 th, 2006 Revision History Final Project Due: Sunday, January 21 th, 2007 Dec 7th, 2006, v1.0: Initial revision for faculty review.

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

Example Program. public class ComputeArea {

Example Program. public class ComputeArea { COMMENTS While most people think of computer programs as a tool for telling computers what to do, programs are actually much more than that. Computer programs are written in human readable language for

More information

Control Statements: Part 1

Control Statements: Part 1 4 Let s all move one place on. Lewis Carroll Control Statements: Part 1 The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert Frost All

More information

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function Due: Mar13 (Note that this is a 2-week lab) This lab must be done using paired partners. You should choose a different partner

More information

Functionally Modular. Self-Review Questions

Functionally Modular. Self-Review Questions Functionally Modular 5 Self-Review Questions Self-review 5.1 Which names are local, which are global and which are built-in in the following code fragment? Global names: Built-in names: space_invaders

More information

Tic-Tac-Toe. By the time you are done with this activity, you and your team should be able to:

Tic-Tac-Toe. By the time you are done with this activity, you and your team should be able to: Tic-Tac-Toe Team Name: Manager: Recorder: Presenter: Analyst: This is a Process Oriented Guided Inquiry Learning (POGIL) activity. You and your team will examine a working program. A series of questions

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

Arrays. Eng. Mohammed Abdualal

Arrays. Eng. Mohammed Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays

More information

Session 8.2. Finding Winners Using Arrays

Session 8.2. Finding Winners Using Arrays 1 Session 8.2 Finding Winners Using Arrays Chapter 8.2: Finding Winners Using Arrays 2 Session Overview Find out how the C# language makes it easy to create an array that contains multiple values of a

More information

Last Class. While loops Infinite loops Loop counters Iterations

Last Class. While loops Infinite loops Loop counters Iterations Last Class While loops Infinite loops Loop counters Iterations public class January31{ public static void main(string[] args) { while (true) { forloops(); if (checkclassunderstands() ) { break; } teacharrays();

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function Due: Mar25 (Note that this is a 2-week lab) This lab must be done using paired partners. You should choose a different partner

More information

Loops. CSE 114, Computer Science 1 Stony Brook University

Loops. CSE 114, Computer Science 1 Stony Brook University Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?

More information

Lab Exercise 1. Objectives: Part 1. Introduction

Lab Exercise 1. Objectives: Part 1. Introduction Objectives: king Saud University College of Computer &Information Science CSC111 Lab Object II All Sections - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

More information

Introduction to Java Applications

Introduction to Java Applications 2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use

More information

4. Java Project Design, Input Methods

4. Java Project Design, Input Methods 4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java

More information

CSIS-120 Final Exam Fall 2015 Name:

CSIS-120 Final Exam Fall 2015 Name: 1. Which line of code creates a Player object called player1 using the default constructor a) Player player1; b) Player player1 = new Player (); c) Player1 Player(); d) Player player1 = new Player ; e)

More information

CS 142 Style Guide Grading and Details

CS 142 Style Guide Grading and Details CS 142 Style Guide Grading and Details In the English language, there are many different ways to convey a message or idea: some ways are acceptable, whereas others are not. Similarly, there are acceptable

More information

CSE120 Wi18 Final Review

CSE120 Wi18 Final Review CSE120 Wi18 Final Review Practice Question Solutions 1. True or false? Looping is necessary for complex programs. Briefly explain. False. Many loops can be explicitly written out as individual statements

More information

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2 Java Foundations Introduction to Program Design and Data Structures 4th Edition Lewis TEST BANK Full download at : https://testbankreal.com/download/java-foundations-introduction-toprogram-design-and-data-structures-4th-edition-lewis-test-bank/

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

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: October 18, 2015 Student Name: Student ID: Total Marks: 45 Obtained Marks: Instructions: Do not open this

More information

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions: Name: New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case Instructions: KEEP TEST BOOKLET CLOSED UNTIL YOU ARE INSTRUCTED TO BEGIN. This exam is double sided (front

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

Programming Project 1

Programming Project 1 Programming Project 1 Handout 6 CSCI 134: Fall, 2016 Guidelines A programming project is a laboratory that you complete on your own, without the help of others. It is a form of take-home exam. You may

More information

Object Oriented Programming. Java-Lecture 6 - Arrays

Object Oriented Programming. Java-Lecture 6 - Arrays Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types

More information

Critters. Critter #2 Attack.ROAR Attack.POUNCE Attack.SCRATCH. Critter #1

Critters. Critter #2 Attack.ROAR Attack.POUNCE Attack.SCRATCH. Critter #1 Critters This assignment was co-created by Stuart Reges and Marty Stepp. This program focuses on classes, objects, and inheritance. You will write the following files: Ant.java, Bird.java, Crab.java, FireAnt.java,

More information

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M Control Structures Intro. Sequential execution Statements are normally executed one

More information

Chapter 6. Repetition Statements. Animated Version The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Chapter 6. Repetition Statements. Animated Version The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6 Repetition Statements Animated Version required for reproduction or display. Chapter 6-1 Objectives After you have read and studied this chapter, you should be able to Implement repetition control

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

Practice Midterm 1. Problem Points Score TOTAL 50

Practice Midterm 1. Problem Points Score TOTAL 50 CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the

More information

Welcome1.java // Fig. 2.1: Welcome1.java // Text-printing program.

Welcome1.java // Fig. 2.1: Welcome1.java // Text-printing program. 1 Welcome1.java // Fig. 2.1: Welcome1.java // Text-printing program. public class Welcome1 // main method begins execution of Java application System.out.println( "Welcome to Java Programming!" ); } //

More information

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

Data & Variables It s elementary, my dear Riker. Sir.

Data & Variables It s elementary, my dear Riker. Sir. Boaz Kantor Introduction to Computer Science, Fall semester 2010-2011 IDC Herzliya Data & Variables It s elementary, my dear Riker. Sir. Data, Star Trek ( Lonely Among US ) Packages Package pack1 Default

More information

HW4: Let s Play Poker

HW4: Let s Play Poker HW4: Let s Play Poker Warm-Up Question How would you access the number 7 in this array? int array[] = {1, 3, 5, 7, 9; Searching through an array - Start from index 0, stored in i - Increment, aka add 1,

More information

McGill University School of Computer Science COMP-202A Introduction to Computing 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

//If target was found, then //found == true and a[index] == target.

//If target was found, then //found == true and a[index] == target. 230 CHAPTER 5 Arrays //If target was found, then //found == true and a[index] == target. } if (found) where = index; return found; 20. 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 21. int a[4][5]; int index1, index2;

More information