CS2 Assignment A1S The Simple Shapes Package

Size: px
Start display at page:

Download "CS2 Assignment A1S The Simple Shapes Package"

Transcription

1 CS2 Assignment A1S The Simple Shapes Package Overview In this project you will create a simple shapes package consisting of three interfaces and three classes. In abstract terms, you will establish classes for circles, squares, and rectangles. I will provide an interface, a class which implements the interface, and a test program for circles. For squares and rectangles, I will provide the interfaces and you will provide the classes and the test programs. The three interfaces and the three classes which implement them will be placed in a source package called shapes, which we will make good use of later. The three test programs will be placed in a source package called testers. This project presents you with a nice opportunity employ the problem solving strategy of working by analogy to help create a nice little package. Demos SCircle demo... Testing the functionality of the SCircle class... Create a circle of radius 10 and display it: <Circle: radius=10.0> Display the radius, diameter, area, perimeter. radius = 10.0 diameter = 20.0 area = perimeter = Expand the circle by 5 and display it: <Circle: radius=15.0> Shrink the circle by 10 and display it: <Circle: radius=5.0> SSquare demo... Testing the functionality of the SSquare class... Create a square of side 100 and display it: <Square: side=100.0> Display the side, diagonal, area, and perimeter. side = diagonal = area = perimeter = Expand the square by 5 and display it: <Square: side=105.0> Shrink the side by 10 and display it: <Square: side=95.0> SRectangle demo... Testing the functionality of the SRectangle class... Create a rectangle of height 40 width 50 and display it: <Rectangle: height=40.0 width=50.0> Display the sides, diagonal, area, and perimeter. height = 40.0 width = 50.0 diagonal = area = perimeter = Expand the height by 11 and width by 12 and display: <Rectangle: height=51.0 width=62.0> Shrink the height by 9 and width by 8 and display: <Rectangle: height=42.0 width=54.0>

