Java Outline (Upto Exam 2)

Similar documents
ECE 122. Engineering Problem Solving with Java

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

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

(Python) Chapter 3: Repetition

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

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

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

About this exam review

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

While Loops A while loop executes a statement as long as a condition is true while condition: statement(s) Statement may be simple or compound Typical

RANDOM NUMBER GAME PROJECT

Loops. CSE 114, Computer Science 1 Stony Brook University

WELCOME! (download slides and.py files and follow along!) LECTURE 1

Condition Controlled Loops. Introduction to Programming - Python

Name Section: M/W T/TH Number Definition Matching (8 Points)

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

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

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

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

Chapter Goals. Contents LOOPS

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

Quiz 1: Functions and Procedures

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Introduction to the Java Basics: Control Flow Statements

Fundamentals of Programming Session 13

University of Massachusetts Amherst, Electrical and Computer Engineering

COMP 110 Programming Exercise: Simulation of the Game of Craps

COMP 202 Java in one week

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Name Section: M/W T/TH Number Definition Matching (6 Points)

CSC 1351: Quiz 6: Sort and Search

CS112 Lecture: Loops

The little book of programming challenges

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

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

APCS Semester #1 Final Exam Practice Problems

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

Chapter 4 Introduction to Control Statements

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

Theory of control structures

Textbook. Topic 5: Repetition. Types of Loops. Repetition

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

Why Is Repetition Needed?

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

C Functions. 5.2 Program Modules in C

Finding and Fixing Bugs

Unit 1 Lesson 4. Introduction to Control Statements

1 Short Answer (2 Points Each)

Chapter 3 - Functions

Outline. Announcements. Homework 2. Boolean expressions 10/12/2007. Announcements Homework 2 questions. Boolean expression

Chapter 4 The If Then Statement

CS 314 Exam 2 Spring

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

CMPT 120 Introduction To Computing Science And Programming I. Pseudocode. Summer 2012 Instructor: Hassan Khosravi

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object

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

CSE123. Program Design and Modular Programming Functions 1-1

Loops (while and for)

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

MITOCW watch?v=0jljzrnhwoi

Advanced Computer Programming

COMP 202. Java in one week

Chapter 3. More Flow of Control. Copyright 2008 Pearson Addison-Wesley. All rights reserved.

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

Crude Video Game Simulator Algorithm

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

Lecture Transcript While and Do While Statements in C++

Lecture 04 FUNCTIONS AND ARRAYS

CS111: PROGRAMMING LANGUAGE II

Repetition, Looping. While Loop

[ the academy_of_code] Senior Beginners

Programming with Java

LN #3 (3 Hrs) Repetition, Computational state CTPS Department of CSE,Coimbatore

The Big Python Guide

Score score < score < score < 65 Score < 50

Flow of Control: Loops

Object-Oriented Programming in Java

CONDITION CONTROLLED LOOPS. Introduction to Programming - Python

Iteration: Intro. Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times. 2. Posttest Condition follows body Iterates 1+ times

Chapter 4 Loops. Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk

Announcements. Homework 0: using cin with 10/3 is NOT the same as (directly)

6.S189 Homework 2. What to turn in. Exercise 3.1 Defining A Function. Exercise 3.2 Math Module.

12/22/11. } Rolling a Six-Sided Die. } Fig 6.7: Rolling a Six-Sided Die 6,000,000 Times

CS112 Lecture: Repetition Statements

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

Software Development Pseudocode

mith College Computer Science Week 8 CSC111 - Spring 2015 Dominique Thiébaut

EASY

(f) d={ alchemist :( a, t ), shaman : ( s, n ), wizard : ( w, z )} d[ shaman ][1]


C++ Final Exam 2017/2018

CS1110 Lab 6 (Mar 17-18, 2015)

