1 Project 15: Animals Using Derived Classes and Inheritance.

Slides:



Advertisements
Similar presentations
1 Project 6: Tic Tac Toe. 2 Tic Tac Toe A Challange Project 10 Points extra credit on final grade OK to work in groups of 2 or 3.
Advertisements

CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 11 / 28 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
© 2003 Walter Savitch These slides are for the exclusive use of students in CSE 11 at UCSD, Winter quarter They may not be copied or used for any.
CS 206 Introduction to Computer Science II 01 / 23 / 2009 Instructor: Michael Eckmann.
1 Project 6: Cats in Tree. 2 Project 3: Cats in Tree In this project you will Create a class definition for a Cat class. Populate a BST with Cat information.
1 Project 7: Huffman Code. 2 Extend the most recent version of the Huffman Code program to include decode information in the binary output file and use.
Welcome to CS 115! Introduction to Programming. Class URL Please write this down!
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
1 Project 7: My Photo Album Graded Project. 2 Assignment Write a web app to permit users to upload and view photos. User can keep up to five photos on.
Writing Classes (Chapter 4)
1 Project 4: XML Product Browser (Not Graded). Objectives This project is an exercise of the following knowledge and skills: Accessing and displaying.
CS125 Exam Review Winter Some Exam Info Tuesday (22nd) at 4:00-6:30pm in the PAC CHECK YOUR SEAT!!! Read Final Exam Information on website –Practice.
What is inheritance? It is the ability to create a new class from an existing class.
1 Project 4: Vehicle Inventory. 2 Write a program to read a text file containing information about vehicles and output the information First in the order.
CS/ENGRD 2110 SPRING 2015 Lecture 6: Consequence of type, casting; function equals 1.
Welcome to CS 115! Introduction to Programming. Class URL Write this down!
CS/ENGRD 2110 FALL 2014 Lecture 6: Consequence of type, casting; function equals 1.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
1 Project 3: Chomp (Not graded). 2 Project 3 The game of Chomp was described in a Math Trek column in Science News:
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
1 Project 5: New Venue. 2 New Venue Based on the posted New Venue scenario 077_Ticket_Booth_Scenarios.pdf.
1 Project 7: Northwind Traders Order Entry. 2 Northwind Order Entry Extend the Select Customer program from Project 6 to permit the user to enter orders.
11 Introduction to Object Oriented Programming (Continued) Cats.
Programming in Java CSCI-2220 Object Oriented Programming.
MIT AITI 2004 – Lecture 12 Inheritance. What is Inheritance?  In the real world: We inherit traits from our mother and father. We also inherit traits.
11 Project 2 Towers of Hanoi. 22 Towers of Hanoi is a well known puzzle that can be very difficult to solve manually but can be programmed very easily.
1 Project 5: Printing Address Labels. 2 Assignment Write a Windows forms program to display and print a set of address labels. Input from a csv file.
1 Project 3 The Kumquat Society Conference. 2 Conference Registration In this project you will write a program to handle a conference registration. The.
1 Derived Classes Chapter Objectives You will be able to: Create and use derived classes.
Project 3: Ticket Printer
Inheritance Fundamentals. Inheritance A derived class extends a base class. It inherits all of its methods (behaviors) and attributes (data) and it may.
1 COP 3331 Object Oriented Design Spring 2016 Section 001 F 8:00 AM – 10:45 AM CPR 115 Classroom Lecture 3 credit hours Instructor:Dr. Rollins Turner ENB.
1 COP 2510 Programming Concepts Spring credit hours Instructor:Dr. Rollins Turner ENB 343F Office Hours: MW 11:00 AM – 12:00.
Inheritance in Java. Access Specifiers private keywordprivate keyword –Used for most instance variables –private variables and methods are accessible.
Written by: Dr. JJ Shepherd
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
1 Project 3 String Methods. Project 3: String Methods Write a program to do the following string manipulations: Prompt the user to enter a phrase and.
1 Project 1: Tickets. 2 Class Ticket Write a definition for class Ticket. A Ticket object corresponds to a physical ticket for a stage show. Attributes.
11 Introduction to Object Oriented Programming (Continued) Cats.
1 Project 2: Sorting Cats. Write a C++ console application to read a text file containing information about cats and output the information to the screen.
1 Project 4 Address Lookup. Project 4 Write an ASP.NET app that permits users to retrieve addresses from a potentially large list of addresses. There.
CS/ENGRD 2110 FALL 2015 Lecture 6: Consequence of type, casting; function equals 1.
1 Project 3: Farey Sequences. 2 Farey Sequences Further details about Farey sequences, and more examples, can be found in the Wikipedia article:
1 Derived Classes Chapter Objectives You will be able to: Create and use derived classes. Understand the meaning of polymorphism and how it works.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
11 Project 2 Temperature Conversion. 22 Project 2: Temperature Conversion Write an ASP.NET Web Forms app to convert temperatures from Fahrenheit to Celsius.
1 Project 5: Leap Years. 222 Leap Years Write a program that reads an integer value from the user representing a year and determines if the year is a.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
1 Project 4: Palindrome Detector. 2 Assignment Write a C++ program that reads a line of text from the keyboard and reports to the user whether the text.
1 Project 4: Venue Sort. 2 This project is an exercise in Using C++ strings. Operator overloading. Text File Input.
1 Project 5 Eyeglass Rx User Control. Eyeglass Rx Earlier in the semester we looked at an eyeglass prescription as an example of an HTML table. 2.
Object-Oriented Design Chapter 7 1. Objectives You will be able to Use the this reference in a Java program. Use the static modifier for member variables.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
1 More About Derived Classes and Inheritance Chapter 9.
1 Project 6: New Venue. 2 New Venue Based on the posted New Venue scenario
1 Project 8: Tic Tac Toe. 2 Assignment Write an HTML and JavaScript page that pemits users to play Tic Tac Toe. Both players use a single browser. Alternating.
1 Project 7: Ticket_Booth_0 Using XML. 2 Ticket Booth 0 Base Level 0 of the real Ticket Booth program. Gets information for a single venue from an XML.
1 Project 12: Cars from File. This is an extension of Project 11, Car Class You may use the posted solution for Project 11 as a starting point for this.
1 Project 6: Northwind Orders. 2 The Northwind Traders Database The Northwind Traders database was created by Microsoft for training and demonstration.
Exam 3 Information George Koutsogiannakis
Inheritance.
PRG 218 Week 5 Individual Assignment Coding: Derived Classes Please click here to buy ( (
More on Classes and Objects
CS201 Fall 2016 George Koutsogiannakis
Java Programming with BlueJ Objectives
February , 2009 CSE 113 B.
Foundations of Programming 2: Inheritance and Polymorphism
Presentation transcript:

1 Project 15: Animals Using Derived Classes and Inheritance

Project 15: Animals In this project we will create a base class to represent animals of various kinds. Class Animal Then we will create derived classes to represent specific kinds of animals. Dog Cat Bird 2

Class Animal Every animal has Kind of animal (Dog, Cat, Bird) Name Owner's name Date of Birth Create a class, Animal, to hold information common to all animals. Will be a base class for derived classes representing specific kinds of animals. 3

Class Animal Define instance variables for the information that is common to all animals: private String kind_of_animal; private String name; private String owner_name; private Calendar date_of_birth; Provide a constructor that has parameters of the same name and type: public Animal(String kind_of_animal, String name, String owner_name, Calendar dob) 4

Class Animal Provide accessor methods for all instance variables. Same name as the instance variable with first letter capitalized. Provide a toString method. See test run. Download program Animal_Tester from the class web site, and use it to test your Animal class. Downloads/Project_15_Animals/ Downloads/Project_15_Animals/ 5

Test Run 6

Class Dog Create class Dog as a derived class from class Animal. Let class Dog have instance variables private String breed; private String favorite_treat; 7

Class Dog The constructor for class Dog should have parameters for breed and favorite treat, in addition to the parameters for class Animal Except it doesn't need kind_of_animal, because we know that will be Dog. public Dog(String name, String owner_name, Calendar dob, String breed, String favorite_treat) 8

Class Dog Provide accessor methods for all instance variables specific to class Dog. Provide a toString method. See test run. Download program Dog_Tester from the class web site, and use it to test your Dog class. Downloads/Project_15_Animals/ Downloads/Project_15_Animals/ 9

Test Run 10

Class Cat Add class Cat, derived from class Animal. Cats have the following attributes in addition to those of class Animal: Breed Preferred Catfood 11

Class Cat The constructor for class Cat should have parameters for breed and preferred catfood, in addition to the parameters for class Animal Except it doesn't need kind_of_animal, because we know that will be Cat. public Cat(String name, String owner_name, Calendar dob, String breed, String preferred_catfood) 12

Class Cat Provide accessor methods for all instance variables specific to class Cat. Provide a toString method. See test run. Download Cat_Tester.java from the class web site, and use it to test your Cat class. Downloads/Project_15_Animals/ Downloads/Project_15_Animals/ 13

Test Run 14

Class Bird Create class Bird as a derived class from class Animal. Let class Bird have instance variables private String species; private double wingspan; 15

Class Bird The constructor for class Bird should have parameters for the instance variables that are specific to class Bird, in addition to the parameters for class Animal Except it doesn't need kind_of_animal, because we know that will be Bird. public Bird(String name, String owner_name, Calendar dob, String species, double wingspan) 16

Class Bird Provide accessor methods for all instance variables specific to class Bird. Provide a toString method. See test run. Download program Bird_Tester from the class web site, and use it to test your Bird class. Downloads/Project_15_Animals/ Downloads/Project_15_Animals/ 17

Test Run 18

19 Submission Put your Java class files into a folder and zip it. Animal.java, Dog.java, Cat.java, Bird.java Only.java files. Nothing else. Don't submit the test drivers. (We already have them!) Submit your zipped folder via Canvas Assignments. Project is due by 11:59 PM Sunday, April 24 All Sections Recommendation: Do this project in your lab session or help session.

20 Ground Rules It is OK to discuss the project with other students BUT Do not share your code with other students. Before or after submitting the project. Do not copy any other student’s code. Or even look at it. Do not let anyone copy or examine your code.

Ground Rules Except for code posted on the class web site Do not copy code from the Internet or any other source (other than the textbook.) Do not ask for help on an Internet forum. If you need help, ask your instructor or a TA. Come to lab and help sessions. Write your own code.