COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 3

Similar documents
JUnit Framework. Terminology: assertions, annotations, fixtures. Dr. Siobhán Drohan Mairead Meagher. Produced by:

Test-Driven Development JUnit

Introduction to Programming Using Java (98-388)

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

Tools for Unit Test JUnit

Test-Driven Development JUnit

APS101- Midterm Sample Questions

Introduction to JUnit. Data Structures and Algorithms for Language Processing

print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Annotations in Java (JUnit)

Tools for Unit Test - JUnit

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

Approach for Unit testing with the help of JUnit...

AP Computer Science A Summer Assignment

UNDERSTANDING CLASS DEFINITIONS CITS1001

Introduc)on to tes)ng with JUnit. Workshop 3

Homework 09. Collecting Beepers

Chapter 2 NUnit Fundamentals

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CHAPTER 7 OBJECTS AND CLASSES

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

AP Computer Science A Summer Assignment

CHAPTER 7 OBJECTS AND CLASSES

Tutorial 3: Unit tests and JUnit

CS159. Nathan Sprague. September 30, 2015

PROGRAMMING FUNDAMENTALS

Ticket Machine Project(s)

Introduction to JUnit

Lab: PiggyBank. Defining objects & classes

Credit where Credit is Due. Lecture 29: Test-Driven Development. Test-Driven Development. Goals for this lecture

Implementation. (Mapping to Java) Jörg Kienzle & Alfred Strohmeier. COMP-533 Implementation

Binghamton University. CS-140 Fall Unit Testing

Thinking Functionally

University of Massachusetts Amherst, Electrical and Computer Engineering

Objectives. Introduce static keyword examine syntax describe common uses

CSC Java Programming, Fall Java Data Types and Control Constructs

Object Oriented Design: Identifying Objects

CS 302 Week 9. Jim Williams

C Sc 227 Practice Test 2 Section Leader Your Name 100pts. a. 1D array b. PriorityList<E> c. ArrayPriorityList<E>

CSE 1102 Fall 2009 Lab Assignment 2

Implementing Classes

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

CS201 - Assignment 3, Part 1 Due: Friday February 28, at the beginning of class

CS/ENGRD 2110 FALL Lecture 3: Fields, getters and setters, constructors, testing

Lecture 3. Black- box Tes3ng

JUnit Testing Framework Architecture

Understanding class definitions. Looking inside classes (based on lecture slides by Barnes and Kölling)

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology

Software and Programming 1

Software Test. Levels of test. Types of test. Regression test The JUnit tool for unit testing Java programs. System test Integration test Unit test

Programming Project: Game of Life

Introduction to Computer Science I

Test-Driven Development

Conversions and Overloading : Overloading

Understanding class definitions

Review. these are the instance variables. these are parameters to the methods

Introduction to Computer Science and Object-Oriented Programming

Main concepts to be covered. Testing and Debugging. Code snippet of the day. Results. Testing Debugging Test automation Writing for maintainability

Verifying and Documenting ADTs: Javadoc, Java Assertions and JUnits

A+ Computer Science -

CS 209 Sec. 52 Spring, 2006 Lab 5: Classes Instructor: J.G. Neal

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CPS122 Lecture: Defining a Class

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CS 201 Advanced Object-Oriented Programming Lab 5 - Sudoku, Part 1 Due: March 3/4, 11:30 PM

CS112 Lecture: Defining Instantiable Classes

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1

Test Execution and Automation. CSCE Lecture 15-03/20/2018

Inheritance and Testing Spring 2018 Exam Prep 4: February 11, 2019

EECS168 Exam 3 Review

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

CSCI 3155: Principles of Programming Languages Exercise sheet #14 28 June 2007

Guessing Game with Objects

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Ranorex Tutorial. About this Document... 1 Ranorex Installation and Setup... 1 Tutorial Test SimpleCalculator using Ranorex... 2

Objects and State. COMP1400 Week 9. Wednesday, 19 September 12

CSE331 Winter 2014, Midterm Examination February 12, 2014

linaye/gl.html

Practice Questions for Chapter 9

EECS 4313 Software Engineering Testing

CS Problem Solving and Object-Oriented Programming

Exam 1 - (20 points)

AP CS Unit 3: Control Structures Notes

Lab #7 Library Classes and JUnit Testing. Daniel Amyot, Diana Inkpen, Alan. Agenda. In this lab, you are going to create your own

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

To gain experience using recursion and recursive data structures.

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects.

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:

Marking rubric for Assignment #2

Problem other classes messing with my stuff!

INTRODUCTION TO JAVA PROGRAMMING JAVA FUNDAMENTALS PART 2

CSE 113 A. Announcements - Lab

CIS 162 Project 4 Farkle (a dice game)