Java Review. Fundamentals of Computer Science

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Transcription:

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 user a skill testing question with a word answer. Tell them if they are right or wrong. (Ex. What is the capital of Sask?) 2. Ask the user a skill testing question with a number answer. Tell them if they are right or wrong. (Ex. What is 12 x 6?) 3. Ask the user for their favourite colour. Deal with 4 different colours as answers. Be sure to deal with the situation that none of the 4 was chosen. (Ex. If their colour is blue, then tell them they must be cold. If their colour is red, then tell them they must be hot. If their colour is green, then tell them they must be naïve. If their colour is black, then tell them they must be mad. For all other colours, then tell them that you don t know what they are.) Suggestion: Test each section one part at a time then move on to the next part. Marks (for Assignment#1 Ifs program) 2. /5 for Skill Testing Questions 3. /5 for Colours Hand in Program Assignment#2 (7 marks): In a new role-playing fantasy game players must design their character by picking a point value for each of three characteristics: Strength, from 1 to 10 Health, from 1 to 10 Luck, from 1 to 10 Write a program called Fantasy that asks for a name for the character and asks for the point value of for each of the three characteristics. However, the total points must be less than 15. If the total exceeds 15, then 5 points are assigned to each characteristic. An example of how the game would work is given below: Welcome to Yertle's Quest Enter the name of your character: Chortle Enter strength (1-10): 8 Enter health (1-10): 4 Enter luck (1-10): 6 You have given your character too many points! Default values have been assigned: Chortle has a strength value of 5, a health value of 5, and a luck value: 5

Marks (for Assignment#2 Fantasy program) 2. /3 for inputs and variables used 3. /2 for outputs (including proper if statement) Notes Assignment Chapter 12/13 (8 marks) 1. two-way decisions 2. block statement 3. boolean expression 4. difference between using the == vs just the = symbols (2 marks) 5. three-way decisions 6. nested if statements 7. danger of comparing floating point amounts (Ex if dlbnum == 5.5) use the if statement use the if else use block if statements, ie using the { } use all the Relational Operators (see below) A == B is A equal to B A < B is A less than B A <= B is A less than or equal to B A > B is A Greater than B A >= B is A Greater than or equal to B A!= B is A not equal to B use nested if statements use the if else if else (See Mr. Kerbrat about this one if needed!) use the.equals( ) method for Strings use constants (final + declare variable) Chapter 14 (Boolean Expressions and Variables) Hand in Program Assignment (10 marks): Create a program called Guess that will do the following: 1. Ask the user for a number from 1 to 100 (3 are correct). 2. If the number is 33 or 45 or 67 then tell them they guessed one of the right numbers. 3. If the number is within 3 or any one number, tell them they are very close. (For example, 30, 31, 32, 34, 35, 36 would be very close) 4. If it is any other number between 1 and 100, tell them they are not very close. 5. Numbers less than 1 or numbers greater than 100 should not be allowed. Tell them they should read the instructions next time.

Marks (for Guess program) 1. /1 for proper comments (header + other meaningful comments) 2. /2 for the code to guess the correct number (Must use in code for full marks) 3. /3 for the code to deal with numbers that are very close to the correct answers 4. /2 for the use of the && Boolean operator in code 5. /2 for dealing with numbers outside of the 1 to 100 range Notes Assignment Chapter 14 (9 marks) logical operators (make a list of them) /3 {state what they mean} relational operators (make a list of them) /6 {state what they mean} create Boolean expressions using the and-operator (&&) Key Use: To check between two amounts (range testing) (Ex Between 10 and 20) create Boolean expressions using the or-operator ( ) Chapter 15-19 (Loops and the While Statement, Counters) Hand in Program Assignment (20 marks): Create a program called Loops1 that will do the following: 1. Use a while loop to print out the pattern: 3 4 5 6 7 8 9 10 11 12 2. Use a while loop to print out the pattern: 20 18 16 14 12 10 3. Use while loops to print out the pattern: 0 1 4 9 16 25 36 49 64 81 100 4. Use while loops, counters and multiple variables to print out the following: The first 10 Fibonacci numbers are: 0 1 1 2 3 5 8 13 21 34 Note: Sequence is derived by adding 2 numbers to get the next in the list. 5. Use a while loop that asks for marks. The loop must add up all the marks together. The loop ends when the user types in any mark that is not between 0 and 100. When the loop is done, it must calculate the average of the marks and print it out. Take care of all possibilities, including divide by zero problem (don t let it crash!). Hint: return; will stop the program break; will exit the current loop Marks (for Loops1 program) 2. /2 pattern 3,4,5 pattern 3. /2 pattern 20,18,16 pattern 4. /3 pattern 0,1,4,9,16 pattern 5. /5 Fibonacci sequence 6. /6 Marks program

Notes Assignment Chapter 15-19 (6 marks) loop counting loop initialization increment iteration infinite loop use the while statement as a loop use counters (intcount = intcount + 1 OR intcount ++) increment loops by values other than 1 (count = count + 2 OR count +=2) Chapter 41 (The For Loop) Hand in Program Assignment (10 marks): Create a program called Loops2 that will create the patterns below and calculate factorial given an inputted number. You must use the for loop. Marks (for Loops2 program) 1. /2 pattern 3,4,5,,12 pattern 2. /2 pattern 20,18,16,,0 pattern 3. /2 pattern 0,1,4,9,16,25,36,49,64,81,100 pattern 4. /4 factorial (Ex. If someone types a 5, then 5! = 120.) Chapter 20 (Random) Hand in Program Assignment#1 (10 marks): Create a program called GuessRandom that does the following: 1. Picks a random number from 1 to 10. 2. Allows the user three guesses. As soon as the user enters the correct number the program writes a winning message and exits. 3. If the user fails to enter the correct number in three guesses, the program writes a failure message that includes what the correct number was and then it exits. (You must use a LOOP here for full marks!) Hint: return; will stop the program break; will exit the current loop Marks (for GuessRandom program) 2. /4 for allowing only 3 guesses ** You must use a LOOP for full marks!! 3. /4 for correct messages if right or wrong

Hand in Program Assignment#2 (Bonus of 10 marks towards Assignments!): (This is an OPTIONAL program!) Create a program called Pig that does the following: 1. Player and Computer start out with zero points. 2. The winner is the first player to reach 100 points or more. 3. In each round, the computer rolls first, followed by the player. 4. The computer rolls three dice and the sum of spots is added to its score. 5. At the start of the player's turn, a working sum is initialized to zero. 6. The player then rolls a single die as many times as desired. - If the die shows a 1 (on the first roll or any roll), then the player's turn is over and nothing is added to the player's score. - For rolls other than 1, the roll is added to the working sum. - If the player stops rolling before a 1 occurs, then the working sum is added to the player's score. Hints: You will need to use multiple loops You will need to use loops inside of loops (nested loops) Use a press enter to continue section (See Extras folder) to slow down the computer so that you can see the output one round at a time, rather than in one giant lump Marks (for Assignment#2 Pig program)) 2. /4 for computer s score 3. /4 for player s score after 1 st round 4. /2 for dealing with 1 s rolled (ending the round) 5. /4 for dealing with loops (nested) 6. /4 for final scores and who wins use the Random class to generate random numbers use nextint(), nextdouble() calculate a random number between a range of numbers (eg. between 3 and 10) EXTRA BONUS (Towards Final Exam Possible 2 marks added to Final) Do the PIG Program with a GUI format (Talk to Mr. K. about this Bonus first!)