Preface The goal of this lab is to calculate and compare the area of Circle, Rectangle and Square In this lab, you need to write 5 classes: AreaCalculator,

Slides:



Advertisements
Similar presentations
Java Programming Abstract classes and Interfaces.
Advertisements

SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Computer Science 209 Software Development Equality and Comparisons.
Inheritance Lakshmish Ramaswamy. Example A Rectangle class with area method A Circle class with area method Array containing references to circles & rectangles.
More about classes and objects Classes in Visual Basic.NET.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
TA: Nouf Al-Harbi NoufNaief.net :::
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Programming 2 LAB TA: Nouf Al-Harbi NoufNaief.net :::
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Factory Method Design Pattern (1) –A creational design.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
1 Lecture 09 Iterators and Enumerations Reading for these lectures: Weiss, Section Iterator Interface. Much better is: ProgramLive, Section 12.3.
CS 307 Fundamentals of Computer ScienceInterfaces and Abstract Classes 1 Topic 7 Interfaces and Abstract Classes “I prefer Agassiz in the abstract, rather.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Abstract Factory Design Pattern making abstract things.
Recitation 4 Abstract classes, Interfaces. A Little More Geometry! Abstract Classes Shape x ____ y ____ Triangle area() base____ height ____ Circle area()
Outline §Review of the last class l class variables and methods l method overloading and overriding §Inheritance and polymorphism l polymorphism l abstract.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Cs205: engineering software university of virginia fall 2006 Subtyping and Inheritance David Evans Quiz Friday: classes through.
Coming up: Inheritance
Repeating patterns Can you work out the next shape in the pattern?
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
CompSci Reading from Files  import java.io.File;  Declare a file File fileOfCats = new File(”cats.txt”);  Use file – pass it as an argument to.
Interfaces, Abstract Classes, and Polymorphism. What Is an Interface? An interface is the set of public methods in a class Java provides the syntax for.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Object-Oriented Programming: Polymorphism Chapter 10.
Day 3: The Command and Visitor Patterns. Preliminaries The Java static type system uses simple rules to infer types for Java expressions. The inferred.
Interfaces & Abstract Classes (For CS III AP) March 2014.
Abstract Classes. Recall We have the ability to create hierarchies of classes. Good design practice suggests that we move common methods as high as possible.
How many …?. What shape can you see? I can see some _____. Q1 Q1 stars.
SHAPES There are many shapes in our world. These are circles. Circles are never ending lines.
Homework Helper Chapter 12 Lesson triangles, 2 squares 2.2 rectangles and square 3.Possible answer: 3 sides; 3 vertices 4.Possible answer: shapes.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Inheritance, Polymorphism, and Interfaces 1 What’s past is prologue. Don’t write it twice — write it once and reuse it. Advanced Placement Computer Science.
1 More About Derived Classes and Inheritance Chapter 9.
Lecture 5:Interfaces and Abstract Classes
Advanced Programming in Java
Java’s World in UML Object Shape {abstract} This is done implicitly
Advanced Programming in Java
Class vs Abstract vs Interface
CS 302 Week 10 Jim Williams.
Shape & Space Surface Area.
CS 200 More Classes Jim Williams, PhD.
What shape am I? I am a plane shape. I have 4 sides.
Week 6 Object-Oriented Programming (2): Polymorphism
Lecture 6 – Exercises TCP1201: 2017/2018.
CSE 1030: Implementing Mixing static and non-static features
CSE 1030: Implementing Non-Static Features
Ben’s Lecture Cliff Notes
Area of a Composite Calculate the area of this shape Total Area =
Shapes.
All About Shapes! Let’s Go!.
Chapter 14 Abstract Classes and Interfaces
SPLITTING OF COMBINED SHAPES
SHAPES By: Ms. Conquest.
Chapter 13 Abstract Classes and Interfaces Part 01
3D shapes *.
Can you work out the next shape in the pattern?
Area and Volume How to … Calculate the area of a square or rectangle
Inheritance Lakshmish Ramaswamy.
2D Shapes Rectangle Circle Triangle Rectangle. What shape is the door? Rectangle.
Can you work out the next shape in the pattern?
Presentation transcript:

Preface The goal of this lab is to calculate and compare the area of Circle, Rectangle and Square In this lab, you need to write 5 classes: AreaCalculator, Shape, Circle, Rectangle and Square as the UML shows

UML

Homework Requirements Class Shape is an abstract class and implements interface Comparable. Comparable includes abstract methods getArea() and toString and overridden methods equals() and implement compareTo(). compareTo() equals() if the two shapes have the same area, they are equal use getArea() to identify whether the two shapes have the same area in equals(). compareTo() if A’s area is large than B’s area, A is greater than B use getArea()

Homework Requirements Circle, Rectangle & Square The three classes need to extend Shape and implement getArea() and toString(). toString() return the string like “I am Square and the area is 100.”

Homework Requirements AreaCalculator The goal of AreaCalculator is used to calculate and compare the area of shapes. overload methods sumOfArea() to add the area of two shapes and three shapes. sumOfArea(Shape s1,Shape s2), sumOfArea(Shape s1,Shape s2,Shape s3) sort shapes by the area use java.util.Arrays.sort(shapes) to sort the shapesjava.util.Arrays.sort(shapes) use Singleton pattern Refer to attached file

Homework Requirements The partial content of main method, but it is not completed

Note Please use package Package name is cs lab1 (if you don’t use package, 20 points deduction) Please pack all the files into a StudentID_lab1_version.zip Ex: _lab1_v1.zip Deadline: 2010/04/08 Mail to