COSC 111: Computer Programming I. Dr. Bowen Hui University of Bri>sh Columbia Okanagan

Similar documents
J a v a Quiz (Unit 3, Test 0 Practice)

CS170 Lab 11 Abstract Data Types & Objects

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Sample CSE8A midterm Multiple Choice (circle one)

Moving from CS 61A Scheme to CS 61B Java

AP COMPUTER SCIENCE A 2007 SCORING GUIDELINES

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Java Crash Course Part I

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

Grundlæggende Programmering IT-C, Forår Written exam in Introductory Programming

Example of a Java program

AP Computer Science Java Subset

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Programming Languages CIS 443

Chapter 1 Java Program Design and Development

Assignment # 2: Design Patterns and GUIs

ECE 122. Engineering Problem Solving with Java

HW3: Programming with stacks

The following program is aiming to extract from a simple text file an analysis of the content such as:

Lecture 1: Course Introduction"

An Incomplete C++ Primer. University of Wyoming MA 5310

LAB4 Making Classes and Objects

1. Writing Simple Classes:

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

E-Learning User Manual

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Contents. 9-1 Copyright (c) N. Afshartous

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

CHAPTER 1 ENGINEERING PROBLEM SOLVING. Copyright 2013 Pearson Education, Inc.

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

Install Java Development Kit (JDK) 1.8

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Chapter 6: Programming Languages

Chapter 2 Writing Simple Programs

CS 111 Classes I 1. Software Organization View to this point:

Software Development with UML and Java 2 SDJ I2, Spring 2010

Goal: Practice writing pseudocode and understand how pseudocode translates to real code.

Writing Self-testing Java Classes with SelfTest

CP Lab 2: Writing programs for simple arithmetic problems

CSE 308. Coding Conventions. Reference

Part I. Multiple Choice Questions (2 points each):

Building Java Programs

Programming Fundamentals I CS 110, Central Washington University. November 2015

It has a parameter list Account(String n, double b) in the creation of an instance of this class.

1 Hour, Closed Notes, Browser open to Java API docs is OK

Basics of Java Programming Input and the Scanner class

Sharpen Solutions. 1 Part One. Sometimes there s more than one right answer. And sometimes the

Introduction to Object-Oriented Programming

Introduction to Python

Java CPD (I) Frans Coenen Department of Computer Science

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

Compiler Construction

(Eng. Hayam Reda Seireg) Sheet Java

Inside the Java Virtual Machine

Computer Programming I

1001ICT Introduction To Programming Lecture Notes

Iteration CHAPTER 6. Topic Summary

COMPUTER SCIENCE. Paper 1 (THEORY)

DOVER-SHERBORN HIGH SCHOOL PROGRAM OF STUDIES

Building Java Programs

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Map Reduce Workflows

Integration of Application Business Logic and Business Rules with DSL and AOP

COSC282 BIG DATA ANALYTICS FALL 2015 LECTURE 2 - SEP 9

Introduction to formal semantics -

Fundamentals of Programming and Software Development Lesson Objectives

Computer Science 401 Introduction to Computers Spring 2012 Syllabus

Free Online Game Games For Cell Phones and Televas

Classes and Objects. Agenda. Quiz 7/1/2008. The Background of the Object-Oriented Approach. Class. Object. Package and import

Two-Dimensional Arrays. Multi-dimensional Arrays. Two-Dimensional Array Indexing

Computer Science 1-3 (AP) Syllabus/Online Course Plan

Computer Programming I & II*

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Software Engineering 1 EEL5881 Spring Homework - 2

Course Syllabus CAD 140 Computer-Aided Drafting I 3 Semester Hours

Understanding class definitions

Software documentation systems

Asking Questions About Public Health: The Role of Epidemiology. Sapp SENCER

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

PIC 10A. Lecture 7: Graphics II and intro to the if statement

RARITAN VALLEY COMMUNITY COLLEGE COURSE OUTLINE. CISY 103 Computer Concepts and Programming

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Software Development. Chapter 7. Outline The Waterfall Model RISKS. Java By Abstraction Chapter 7

java Features Version April 19, 2013 by Thorsten Kracht

Java Programming Fundamentals

Best Practices for Helping All Students Get Ready for the SAT. Prepared for Idaho SDE January 2014

Integrating Formal Models into the Programming Languages Course

Ms. Nicholas Spring VIDEO GAME DESIGN LESSON PLANS

CS 101 Computer Programming and Utilization

Intruduction to Groovy & Grails programming languages beyond Java

GENERATION OF EPC BASED SIMULATION MODELS. EURO 2012 Vilnius, Lithuania

Transcription:

COSC 111: Computer Programming I Dr. Bowen Hui University of Bri>sh Columbia Okanagan 1

Today Review slides from week 2 Review another example with classes and objects Review classes in A1 2