Object-Oriented Programming Concepts

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Chapter 14 Abstract Classes and Interfaces

Copy Constructors & Destructors

Transcription:

COMP 111 Introduction to Computer Science and Object-Oriented Programming

Tasks and Tools download submit edit Web-CAT compile unit test view results

Working with Java Classes You Use You Complete public double getamountincoins() // you code this return -1.0; // replace this } You Define From Scratch

Enable Testing Tools Select Preferences Check the box next to Show Unit Testing Tools

Structure of a Class /** * */ public class PocketMoney } Comments Definition of Instance Variables Definition of Constructor(s) Definition of Method(s)

The PocketMoney Class /** * An example used for * * @author Doyt Perry * @version */ public class PocketMoney // instance variables private int amountinbills = 0; private double amountincoins = 0; Needs a separate comment // conversion rate: 1 US dollar to Canadian dollar private double tocanadianrate = 1.0104;

/** * Constructor for objects of class PocketMoney */ public PocketMoney(int inamountinbills,, double inamountincoins) this.amountinbills = inamountinbills; this.amountincoins = inamountincoins; }

} /** * Convert to Canadian * * @return double converts total to Canadian dollars */ public double converttocanadian() return tocanadianrate * (this.amountinbills + this.amountincoins amountincoins); }

Using a Driver to Demo See handout Lab 1 comes with a driver You need not use or modify May want to run as a demo of program

Visualizing Execution PocketMoney patpocket = new PacketMoney(9, 1.0)

PocketMoney patpocket = new PacketMoney(9, 1.0)

PocketMoney patpocket = new PacketMoney(9, 1.0)

PocketMoney patpocket = new PacketMoney(9, 1.0)

PocketMoney patpocket = new PacketMoney(9, 1.0)

PocketMoney patpocket = new PacketMoney(9, 1.0)

PocketMoney patpocket = new PacketMoney(9, 1.0)

PocketMoney jopocket = new PacketMoney(4, 2.37);

PocketMoney jopocket = new PacketMoney(4, 2.37);

PocketMoney jopocket = new PacketMoney(4, 2.37);

System.out.println("Pat's pocket money in Canadian is " + patpocket.converttocanadian() );

System.out.println("Pat's pocket money in Canadian is " + patpocket.converttocanadian() ); public double converttocanadian() return tocanadianrate * (this.amountinbills + this.amountincoins); }

System.out.println("Pat's pocket money in Canadian is " + patpocket.converttocanadian() ); public double converttocanadian() return tocanadianrate * (this.amountinbills + this.amountincoins); }

System.out.println("Pat's pocket money in Canadian is " + patpocket.converttocanadian() ); public double converttocanadian() return tocanadianrate * (this.amountinbills + this.amountincoins); }

System.out.println("Pat's pocket money in Canadian is " + patpocket.converttocanadian() ); public double converttocanadian() return tocanadianrate * (this.amountinbills + this.amountincoins); }

System.out.println("Pat's pocket money in Canadian is " + patpocket.converttocanadian() ); public double converttocanadian() return tocanadianrate * (this.amountinbills + this.amountincoins); }

System.out.println("Pat's pocket money in Canadian is " + patpocket.converttocanadian() ); public double converttocanadian() return tocanadianrate * (this.amountinbills + this.amountincoins); }

System.out.println("Pat's pocket money in Canadian is " + patpocket.converttocanadian() );

Checking Style Can do within BlueJ Click checkstyle Look at demo

Structure of a Test Class /** * */ public class PocketMoney extends junit.framework..framework.testcase } Comments Test Class Constructor, setup & teardown Test(s) of Constructor(s) Test(s) of Method(s)

PocketMoneyTest /** * The test class PocketMoneyTest. * * @author Doyt Perry * @version 1.0 */ public class PocketMoneyTest extends junit.framework.testcase /** * Default constructor for test class PocketMoneyTest */ public PocketMoneyTest() // not used in this example }

/** * Sets up the test fixture. * * Called before every test case method. */ protected void setup() // not used in this example }

/** * Tears down the test fixture. * * Called after every test case method. */ protected void teardown() // not used in this example }

/** * Test constructor */ public void testconstructor() PocketMoney money = new PocketMoney(9,1.0); assertnotnull(money); }

/** * Test the converttocanadian method */ public void testconverttocanadian() PocketMoney money = new PocketMoney(9,1.0); assertequals(10.104, money.converttocanadian()); } }

assert Commands You can verify that a result is correct by using one of the assert commands // test passes if expected value is equivalent to actual assertequals(double expected, double actual, double delta); assertequals( int expected, int actual); assertequals( String expected, String actual); Decimal precision. // test passes if object is not null (tests instantiation) assertnotnull(object);