Chapter 5 Case Study. Chapter 5 The RPS Flowchart.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Computer Programming Lab 8.
CS110 Programming Language I Lab 10: Arrays I Computer Science Department Spring 2014.
 for loop  while loop  do while loop  How to choose?  Nested loop  practice.
Building Java Programs Chapter 5
TA: Nouf Al-Harbi NoufNaief.net :::
CS212: DATASTRUCTURES Lecture 3: Searching 1. Search Algorithms Sequential Search It does not require an ordered list. Binary Search It requires an ordered.
LAB 10.
1 Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1, 5.6.
Computer Programming Lab(4).
Computer Programming Lab(5).
The for-statement. Different loop-statements in Java Java provides 3 types of loop-statements: 1. The for-statement 2. The while-statement 3. The do-while-statement.
 The pool rack example could be implemented using a for loop.  It is also possible to write recursive methods that accomplish things that you might.
Lecture 10 Instructor: Craig Duckett Lecture 10 is in Lecture 11 Folder.
Lecture 10 Recursion. public class recursionDemo { public static void main(String[] args) { System.out.println("TriCount for n = 5 is... " + triCount(5));
CSCI S-1 Section 6. Coming Soon Homework Part A – Friday, July 10, 17:00 EST Homework Part B – Tuesday, July 14, 17:00 EST Mid-Term Quiz Review – Friday,
Making Decisions Chapter 5.  Thus far we have created classes and performed basic mathematical operations  Consider our ComputeArea.java program to.
Boolean expressions, part 2: Logical operators. Previously discussed Recall that there are 2 types of operators that return a boolean result (true or.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
Random numbers. 2 The Random class A Random object generates pseudo-random numbers. –Class Random is found in the java.util package. import java.util.*;
The if-else statement. The if-else statement in Java The if-else statement is the second conditional statement in Java The if-else statement selects one.
TIC TAC TOE. import java.util.Scanner; import java.util.Random; public class PlayTTT{ public static void main(String[]args){ Scanner reader = new Scanner(System.in);
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
SELF STUDY. IF STATEMENTS SELECTION STRUCTURE if selection statement if … else selection statement switch selection statement.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
1 Building Java Programs Chapter 5 Lecture 11: Random Numbers reading: 5.1, 5.6.
Topic 15 boolean methods and random numbers
Chapter 2 Clarifications
Software Development I/O and Numbers
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
Building Java Programs
Building Java Programs
Building Java Programs Chapter 5
Building Java Programs
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Software Development Packages
Building Java Programs
Building Java Programs
Multiple if-else boolean Data
Computer Programming Methodology Input and While Loop
Building Java Programs
Repetition-Counter control Loop
Data types, Expressions and assignment, Input from User
Comp Sci 200 Programming I Jim Williams, PhD.
Something about Java Introduction to Problem Solving and Programming 1.
Topic 15 boolean methods and random numbers
מבוא למדעי המחשב, סמסטר א', תשע"א תרגול מס' 2
Building Java Programs
Building Java Programs
Self study.
Building Java Programs
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Lecture Notes – Week 3 Lecture-1
Lecture Notes – Week 2 Lecture-2
Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3.
Building Java Programs
CSC1401 Input and Output (with Files)
Building Java Programs
Random Numbers while loop
Building Java Programs
Consider the following code:
Presentation transcript:

Chapter 5 Case Study

Chapter 5 The RPS Flowchart

import java.util.Scanner; import java.lang.Math; public class RPS { public static void main(String[] args) { final int ROCK = 1, PAPER = 2, SCISSORS = 3; int playerThrow, computerThrow; Scanner input = new Scanner(System.in); System.out.print("Enter your throw (1=Rock, 2=Paper, 3=Scissors): "); playerThrow = input.nextInt(); input.close(); computerThrow = (int)(3 * Math.random() + 1); /* random int between 1 and 3 */

System.out.print("Player throws "); switch (playerThrow) { case ROCK: System.out.println("ROCK."); break; case PAPER: System.out.println("PAPER."); break; case SCISSORS: System.out.println("SCISSORS."); break; } System.out.print("Computer throws "); switch (computerThrow) { case ROCK: System.out.println("ROCK."); break; case PAPER: System.out.println("PAPER."); break; case SCISSORS: System.out.println("SCISSORS."); break; }

if (playerThrow == ROCK && computerThrow == ROCK) System.out.println("It's a draw!"); else if (playerThrow == ROCK && computerThrow == PAPER) System.out.println("Computer wins!"); else if (playerThrow == ROCK && computerThrow == SCISSORS) System.out.println("Player wins!"); if (playerThrow == PAPER && computerThrow == ROCK) System.out.println("Player wins!"); else if (playerThrow == PAPER && computerThrow == PAPER) System.out.println("It's a draw!"); else if (playerThrow == PAPER && computerThrow == SCISSORS) System.out.println("Computer wins!"); if (playerThrow == SCISSORS && computerThrow == ROCK) System.out.println("Computer wins!"); else if (playerThrow == SCISSORS && computerThrow == PAPER) System.out.println("Player wins!"); else if (playerThrow == SCISSORS && computerThrow == SCISSORS) System.out.println("It's a draw!"); }