Discussion Forum on Connect Answers to ques>ons TAs have posted helpful hints based on what they saw in the lab 3

Slides, Notes, Readings Course website s tenta>ve lecture schedule updated as we go Slides and notes are posted TAs will have access to what has been taught in class Read before class as part of your prep 4

From Week 2: Trivia Game Design Game Main responsibility: Needs to keep track of: Have ability to do: Ques>on Main responsibility: Needs to keep track of: Have ability to do: Player Main responsibility: Needs to keep track of: Have ability to do:. 5

We said: Once you have a design 1. Translate each kind of object into a Java class 2. Translate group of things to keep track of into ayributes 3. Translate each ability into a skeleton method Detail the list of commands to issue in each method Rule of thumb: each ability corresponds to one process (or rou>ne, or method, or ) Later, you will start to combine processes together Later, you will start to decompose complicated processes into mul>ple, smaller processes 6

We said: From Planning to Implementa>on Quiz game design Keep track of Abili>es Test design?? Class template class Game // ayributes // methods class TestQuiz Game quiz = new Game(); quiz.startgame(); // con>nue here Simplified template 7

We had: Classes for Game, Ques>on, Player class Game // ayributes // methods class Ques>on // ayributes // methods class Player // ayributes // methods class TestGame Quiz game = new Quiz(); game.startgame(); // con>nue here 8

We had: Methods Think of it as a rou>ne A set of repe>>ve steps grouped together How to do something Used to define an object s ability Examples in your everyday life? Carry conversa>on Walking to a classroom Cooking spaghej Doing homework 9

We introduced: Input- process- output (IPO) Model to show process interac>on Input informa>on, resources needed Process step- by- step commands Output results of transforming I by P Input Process Output 10

Game ability We went through: Example IPOs for these Display 10 ques>ons in each game Ques>on ability Set correct answer Player ability Maintain own high score across all previous games 11

We started: Transla>ng to Java methods Template structure: returntype methodname( vartype 1 var 1,, vartype k var k ) // commands go here Parameters = variables inside brackets Like a math func>on e.g. f(x) These vars can be used in the commands inside method Return type and parameter type must follow the same rules as the type of informa>on for ayributes 12

Review: Example design class Quiz // ayributes // constructor // other methods here void startgame() int getplayerscore() // access score in // person s ayributes return - 1; int comphighs( int score1, int score2 ) // compare score1 with score2 // return higher of the two return - 1; // con>nue next column boolean isgameover() // are all ques>ons answered? // if so, return true return false; String isbeyer( Player p2 ) // compare my person s // high score to p2 s highscore // return name of my person // if it has higher score // else return p2 s name return temp ; 13

Tes>ng the classes class TestQuiz Calls the constructor method Player bob = new Player( robert ); // call its methods here Ques>on q1 = new Ques>on( What is, a. 1, b. 5, c. 10 ); q1.setrealanswer( b ); // call its methods here Game quiz = new Game(); quiz.startgame(); // call its methods here Calls a method pass in real values 14

We ended with this summary: Steps: Convert class design to class skeleton Convert each thing to keep track of into ayributes Declare them only Build a constructor method Ini>alize all the ayributes in it Convert each class ability into a method Create a test class by crea>ng object and calling its methods class TestQuiz Quiz game = new Quiz(); game.startgame(); 15

Today: Another Game Example class Ques>on // ayributes String ques>onwords; String mc1; String mc2; String mc3; int realanswer; // methods Ques>on( String q, String opt1, String op2, String op3 ) String tostring() 16

Con>nue with Game Class class Game // ayributes int numcorrect; Ques>on q1; Ques>on q2; // methods Game() void setanswer1( int i ) void setanswer2( int i ) void printques>ons() 17

What do the Ques>on objects look See handout: like? Ques>on- object- q1.txt shows the ayributes have been set certain values that were used when q1 was ini>alized Ques>on- object- q2.txt shows different values that were used when q2 was ini>alized 18

Lastly, a TestGame class (simplified) class TestGame // declare object here // call object s methods here 19

Lastly, a TestGame class (actual template) class TestGame public sta>c void main( String args[] ) // declare object here // call object s methods here 20

TestGame class class TestGame public sta>c void main( String args[] ) // declare object here Game quiz = new Game(); // call object s methods here quiz.setanswer1( 2 ); quiz.setanswer2( 3 ); quiz.printques>ons(); 21

Homework Study this layer Game example using the handouts we just reviewed (also available online) Goal: Understand the detailed code with lots of comments Use the comments as a guide to understand the program 22

Classes Provided in A1 TakeOut.java Review its responsibility, ayributes, methods Has most of the defini>on given Some code missing Use comments as a guide Customer.java and Order.java Review their responsibili>es, ayributes, methods Use comments as a guide TestTakeOut.java Use comments as a guide Some code missing 23