CS305J Introduction to Computing

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Introduction to Programming
Introduction to Programming
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
CSCI 160 Midterm Review Rasanjalee DM.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. It is common to use two nested loops when filling or searching: for.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-1: Arrays reading: 7.1 self-checks: #1-9 videos: Ch. 7 #4.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
1 Fall 2008ACS-1903 for Loop Reading files String conversions Random class.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Chapter 7: User-Defined Methods
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Review COMP 102 #
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Lecture 2: Classes and Objects, using Scanner and String.
Chapter 5 Loops.
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 18 Recursion Lecture 6 Dr. Musab.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
Java Review if Online Time For loop Quiz on Thursday.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
CS12230 Introduction to Programming Extra example– More on responsibilities 1.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
TOPIC 8 MORE ON WHILE LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Week91 APCS-A: Java Problem Solving November 2, 2005.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
A 2-D Array is a structure that storage space both vertically and horizontally. Thus, the array has both rows and columns. 2-D Arrays are used to create.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Objects Real and Java COMP T1 3
CSC111 Quick Revision.
Chapter 7 User-Defined Methods.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 7 User-Defined Methods.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Chapter 8 – Arrays and Array Lists
Week of 12/12/16 Test Review.
Loop Structures.
Computer Programming Methodology Input and While Loop
SELECTION STATEMENTS (1)
INPUT STATEMENTS GC 201.
Tools for implementing a game: Rock, Paper, Scissors
While Statement.
Decision statements. - They can use logic to arrive at desired results
Java Fix a program that has if Online time for Monday’s Program
Introduction to Programming
An Introduction to Java – Part I, language basics
Lecture Notes – Week 3 Lecture-2
Truth tables: Ways to organize results of Boolean expressions.
Lec 4: while loop and do-while loop
Truth tables: Ways to organize results of Boolean expressions.
Java Fix a program that has if Online time for Monday’s Program
IPC144 Introduction to Programming Using C Week 4 – Lesson 1
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 14, 2011
Announcements & Review
Methods/Functions.
Presentation transcript:

CS305J Introduction to Computing Discussion Section Week 12

Announcements No lab 11, no A Pair assignment has changed lab 11 counts for 10 out of 100 total Pair assignment has changed check at the discussion board Set game rules

Recap from Lab 10 Input racecar testing a end Output racecar is a palindrome testing is not a palindrome a is a palindrome

To-do List Repeat these three steps until “end” Read a word from file input Check if the word is palindrome or not Output to the terminal if the word is (not) a palindrome print the result read from file check palindrome stop if “end”

Methods Method 1 (nextWord) Method 2 (isPalindrome) parameter: Scanner file return: String word Method 2 (isPalindrome) parameter: String word return: boolean result Method 3 (printResult) parameter: boolean result, String word return: void read from file word check palindrome result print the result

Use Java API BlueJ->Help->Java Class Libraries nextWord = next() in Scanner class printResult = System.out.print(word) printResult nextWord isPalindrome stop if “end” Main method only contains the “logic” part. while loop stops at “end” calls other methods

Class Palindrome public static boolean isPalindrome(String word) return true if the word is a palindrome public static void main(String[]) while (word is not end) read word using next() call isPalindrome(word) print the result

Recap from TicTacToe Input moves Output for each move, 1,1 0,1 1,0 . Output for each move, print error if illegal move display the board announce the winner

Design with many classes What objects? (Classes) What to remember? (Instance Variables) How the classes interact? game instance variables: int turn, board b b.display() b.move(x, y, turn) board instance variable: int[][] board public void display() public boolean move(int x, int y, int turn)

Design each Class Classes: game, board Instance variables What to do in each class? (Methods) game receive user input for the move announce the winner game instance variables: int turn, board b b.display() b.move(x, y, turn) board instance variable: int[][] board public void display() public boolean move(int x, int y, int turn)

Class Game private int turn private board myBoard public static void main(String[]) initialize myBoard while (there is no winner) read (x,y) location for the next move myBoard.move(x, y, turn) myBoard.display() myBoard.isWin() change the turn read the move (x,y) move on the board true/false display board check winner false change the turn

Class Board private int[][] board private boolean winner public boolean move(int x, int y, int turn) return false if the move is not allowed set winner to be true if this is the winning move public void display() display the current board public boolean isWin() return true if instance variable winner is true

Connect Four Turn-in by 10pm today Cover page: names and discussion sections Input/Output Class Interaction Design Design for each class (instance variables, methods) Diagram for the logic in the main method Turn-in by 10pm today rtf, doc, ppt, ps, pdf hard copy in homework box in TAY