CS2 Assignment A1S The Simple Shapes Package

Similar documents
Object Oriented Programming

CS Week 13. Jim Williams, PhD

Chapter 5 Lab Methods

Object Oriented Programming in C#

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

Chapter 5 Lab Methods

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

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

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

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

Chapter 5 Lab Methods

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

Lesson11-Inheritance-Abstract-Classes. The GeometricObject case

CS 1301 Ch 8, Handout 2

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

Making New instances of Classes

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

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

CSE 143 Lecture 20. Circle

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

Programming 2. Inheritance & Polymorphism

Documenting, Using, and Testing Utility Classes

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

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

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

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Eng. Mohammed Alokshiya

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

Programming by Delegation

Area and Perimeter Name: Date:

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

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

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

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

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

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

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

Topic 7: Algebraic Data Types

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

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

ITI Introduction to Computing II

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

ITI Introduction to Computing II

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

UFCE3T-15-M Object-oriented Design and Programming

Eng. Mohammed S. Abdualal

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

Java interface Lecture 15

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

Computational Expression

CSIS 10A Assignment 9 Solutions

Review: Array Initializer Lists

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

What is Polymorphism? CS 112 Introduction to Programming

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

Lab 9: Creating a Reusable Class

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

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

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

public class SomeClass OtherClass SomeInterface { }

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

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

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

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.

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

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

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

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

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

Area of Polygons And Circles

Advanced Computer Programming

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

Chapter 23. Inheritance and Polymorphism

Perimeter, Area, Surface Area, & Volume

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

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

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

Java for Interfaces and Networks (DT3010, HT11)

CS 113 PRACTICE FINAL

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

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

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

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

TWO-DIMENSIONAL FIGURES

Chapters 1.18 and 2.18 Areas, Perimeters and Volumes

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

Reviewing OO Concepts

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

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

Java for Interfaces and Networks (DT3029)

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

CS 11 java track: lecture 3

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

COMP 250. inheritance (cont.) interfaces abstract classes

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

Java Memory Management

Surface Area and Volume

Formative Assessment Area Unit 5

Reviewing OO Concepts

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

Transcription:

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 = 314.1592653589793 perimeter = 62.83185307179586 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 = 100.0 diagonal = 141.4213562373095 area = 10000.0 perimeter = 400.0 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 = 64.03124237432849 area = 2000.0 perimeter = 180.0 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>

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 instance. @param r the radius of the circle public SCircle(double r) { this.radius = r; Computes the radius of the circle. @return the radius of the circle public double radius() { return radius; Computes the area of the circle. @return the area of the circle public double area() { return Math.PI Math.pow(radius,2);

Computes the perimeter of the circle. @return the perimeter of the circle public double perimeter() { return Math.PI diameter(); Computes the diameter of the circle. @return the diameter of the circle public double diameter() { return radius2; Expand the circle by a given amount. @param a is the amount by which the radius is increased public void expand(double a) { radius = radius + a; Shrink the circle by a given amount. @param a is the amount by which the radius is decreased public void shrink(double a) { radius = radius - a; Computes a textual representation of the circle. @return 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 class. @param 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());

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

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.

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?