2 Code SCircleADT.java... / Abstract Data Type for a simple Circle class. public interface SCircleADT { public double radius(); public double diameter(); public double area(); public double perimeter(); public void expand(double amount); public void shrink(double amount); public String tostring(); SCircle.java... / Simple Circle class. public class SCircle implements SCircleADT { private double radius; Creates a new SCircle r the radius of the circle public SCircle(double r) { this.radius = r; Computes the radius of the the radius of the circle public double radius() { return radius; Computes the area of the the area of the circle public double area() { return Math.PI Math.pow(radius,2);

3 Computes the perimeter of the the perimeter of the circle public double perimeter() { return Math.PI diameter(); Computes the diameter of the the diameter of the circle public double diameter() { return radius2; Expand the circle by a given a is the amount by which the radius is increased public void expand(double a) { radius = radius + a; Shrink the circle by a given a is the amount by which the radius is decreased public void shrink(double a) { radius = radius - a; Computes a textual representation of the a textual representation of the circle public String tostring() { return "<Circle: radius=" + radius + ">"; SCircleTester.java... / SCircleTester is a program to test the SCircle functionality. package testers; import shapes.scircle; public class SCircleTester { Test the functionality of the SCircle args the command line arguments public static void main(string[] args) { System.out.println( "Testing the functionality of the SCircle class..."); System.out.print("Create a circle of radius 10 and display it: "); SCircle c = new SCircle(10); System.out.println(c.toString());

4 System.out.println( "Display the radius, diameter, area, perimeter."); System.out.println("radius = " + c.radius()); System.out.println("diameter = " + c.diameter()); System.out.println("area = " + c.area()); System.out.println("perimeter = " + c.perimeter()); System.out.print("Expand the circle by 5 and display it: "); c.expand(5); System.out.println(c.toString()); System.out.print("Shrink the circle by 10 and display it: "); c.shrink(10); System.out.println(c.toString()); SSquareADT.java... / Abstract Data Type for a simple Square Class public interface SSquareADT { public double side(); public double area(); public double perimeter(); public double diagonal(); public void expand(double amount); public void shrink(double amount); public String tostring(); SRectangleADT.java... / Abstract Data Type for a simple Rectangle class. public interface SRectangleADT { public double height(); public double width(); public double area(); public double perimeter(); public double diagonal(); public void expand(double h, double w); public void shrink(double h, double w); public String tostring(); Tasks

5 1. Get into Netbeans. 2. Choose File New Project. 3. Establish a new project by stepping through the New Project wizard. (a) On the Choose Project form: i. Select Catategories = Java and Projects = Java Class Application and then hit Next. i. Type Shapes into the Project Name Field. 4. Notice that there is no Main.java class, as this is not an application. 5. Choose File New File. 6. Establish the SCircleADT interface by stepping through the New File wizard. (a) On the Choose File Type form: i. Select Catategories = Java and File Type = Java Interface ii. Hit Next. i. Make Class Name = SCircleADT and Package = shapes. 7. Modify the SCircleADT.java interface template so that, except for the author information, it matches that given above. 8. Choose File New File. 9. Establish the SCircle class by stepping through the New File wizard. (a) On the Choose File Type form: i. Select Catategories = Java and File Type = Java Class ii. Hit Next. i. Make Class Name = SCircle and Package = shapes. 10. Modify the SCircle.java interface template so that, except for the author information, it matches that given above. 11. Choose File New File. 12. Establish the SCircleTester class by stepping through the New File wizard. (a) On the Choose File Type form: i. Select Catategories = Java and File Type = Java Main Class ii. Hit Next. i. Make Class Name = SCircleTester and Package = testers. 13. Modify the SCircleTester.java interface template so that, except for the author information, it matches that given above.

6 14. Run the test program. Compare the output with that required. Fix as necessary. 15. Working by analogy, establish SSquareADT.java, SSquare.java, and SSquareTester.java in the appropriate packages. Note that SSquareADT.java must be used as provided, and that it is up to you to write the other two programs. Run the test program. Compare the output with that required. Fix as necessary. 16. Working by analogy, establish SRectangleADT.java, SRectangle.java, and SRectangleTester.java in the appropriate packages. Note that SRectangleADT.java must be used as provided, and that it is up to you to write the other two programs. Run the test program. Compare the output with that required. Fix as necessary. 17. Run the javadoc on the project in order to generate the HTML documentation for this package. (To generate the documentation for a package using the Javadoc tool you can click on the Generate Javadoc item associated with the name of the package!) Questions 1. What is an interface? 2. What does it mean for a class to implement an interface? 3. What does it mean in number 15 to work by analogy. 4. What does it mean in number 16 to work by analogy. 5. What does the Javadoc tool do? 6. How many packages did you establish in this project? 7. How many interfaces did you establish in this project? 8. How many classes did you establish in this project? 9. How many objects does each test program create when run?

Object Oriented Programming

Object Oriented Programming Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 11 Object Oriented Programming Eng. Mohammed Alokshiya December 16, 2014 Object-oriented

More information

CS Week 13. Jim Williams, PhD

CS Week 13. Jim Williams, PhD CS 200 - Week 13 Jim Williams, PhD This Week 1. Team Lab: Instantiable Class 2. BP2 Strategy 3. Lecture: Classes as templates BP2 Strategy 1. M1: 2 of 3 milestone tests didn't require reading a file. 2.

More information

Chapter 5 Lab Methods

Chapter 5 Lab Methods Chapter 5 Lab Methods Lab Objectives Be able to write methods Be able to call methods Be able to write javadoc comments Be able to create HTML documentation using the javadoc utility Introduction Methods

More information

Object Oriented Programming in C#

Object Oriented Programming in C# Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create

More information

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes COMP200 - Object Oriented Programming: Test One Duration - 60 minutes Study the following class and answer the questions that follow: package shapes3d; public class Circular3DShape { private double radius;

More information

Chapter 5 Lab Methods

Chapter 5 Lab Methods Gaddis_516907_Java 4/10/07 2:10 PM Page 41 Chapter 5 Lab Methods Objectives Be able to write methods Be able to call methods Be able to write javadoc comments Be able to create HTML documentation for our

More information

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding Java Class Design Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Objectives Implement encapsulation Implement inheritance

More information

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario The Story So Far... Classes as collections of fields and methods. Methods can access fields, and

More information

Chapter 21- Using Generics Case Study: Geometric Bunch. Class: Driver. package csu.matos; import java.util.arraylist; public class Driver {

Chapter 21- Using Generics Case Study: Geometric Bunch. Class: Driver. package csu.matos; import java.util.arraylist; public class Driver { Chapter 21- Using Generics Case Study: Geometric Bunch In this example a class called GeometricBunch is made to wrap around a list of GeometricObjects. Circle and Rectangle are subclasses of GeometricObject.

More information

CSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3:

CSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3: PROGRAMMING ASSIGNMENT 3: Read Savitch: Chapter 7 Programming: You will have 5 files all should be located in a dir. named PA3: ShapeP3.java PointP3.java CircleP3.java RectangleP3.java TriangleP3.java

More information

Chapter 5 Lab Methods

Chapter 5 Lab Methods Chapter 5 Lab Methods Lab Objectives Be able to write methods Be able to call methods Be able to write javadoc comments Be able to create HTML documentation for our Java class using javadoc Introduction

More information

AShape.java Sun Jan 21 22:32: /** * Abstract strategy to compute the area of a geometrical shape. Dung X. Nguyen * * Copyright

AShape.java Sun Jan 21 22:32: /** * Abstract strategy to compute the area of a geometrical shape. Dung X. Nguyen * * Copyright AShape.java Sun Jan 21 22:32:31 2001 1 Abstract strategy to compute the area of a geometrical shape. @author Dung X. Nguyen Copyright 1999 by Dung X. Nguyen - All rights reserved. Modifications by Alan

More information

Lesson11-Inheritance-Abstract-Classes. The GeometricObject case

Lesson11-Inheritance-Abstract-Classes. The GeometricObject case Lesson11-Inheritance-Abstract-Classes The GeometricObject case GeometricObject class public abstract class GeometricObject private string color = "White"; private DateTime datecreated = new DateTime(2017,

More information

CS 1301 Ch 8, Handout 2

CS 1301 Ch 8, Handout 2 CS 1301 Ch 8, Handout 2 This section discusses the split and match methods of the String class, regular expressions, and creating objects from strings, and command line arguments. The split Method 1. The

More information

Use the scantron sheet to enter the answer to questions (pages 1-6)

Use the scantron sheet to enter the answer to questions (pages 1-6) Use the scantron sheet to enter the answer to questions 1-100 (pages 1-6) Part I. Mark A for True, B for false. (1 point each) 1. Abstraction allow us to specify an object regardless of how the object

More information

Making New instances of Classes

Making New instances of Classes Making New instances of Classes NOTE: revised from previous version of Lecture04 New Operator Classes are user defined datatypes in OOP languages How do we make instances of these new datatypes? Using

More information

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

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods

More information

public static boolean isoutside(int min, int max, int value)

public static boolean isoutside(int min, int max, int value) See the 2 APIs attached at the end of this worksheet. 1. Methods: Javadoc Complete the Javadoc comments for the following two methods from the API: (a) / @param @param @param @return @pre. / public static

More information

CSE 143 Lecture 20. Circle

CSE 143 Lecture 20. Circle CSE 143 Lecture 20 Abstract classes Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; public double area() { return Math.PI * radius * radius; public

More information

F I N A L E X A M I N A T I O N

F I N A L E X A M I N A T I O N Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student

More information

Programming 2. Inheritance & Polymorphism

Programming 2. Inheritance & Polymorphism Programming 2 Inheritance & Polymorphism Motivation Lame Shape Application public class LameShapeApplication { Rectangle[] therects=new Rectangle[100]; Circle[] thecircles=new Circle[100]; Triangle[] thetriangles=new

More information

Documenting, Using, and Testing Utility Classes

Documenting, Using, and Testing Utility Classes Documenting, Using, and Testing Utility Classes Readings: Chapter 2 of the Course Notes EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Structure of Project: Packages and Classes

More information

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington First Programs CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Output System.out.println( ) prints out something. System.out.println is the first

More information

CPS109 Lab 7. Source: Big Java, Chapter 7 Preparation: read Chapter 7 and the lecture notes for this week.

CPS109 Lab 7. Source: Big Java, Chapter 7 Preparation: read Chapter 7 and the lecture notes for this week. 1 CPS109 Lab 7 Source: Big Java, Chapter 7 Preparation: read Chapter 7 and the lecture notes for this week. Objectives: 1. To practice using one- and two-dimensional arrays 2. To practice using partially

More information

COE 212 Engineering Programming. Welcome to Exam I Thursday June 21, Instructor: Dr. Wissam F. Fawaz

COE 212 Engineering Programming. Welcome to Exam I Thursday June 21, Instructor: Dr. Wissam F. Fawaz 1 COE 212 Engineering Programming Welcome to Exam I Thursday June 21, 2018 Instructor: Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book. Please do not forget to write your

More information

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber Chapter 10 Inheritance and Polymorphism Dr. Hikmat Jaber 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the

More information

Eng. Mohammed Alokshiya

Eng. Mohammed Alokshiya Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Lab 1 Introduction to Java Eng. Mohammed Alokshiya September 28, 2014 Java Programming

More information

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017 Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 11: Inheritance and Polymorphism Part 1 Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad

More information

Programming by Delegation

Programming by Delegation Chapter 2 a Programming by Delegation I. Scott MacKenzie a These slides are mostly based on the course text: Java by abstraction: A client-view approach (4 th edition), H. Roumani (2015). 1 Topics What

More information

Area and Perimeter Name: Date:

Area and Perimeter Name: Date: Area and Perimeter Name: Date: RECTANGLE: PARALLELOGRAM: TRIANGLE: TRAPEZOID: PERIMETER: 1. Plot the following points on the graph above: R(-3, 2), T(-3, 7), W(-9, 2), S(-9, 7). Now connect the points.

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn how to describe objects and classes and how to define classes and create objects

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn how to describe objects and classes and how to define classes and create objects Islamic University of Gaza Faculty of Engineering Computer Engineering Dept Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn how to describe objects and classes and how to define

More information

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;}

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;} 1. What does mystery(3) return? public int mystery (int n) { int m = 0; while (n > 1) {if (n % 2 == 0) n = n / 2; else n = 3 * n + 1; m = m + 1;} return m; } (a) 0 (b) 1 (c) 6 (d) (*) 7 (e) 8 2. What are

More information

COMP200 ABSTRACT CLASSES. OOP using Java, from slides by Shayan Javed

COMP200 ABSTRACT CLASSES. OOP using Java, from slides by Shayan Javed 1 1 COMP200 ABSTRACT CLASSES OOP using Java, from slides by Shayan Javed Abstract Classes 2 3 From the previous lecture: public class GeometricObject { protected String Color; protected String name; protected

More information

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

IST311. Advanced Issues in OOP: Inheritance and Polymorphism IST311 Advanced Issues in OOP: Inheritance and Polymorphism IST311/602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition

More information

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington First Programs CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Output System.out.println( ) prints out something. System.out.println is the first

More information

Using NetBeans to document code. The NetBeans IDE can be used to help generate Javadoc documentation and to check that the documentation is complete.

Using NetBeans to document code. The NetBeans IDE can be used to help generate Javadoc documentation and to check that the documentation is complete. Using NetBeans to document code The NetBeans IDE can be used to help generate Javadoc documentation and to check that the documentation is complete. Before you generate documentation you should set the

More information

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington First Programs CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Output System.out.println( ) prints out something. System.out.println is the first

More information

Topic 7: Algebraic Data Types

Topic 7: Algebraic Data Types Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,

More information

Give one example where you might wish to use a three dimensional array

Give one example where you might wish to use a three dimensional array CS 110: INTRODUCTION TO COMPUTER SCIENCE SAMPLE TEST 3 TIME ALLOWED: 60 MINUTES Student s Name: MAXIMUM MARK 100 NOTE: Unless otherwise stated, the questions are with reference to the Java Programming

More information

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

1. Which of the following is the correct expression of character 4? a. 4 b. 4 c. '\0004' d. '4' Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

- Aggregation - UML diagram - Self-Referential Classes - Generisity

- Aggregation - UML diagram - Self-Referential Classes - Generisity - Aggregation - UML diagram - Self-Referential Classes - Generisity 1 Class Circle public class Circle private double xcenter; // x center coordinate private double ycenter; // y center coordinate private

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor: Alan

More information

UFCE3T-15-M Object-oriented Design and Programming

UFCE3T-15-M Object-oriented Design and Programming UFCE3T-15-M Object-oriented Design and Programming Block1: Objects and Classes Jin Sa 27-Sep-05 UFCE3T-15-M Programming part 1 Objectives To understand objects and classes and use classes to model objects.

More information

Eng. Mohammed S. Abdualal

Eng. Mohammed S. Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2124) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 1 Introduction

More information

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes. a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must

More information

Java interface Lecture 15

Java interface Lecture 15 Lecture 15 Waterford Institute of Technology April 5, 2016 John Fitzgerald Waterford Institute of Technology, Java interface Lecture 15 1/34 Presentation outline Estimated duration presentation Questions

More information

CSE 143. Lecture 13: Interfaces, Comparable reading: , 16.4, 10.2

CSE 143. Lecture 13: Interfaces, Comparable reading: , 16.4, 10.2 CSE 143 Lecture 13: Interfaces, Comparable reading: 9.5-9.6, 16.4, 10.2 Related classes Consider classes for shapes with common features: Circle (defined by radius r ): area = r 2, perimeter = 2 r Rectangle

More information

Computational Expression

Computational Expression Computational Expression Graphics Janyl Jumadinova 6 February, 2019 Janyl Jumadinova Computational Expression 6 February, 2019 1 / 11 Java Graphics Graphics can be simple or complex, but they are just

More information

CSIS 10A Assignment 9 Solutions

CSIS 10A Assignment 9 Solutions CSIS 10A Assignment 9 Solutions Read: Chapter 9 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

Review: Array Initializer Lists

Review: Array Initializer Lists More on Arrays Review of Arrays of ints, doubles, chars Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 7.2 Reading for this lecture: L&L 7.3 7.7,

More information

Objects. say something to express one's disapproval of or disagreement with something.

Objects. say something to express one's disapproval of or disagreement with something. Objects say something to express one's disapproval of or disagreement with something. class Person: def init (self, name, age): self.name = name self.age = age p1 = Person("John", 36) class Person: def

More information

What is Polymorphism? CS 112 Introduction to Programming

What is Polymorphism? CS 112 Introduction to Programming What is Polymorphism? CS 112 Introduction to Programming (Spring 2012) q polymorphism: Ability for the same code to be used with different types of objects and behave differently with each. Lecture #33:

More information

Interfaces. Relatedness of types. Interface as a contract. The area and perimeter of shapes 7/15/15. Savitch ch. 8.4

Interfaces. Relatedness of types. Interface as a contract. The area and perimeter of shapes 7/15/15. Savitch ch. 8.4 Relatedness of types Interfaces Savitch ch. 8.4 Consider the task of writing classes to represent 2D shapes such as Circle, Rectangle, and Triangle. There are certain attributes or operations that are

More information

Lab 9: Creating a Reusable Class

Lab 9: Creating a Reusable Class Lab 9: Creating a Reusable Class Objective This will introduce the student to creating custom, reusable classes This will introduce the student to using the custom, reusable class This will reinforce programming

More information

Chapter Test Form A. 173 Holt Geometry. Name Date Class. 1. Find the area of the triangle.

Chapter Test Form A. 173 Holt Geometry. Name Date Class. 1. Find the area of the triangle. Form A 1. Find the area of the triangle. 6. A square has a perimeter of 8 inches. Find the area of the square. cm 7. Find the circumference of C in terms of.. Find the area of the parallelogram. 11 cm

More information

Abstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof

Abstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof Abstract Class Lecture 21 Based on Slides of Dr. Norazah Yusof 1 Abstract Class Abstract class is a class with one or more abstract methods. The abstract method Method signature without implementation

More information

Clean Classes. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 11

Clean Classes. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 11 Clean Classes Christopher Simpkins chris.simpkins@gatech.edu Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 1 / 11 Data Abstraction with Classes Consider a concrete Point data type: public

More information

public class SomeClass OtherClass SomeInterface { }

public class SomeClass OtherClass SomeInterface { } CMP 326 Final Fall 2015 Name: There is a blank page at the end of the exam if you need more room to answer a question. 1) (10 pts) Fill in the blanks to specify the missing keywords or definitions. public

More information

Name: Class: Date: 2. I have four vertices. I have four right angles and all my sides are the same length.

Name: Class: Date: 2. I have four vertices. I have four right angles and all my sides are the same length. 1. Circle the right triangles. Use the corner of a piece of paper to check. 2. I have four vertices. I have four right angles and all my sides are the same length. What am I? 3. I have four vertices. All

More information

Aim: How do we find the volume of a figure with a given base? Get Ready: The region R is bounded by the curves. y = x 2 + 1

Aim: How do we find the volume of a figure with a given base? Get Ready: The region R is bounded by the curves. y = x 2 + 1 Get Ready: The region R is bounded by the curves y = x 2 + 1 y = x + 3. a. Find the area of region R. b. The region R is revolved around the horizontal line y = 1. Find the volume of the solid formed.

More information

Formatted Output (printf) CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Formatted Output (printf) CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Formatted Output (printf) CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Formatted Printing - References Java API: https://docs.oracle.com/javase/7/docs/api/java/util/formatter.html#syntax

More information

The width is cm 2 marks. 2 a Measure the length of the line in millimetres. b Mark with an arrow ( ) the midpoint of the line.

The width is cm 2 marks. 2 a Measure the length of the line in millimetres. b Mark with an arrow ( ) the midpoint of the line. GM End-of-unit Test Measure the sides of this rectangle. The length is cm The width is cm 2 a Measure the length of the line in millimetres. mm Mark with an arrow ( ) the midpoint of the line. c This is

More information

CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions

CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions Name CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions 1. a. (25 points) A rational number is a number that can be represented by a pair of integers a numerator and a denominator.

More information

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1 Inheritance & Polymorphism Recap Inheritance & Polymorphism 1 Introduction! Besides composition, another form of reuse is inheritance.! With inheritance, an object can inherit behavior from another object,

More information

The Essence of OOP using Java, Nested Top-Level Classes. Preface

The Essence of OOP using Java, Nested Top-Level Classes. Preface The Essence of OOP using Java, Nested Top-Level Classes Baldwin explains nested top-level classes, and illustrates a very useful polymorphic structure where nested classes extend the enclosing class and

More information

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging WIT COMP1000 Testing and Debugging Testing Programs When testing your code, always test a variety of input values Never test only one or two values because those samples may not catch some errors Always

More information

Math-2 Lesson 6-3: Area of: Triangles, rectangles, circles and Surface Area of Pyramids

Math-2 Lesson 6-3: Area of: Triangles, rectangles, circles and Surface Area of Pyramids Math- Lesson 6-3: rea of: Triangles, rectangles, circles and Surface rea of Pyramids SM: Lesson 6-3 (rea) For the following geometric shapes, how would you answer the question; how big is it? Describe

More information

Area of Polygons And Circles

Area of Polygons And Circles Name: Date: Geometry 2011-2012 Area of Polygons And Circles Name: Teacher: Pd: Table of Contents DAY 1: SWBAT: Calculate the area and perimeter of Parallelograms and Triangles Pgs: 1-5 HW: Pgs: 6-7 DAY

More information

Advanced Computer Programming

Advanced Computer Programming Programming in the Large I: Methods (Subroutines) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University

More information

COMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed

COMP200 INHERITANCE. OOP using Java, from slides by Shayan Javed 1 1 COMP200 INHERITANCE OOP using Java, from slides by Shayan Javed 2 Inheritance Derive new classes (subclass) from existing ones (superclass). Only the Object class (java.lang) has no superclass Every

More information

Chapter 23. Inheritance and Polymorphism

Chapter 23. Inheritance and Polymorphism B B Chapter 23 Inheritance and Polymorphism 533 This chapter describes six levels of abstraction. Data abstraction, encompassing Type abstraction, and Structure abstraction Control abstraction, encompassing

More information

Perimeter, Area, Surface Area, & Volume

Perimeter, Area, Surface Area, & Volume Additional Options: Hide Multiple Choice Answers (Written Response) Open in Microsoft Word (add page breaks and/or edit questions) Generation Date: 11/25/2009 Generated By: Margaret Buell Copyright 2009

More information

TeeJay Publishers Homework for Level D book Ch 10-2 Dimensions

TeeJay Publishers Homework for Level D book Ch 10-2 Dimensions Chapter 10 2 Dimensions Exercise 1 1. Name these shapes :- a b c d e f g 2. Identify all the 2 Dimensional mathematical shapes in these figures : (d) (e) (f) (g) (h) 3. Write down the special name for

More information

Note : That the code coverage tool is not available for Java CAPS Repository based projects.

Note : That the code coverage tool is not available for Java CAPS Repository based projects. Code Coverage in Netbeans 6.1 Holger Paffrath August 2009 Code coverage is a simple method used to determine if your unit tests have covered all relevant lines of code in your program. Netbeans has a plugin

More information

Question 2. [5 points] Given the following symbolic constant definition

Question 2. [5 points] Given the following symbolic constant definition CS 101, Spring 2012 Mar 20th Exam 2 Name: Question 1. [5 points] Determine which of the following function calls are valid for a function with the prototype: void drawrect(int width, int height); Assume

More information

Java for Interfaces and Networks (DT3010, HT11)

Java for Interfaces and Networks (DT3010, HT11) Java for Interfaces and Networks (DT3010, HT11) Introduction Federico Pecora School of Science and Technology Örebro University federico.pecora@oru.se Federico Pecora Java for Interfaces and Networks Lecture

More information

CS 113 PRACTICE FINAL

CS 113 PRACTICE FINAL CS 113 PRACTICE FINAL There are 13 questions on this test. The value of each question is: 1-10 multiple choice (4 pt) 11-13 coding problems (20 pt) You may get partial credit for questions 11-13. If you

More information

1.124J Foundations of Software Engineering. Problem Set 5. Due Date: Tuesday 10/24/00

1.124J Foundations of Software Engineering. Problem Set 5. Due Date: Tuesday 10/24/00 1.124J Foundations of Software Engineering Problem Set 5 Due Date: Tuesday 10/24/00 Reference Readings: From Java Tutorial Getting Started: Lessons 1-3 Learning the Java Language: Lessons 4-7 o 4. Object-Oriented

More information

Building Java Programs. Interfaces and Comparable reading: , 10.2, 16.4

Building Java Programs. Interfaces and Comparable reading: , 10.2, 16.4 Building Java Programs Interfaces and Comparable reading: 9.5-9.6, 10.2, 16.4 2 Shapes Consider the task of writing classes to represent 2D shapes such as Circle, Rectangle, and Triangle. Certain operations

More information

Free Response. Test A. 1. What is the estimated area of the figure?

Free Response. Test A. 1. What is the estimated area of the figure? Test A 1. What is the estimated area of the 6. An 8.5 in. by 11 in. sheet of paper is enlarged to make a poster by doubling its length and width. What is the new perimeter? 7. How does the area of a square

More information

S8.6 Volume. Section 1. Surface area of cuboids: Q1. Work out the surface area of each cuboid shown below:

S8.6 Volume. Section 1. Surface area of cuboids: Q1. Work out the surface area of each cuboid shown below: Things to Learn (Key words, Notation & Formulae) Complete from your notes Radius- Diameter- Surface Area- Volume- Capacity- Prism- Cross-section- Surface area of a prism- Surface area of a cylinder- Volume

More information

TWO-DIMENSIONAL FIGURES

TWO-DIMENSIONAL FIGURES TWO-DIMENSIONAL FIGURES Two-dimensional (D) figures can be rendered by a graphics context. Here are the Graphics methods for drawing draw common figures: java.awt.graphics Methods to Draw Lines, Rectangles

More information

Chapters 1.18 and 2.18 Areas, Perimeters and Volumes

Chapters 1.18 and 2.18 Areas, Perimeters and Volumes Chapters 1.18 and.18 Areas, Perimeters and Volumes In this chapter, we will learn about: From Text Book 1: 1. Perimeter of a flat shape: 1.A Perimeter of a square 1.B Perimeter of a rectangle 1.C Perimeter

More information

Programming in the Large II: Objects and Classes (Part 1)

Programming in the Large II: Objects and Classes (Part 1) Programming in the Large II: Objects and Classes (Part 1) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen

More information

Reviewing OO Concepts

Reviewing OO Concepts Reviewing OO Concepts Users want to draw circles onto the display canvas. public class Circle { // more code here SWEN-261 Introduc2on to So3ware Engineering Department of So3ware Engineering Rochester

More information

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1 Java and OOP Part 3 Extending classes OOP in Java : W. Milner 2005 : Slide 1 Inheritance Suppose we want a version of an existing class, which is slightly different from it. We want to avoid starting again

More information

Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY. Arithmetic Operators

Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY. Arithmetic Operators Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY Arithmetic Operators There are four basic arithmetic operations: OPERATOR USE DESCRIPTION + op1 + op2 Adds op1 and op2 - op1 + op2 Subtracts

More information

Java for Interfaces and Networks (DT3029)

Java for Interfaces and Networks (DT3029) Java for Interfaces and Networks (DT3029) Lecture 1 Introduction and Basics Federico Pecora federico.pecora@oru.se Center for Applied Autonomous Sensor Systems (AASS) Örebro University, Sweden Image source:

More information

COMP 1210 Documentation Guidelines Page 1 of 7. Class documentation (Chapter 1):

COMP 1210 Documentation Guidelines Page 1 of 7. Class documentation (Chapter 1): COMP 1210 Documentation Guidelines Page 1 of 7 Class documentation (Chapter 1): Every class in your program should have a Javadoc tag that specifies the programs purpose, the project number, the author,

More information

CS 11 java track: lecture 3

CS 11 java track: lecture 3 CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor:

More information

COMP 250. inheritance (cont.) interfaces abstract classes

COMP 250. inheritance (cont.) interfaces abstract classes COMP 250 Lecture 31 inheritance (cont.) interfaces abstract classes Nov. 20, 2017 1 https//goo.gl/forms/ymqdaeilt7vxpnzs2 2 class Object boolean equals( Object ) int hashcode( ) String tostring( ) Object

More information

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 6 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 21, 2013 Question 1 What is the output of the following C++ program? #include #include using namespace

More information

Java Memory Management

Java Memory Management Java Memory Management Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each code (classes and interfaces) objects running methods 1-2 Memory Areas

More information

Surface Area and Volume

Surface Area and Volume Surface Area and Volume Day 1 - Surface Area of Prisms Surface Area = The total area of the surface of a three-dimensional object (Or think of it as the amount of paper you ll need to wrap the shape.)

More information

Formative Assessment Area Unit 5

Formative Assessment Area Unit 5 Area Unit 5 Administer the formative assessment and select contrasting student responses to create further opportunities for learning about area measure, especially the difference between units of length

More information

Reviewing OO Concepts

Reviewing OO Concepts Reviewing OO Concepts Users want to draw circles onto the display canvas. public class Circle { // more code here SWEN-261 Introduction to Software Engineering Department of Software Engineering Rochester

More information

Unit #13 : Integration to Find Areas and Volumes, Volumes of Revolution

Unit #13 : Integration to Find Areas and Volumes, Volumes of Revolution Unit #13 : Integration to Find Areas and Volumes, Volumes of Revolution Goals: Beabletoapplyaslicingapproachtoconstructintegralsforareasandvolumes. Be able to visualize surfaces generated by rotating functions

More information