public static void main(string[] args) throws FileNotFoundException { ArrayList<Vehicle> arrayofvehicles = new ArrayList<Vehicle>();
|
|
- Brian Goodwin
- 6 years ago
- Views:
Transcription
1 import java.io.*; import java.util.*; import java.text.*; import java.lang.*; // Class n public class Project4 static class Comparator implements Comparator <Vehicle> public int compare(vehicle one, Vehicle two) Vehicle p1 =(Vehicle) one; Vehicle p2 =(Vehicle) two; return (p1.get ().compareto(p2.get ())); public static void main(string[] args) throws FileNotFoundException //creating arraylist for vechicle class File file = new File(args[0]); System.out.println(file.exists()); Scanner input = new Scanner(file); ArrayList<Vehicle> arrayofvehicles = new ArrayList<Vehicle>(); while(input.hasnextline()) String test = input.nextline(); ///if type vehicle if (test.equals("vehicle")) String name = input.nextline(); String address = input.nextline(); String phone = input.nextline(); String = input.nextline(); // create vehicle object arrayofvehicles.add(new Vehicle(name, address, phone, )); else if (test.equals("car")) String name = input.nextline(); String address = input.nextline(); String phone = input.nextline(); String = input.nextline(); boolean convertible = input.nextboolean(); input.nextline(); String color = input.nextline(); // create car object arrayofvehicles.add(new Car(name, address, phone, , convertible, color));
2 else if (test.equals("american car")) String name = input.nextline(); String address = input.nextline(); String phone = input.nextline(); String = input.nextline(); boolean convertible = input.nextboolean(); input.nextline(); String color = input.nextline(); boolean detroit = input.nextboolean(); boolean union = input.nextboolean(); // create american car object arrayofvehicles.add(new AmericanCar(name, address, phone, , convertible, color, detroit, union)); else if (test.equals("foreign car")) String name = input.nextline(); String address = input.nextline(); String phone = input.nextline(); String = input.nextline(); boolean convertible = input.nextboolean(); input.nextline(); String color = input.nextline(); String manufacturer = input.nextline(); //boolean detroit = input.nextboolean(); //boolean union = input.nextboolean(); float importduty = input.nextfloat(); input.nextline(); input.nextline(); // create foreign car object arrayofvehicles.add(new ForeignCar(name, address, phone, , convertible, color, manufacturer, importduty)); else if (test.equals("bicycle")) String name = input.nextline(); String address = input.nextline(); String phone = input.nextline(); String = input.nextline(); int speed = input.nextint(); // create bicycle object arrayofvehicles.add(new Bicycle(name, address, phone, , speed)); else if (test.equals("truck")) String name = input.nextline(); String address = input.nextline(); String phone = input.nextline(); String = input.nextline(); float tons = input.nextfloat(); float cost = input.nextfloat(); input.nextline(); String date = input.nextline(); arrayofvehicles.add(new Truck(name, address, phone, , tons, cost, date));
3 input.close(); // Calling Methods System.out.println("**********Printing Details**********"); // Calls printall System.out.println("The Array List"); printall(arrayofvehicles); // Calls Id System.out.println("Sorting by ID"); sort(arrayofvehicles); // Calls numberofentries printrecord(arrayofvehicles); // Calls justbt System.out.println("Just Bicycles and Trucks"); justbt(arrayofvehicles); // Calls areacode System.out.println("Area Code 987"); areacode(arrayofvehicles); //main // Methods //Prints the ArrayList public static void printall(arraylist<vehicle> array) for (int x = 0; x <= array.size() -1; x++) System.out.println(array.get(x).toString());
4 //Sorts id in arraylist public static void sort(arraylist<vehicle> array) Collections.sort(array, new Comparator()); for (int i = 0; i <= array.size() -1; i++) System.out.println(array.get(i).toString()); //Prints number of entries public static void printrecord(arraylist<vehicle> array) System.out.println("The number of records: " + array.size()); //Prints number of entries public static void justbt(arraylist<vehicle> array) for (int x = 0; x <= array.size() -1; x++) if (array.get(x) instanceof Bicycle) System.out.println(array.get(x).toString()); else if (array.get(x) instanceof Truck) System.out.println(array.get(x).toString()); //Prints number of entries public static void areacode(arraylist<vehicle> array) String number; for (int x = 0; x <= array.size() -1; x++) number = array.get(x).getphone(); if (number.substring(1,4).equals("987")) System.out.println(array.get(x).toString()); //class // Vehicle as parent class class Vehicle //data members declared as private private String ownername; private String address; private String phone; private String ;
5 //null public Vehicle () //parameterized constructor of vechicle class public Vehicle(String ownername, String address, String phone, String ) this.ownername = ownername; this.address= address; this.phone = phone; this. = ; //getters and setters for data members public String getownername() return ownername; public void setownername(string newownername) this.ownername = newownername; public String getaddress() return address; public void setaddress(string newaddress) this.address = newaddress; public String getphone() return phone; public void setphone(string newphone) this.phone = newphone; public String get () return ; public void set (string new ) this. = new ; public boolean equals(object obj) return true; //tostring(0 returns String type contains data member values of a vehicle class
6 public String tostring() return "Type of Vehicle: Vehicle\n" + "Owner's name : " + ownername + "\n" + "Address : " + address + "\n" + "Phone : " + phone + "\n" + " " + ; //Car is child class inherits from vechile class Car extends Vehicle //datamembers intilation as private private boolean convertible; private String color; //parameterized constructor of Car class public Car(String ownername, String address, String phone, String , boolean convertible, String color) //calling Vechicle class constructor using super super(ownername, address, phone, ); setconvertible(convertible); setcolor(color); //getters and setters for convertible and getcolor data members of car public boolean getconvertible() return convertible; public void setconvertible(boolean newconvertible) this.convertible = newconvertible; public String getcolor() return color; public void setcolor(string newcolor) this.color = newcolor; //tostring() method returns String type And over rides parent class is Vehicle public String tostring() return super.tostring() + "Type of Vehicle: Car\n" + "Convertible : " + convertible + "\n" +
7 "Color : " + color; //end car class /*AmericanCar inherits Car and Car inherits vechile.i.e multilevel inhertience between vechile and AmericanCar*/ // Subclass of Car class AmericanCar extends Car //Adding two data members private boolean madedetroit; private boolean unionshop; //parameterized constructor of American car public AmericanCar(String ownername, String address, String phone, String , boolean convertible, String color, boolean madedetroit, boolean unionshop) //calling car class parameterized constructor super(ownername, address, phone, , convertible, color); setmadedetroit(madedetroit); setunionshop(unionshop); //getter and setters for madedetroit, unionshop data members public boolean getmadedetroit() return madedetroit; public void setmadedetroit(boolean newmadedetroit) this.madedetroit = newmadedetroit; public boolean getunionshop() return unionshop; public void setunionshop(boolean newunionshop)
8 this.unionshop = newunionshop; //overriding super class tostring() and returns adding with newly added variables public String tostring() return super.tostring() + "Type of Vehicle: American Car\n" + "Made in Detroit : " + madedetroit + "\n" + "Union shop : " + unionshop; //child class ForeignCar inherits from Car parent class // Subclass of Car class ForeignCar extends Car // ForeignCar data members intilization private String manufacturercountry; private float importduty; //parameterized constructor for ForeignCar public ForeignCar(String ownername, String address, String phone, String , boolean convertible, String color, String manufacturercountry, float importduty) super(ownername, address, phone, , convertible, color); this.manufacturercountry = manufacturercountry; this.importduty = importduty; //getters and setters for manufacturercountry, importduty public String getmanufacturercountry() return manufacturercountry;
9 public void setmanufacturercountry(string newmanufacturercountry) this.manufacturercountry = newmanufacturercountry; public float getimportduty() return importduty; public void setimportduty(float newimportduty) this.importduty = newimportduty; //tostring() overrides parent class car public String tostring() return super.tostring() + "Type of Vehicle: Foreign Car\n" + "Manufacturer country : " + manufacturercountry + "\n" + "Import duty : " + importduty; //child class Bicycle inherits from vehicle parent class //Bicycle is child class inherits from vechile class Bicycle extends Vehicle //initialize data member as private private int numberspeeds; //parameter constructor of Bicycle public Bicycle(String ownername, String address, String phone, String , int numberspeeds) super(ownername, address, phone, ); this.numberspeeds = numberspeeds; //getter and setter of numberspeeds data member
10 public int getnumberspeeds() return numberspeeds; public void setnumberspeeds(int newnumberspeeds) this.numberspeeds = newnumberspeeds; //overriding tostring method() return String type public String tostring() return super.tostring() + "Type of Vehicle: Bicycle\n" + "Number of speeds : " + numberspeeds; //child class Truck inherits parent class Vechicle //Truck is child class inherits from vechile class Truck extends Vehicle private float numbertons; private float truckcost; private String datepurchased; //parameter constructor of Truck public Truck(String ownername, String address, String phone, String , float numbertons, float truckcost, String datepurchased) super(ownername, address, phone, ); this.numbertons = numbertons; this.truckcost = truckcost; this.datepurchased = datepurchased; //getters and setter for Truck data members
11 public float getnumbertons() return numbertons; public void setnumbertons(float newnumbertons) this.numbertons = newnumbertons; public float gettruckcost() return truckcost; public void settruckcost(float newtruckcost) this.truckcost = newtruckcost; public String getdatepurchased() return datepurchased; public void setdatepurchased(string newdatepurchased) this.datepurchased = newdatepurchased; //tostring() override superclass method public String tostring() return super.tostring() + "Type of Vehicle: Truck\n" + "Number of tons : " + numbertons + "\n" + "Truck cost : " + truckcost + "\n" + "Date purchased : " + datepurchased;
12 /* sets, null cnstuctors, comparator, type of vehicles, Boolean after each class... */
DM503 Programming B. Peter Schneider-Kamp.
DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! TYPE CASTS & FILES & EXCEPTION HANDLING 2 Type Conversion Java uses type casts for converting values
More informationLecture 2: Java & Javadoc
Lecture 2: Java & Javadoc CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Instance Variables or member variables or fields Declared in a class, but outside of any method, constructor or block
More informationDM537 Object-Oriented Programming. Peter Schneider-Kamp.
DM537 Object-Oriented Programming Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm537/! TYPE CASTS & FILES & EXCEPTION HANDLING 2 Type Conversion Java uses type casts for converting
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming
More informationCOMP200 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 informationDM550 Introduction to Programming part 2. Jan Baumbach.
DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net CALLING & DEFINING FUNCTIONS 2 Functions and Methods all functions in java are defined inside
More informationInheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.
Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods
More informationName Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?
1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationCS1150 Principles of Computer Science Objects and Classes
CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8
More informationCSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community
CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Inheritance Three main programming mechanisms that constitute object-oriented programming (OOP) Encapsulation
More informationInformatik II (D-ITET) Tutorial 6
Informatik II (D-ITET) Tutorial 6 TA: Marian George, E-mail: marian.george@inf.ethz.ch Distributed Systems Group, ETH Zürich Exercise Sheet 5: Solutions and Remarks Variables & Methods beginwithlowercase,
More informationBig software. code reuse: The practice of writing program code once and using it in many contexts.
Inheritance Big software software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues: getting
More informationProgramming in the Large II: Objects and Classes (Part 2)
Programming in the Large II: Objects and Classes (Part 2) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen
More informationLecture Notes Chapter #9_b Inheritance & Polymorphism
Lecture Notes Chapter #9_b Inheritance & Polymorphism Inheritance results from deriving new classes from existing classes Root Class all java classes are derived from the java.lang.object class GeometricObject1
More informationObject Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance
CS257 Computer Science I Kevin Sahr, PhD Lecture 10: Inheritance 1 Object Oriented Features For a programming language to be called object oriented it should support the following features: 1. objects:
More informationInheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L
Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive
More informationCONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence.
Constructor in Java 1. What are CONSTRUCTORs? Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs
More informationInformatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,
Informatik II Tutorial 6 Mihai Bâce mihai.bace@inf.ethz.ch 05.04.2017 Mihai Bâce April 5, 2017 1 Overview Debriefing Exercise 5 Briefing Exercise 6 Mihai Bâce April 5, 2017 2 U05 Some Hints Variables &
More informationInheritance (Part 5) Odds and ends
Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there
More informationIT 313 Advanced Application Development Midterm Exam
Page 1 of 9 February 12, 2019 IT 313 Advanced Application Development Midterm Exam Name Part A. Multiple Choice Questions. Circle the letter of the correct answer for each question. Optional: supply a
More informationCOMP200 - 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 informationOverview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008
Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object
More informationJAVA MOCK TEST JAVA MOCK TEST II
http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your
More informationClasses and Inheritance Extending Classes, Chapter 5.2
Classes and Inheritance Extending Classes, Chapter 5.2 Dr. Yvon Feaster Inheritance Inheritance defines a relationship among classes. Key words often associated with inheritance are extend and implements.
More informationJava Fundamentals (II)
Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class
More informationif (i % 2 == 0) { return 4 + method(i + 5) } if (i % 2 == 1) { return 2 + method(i + 3) } public static int method( int i )
Review Exercises Here is a list of review exercises. There are times when an exercise will be open ended, allowing you to pursue multiple aspects of the material. While encompassing some areas we have
More informationChapter 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 informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationCMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.
CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object
More informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationC12a: The Object Superclass and Selected Methods
CISC 3115 TY3 C12a: The Object Superclass and Selected Methods Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/4/2018 CUNY Brooklyn College 1 Outline The Object class and
More informationCOMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code
COMPUTER SCIENCE DEPARTMENT PICNIC Welcome to the 2016-2017 Academic year! Meet your faculty, department staff, and fellow students in a social setting. Food and drink will be provided. When: Saturday,
More informationDay 4. COMP1006/1406 Summer M. Jason Hinek Carleton University
Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information
More informationJava Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar
Java Classes Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie
More informationObject-Oriented Programming (Java)
Object-Oriented Programming (Java) Topics Covered Today 2.1 Implementing Classes 2.1.1 Defining Classes 2.1.2 Inheritance 2.1.3 Method equals and Method tostring 2 Define Classes class classname extends
More informationCH. 2 OBJECT-ORIENTED PROGRAMMING
CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationInheritance (Part 2) Notes Chapter 6
Inheritance (Part 2) Notes Chapter 6 1 Object Dog extends Object Dog PureBreed extends Dog PureBreed Mix BloodHound Komondor... Komondor extends PureBreed 2 Implementing Inheritance suppose you want to
More informationJava Classes, Inheritance, and Interfaces
Java Classes, Inheritance, and Interfaces Introduction Classes are a foundational element in Java. Everything in Java is contained in a class. Classes are used to create Objects which contain the functionality
More informationMore about inheritance
Main concepts to be covered More about inheritance Exploring polymorphism method polymorphism static and dynamic type overriding dynamic method lookup protected access 4.1 The inheritance hierarchy Conflicting
More informationF 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 informationLecture Notes Chapter #9_c Abstract Classes & Interfaces
Lecture Notes Chapter #9_c Abstract Classes & Interfaces Abstract Classes parent class child class more abstract more concrete, i.e., less abstract abstract class o class with an abstract modifier o class
More informationPolymorphism. return a.doublevalue() + b.doublevalue();
Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces
More informationBasic Class Diagrams. Class Diagrams, cont d. Class Diagrams, cont d. Car. Car. Car. What does the minus sign here mean?
Class #02: Inheritance and Object-Oriented Design Software Design II (CS 220): M. Allen, 23 Jan. 18 Basic Class Diagrams Describes a class and how it can be used properly Sketch of properties and behaviors
More informationJava classes cannot extend multiple superclasses (unlike Python) but classes can implement multiple interfaces.
CSM 61B Abstract Classes & Interfaces Spring 2017 Week 5: February 13, 2017 1 An Appealing Appetizer 1.1 public interface Consumable { public void consume (); public abstract class Food implements Consumable
More informationInheritance and Polymorphism
Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationMore on Objects in JAVA TM
More on Objects in JAVA TM Inheritance : Definition: A subclass is a class that extends another class. A subclass inherits state and behavior from all of its ancestors. The term superclass refers to a
More informationOBJECT ORIENTED PROGRAMMING. Course 4 Loredana STANCIU Room B616
OBJECT ORIENTED PROGRAMMING Course 4 Loredana STANCIU loredana.stanciu@upt.ro Room B616 Inheritance A class that is derived from another class is called a subclass (also a derived class, extended class,
More informationInheritance. Transitivity
Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated
More informationAdvanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II
Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationMaking 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 informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationQUESTIONS FOR AVERAGE BLOOMERS
MANTHLY TEST JULY 2017 QUESTIONS FOR AVERAGE BLOOMERS 1. How many types of polymorphism? Ans- 1.Static Polymorphism (compile time polymorphism/ Method overloading) 2.Dynamic Polymorphism (run time polymorphism/
More informationNoSuchElementException 5. Name of the Exception that occurs when you try to read past the end of the input data in a file.
CSC116 Practice Exam 2 - KEY Part I: Vocabulary (10 points) Write the terms defined by the statements below. Cumulative Algorithm 1. An operation in which an overall value is computed incrementally, often
More informationInheritance. Lecture 11 COP 3252 Summer May 25, 2017
Inheritance Lecture 11 COP 3252 Summer 2017 May 25, 2017 Subclasses and Superclasses Inheritance is a technique that allows one class to be derived from another. A derived class inherits all of the data
More informationInformatik II Tutorial 6. Subho Shankar Basu
Informatik II Tutorial 6 Subho Shankar Basu subho.basu@inf.ethz.ch 06.04.2017 Overview Debriefing Exercise 5 Briefing Exercise 6 2 U05 Some Hints Variables & Methods beginwithlowercase, areverydescriptiveand
More informationIntroduction to Inheritance
Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits
More informationChapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,
Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design
More informationjavagently jg3e H:\ ProgTwo Programming II Lecture 7 A case study (class containing an array) and model diagrams. 02/02/2003 Dr Andy Brooks 1
H:\ jg3e javagently ProgTwo Lab3 Laboratory Programming II Lecture 7 A case study (class containing an array) and model diagrams. 02/02/2003 Dr Andy Brooks 1 Scope The scope of an identifier is the region
More informationProgramming overview
Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in
More informationThe software crisis. code reuse: The practice of writing program code once and using it in many contexts.
Inheritance The software crisis software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues:
More informationInheritance and Polymorphism. CSE 114, Computer Science 1 Stony Brook University
Inheritance and Polymorphism CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Model classes with similar properties and methods: Circles, rectangles
More informationHAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.
HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all
More informationAbstract Classes and Interfaces
Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass
More informationInheritance (IS A Relationship)
Inheritance (IS A Relationship) We've talked about the basic idea of inheritance before, but we haven't yet seen how to implement it. Inheritance encapsulates the IS A Relationship. A String IS A Object.
More informationSoftware and Programming 1
Software and Programming 1 Week 9 Lab - Use of Classes and Inheritance 8th March 2018 SP1-Lab9-2018.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab 9: Objectives Exercise 1 Student & StudentTest classes 1.
More informationChapter 14 Abstract Classes and Interfaces
Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationOverriding Variables: Shadowing
Overriding Variables: Shadowing We can override methods, can we override instance variables too? Answer: Yes, it is possible, but not recommended Overriding an instance variable is called shadowing, because
More informationInheritance. The Java Platform Class Hierarchy
Inheritance In the preceding lessons, you have seen inheritance mentioned several times. In the Java language, classes can be derived from other classes, thereby inheriting fields and methods from those
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 09 Inheritance What is Inheritance? In the real world: We have general terms for objects in the real
More informationArgument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.
Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar
More informationCOMP 250: Java Object Oriented Programming
COMP 250: Java Object Oriented Programming January 22-23, 2018 Carlos G. Oliver Slides adapted from M. Blanchette 2 Objects behave according to their kind (Type) Let us turn to Genesis 1:25. "And God made
More informationJAVA Ch. 4. Variables and Constants Lawrenceville Press
JAVA Ch. 4 Variables and Constants Slide 1 Slide 2 Warm up/introduction int A = 13; int B = 23; int C; C = A+B; System.out.print( The answer is +C); Slide 3 Declaring and using variables Slide 4 Declaring
More informationClass, Variable, Constructor, Object, Method Questions
Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx
More informationIntroduction to Computer Science II (CSI 1101) Midterm Examination
Identification Student name: Introduction to Computer Science II (CSI 1101) Midterm Examination Instructor: Marcel Turcotte February 2003, duration: 2 hours Student number: Section: Instructions 1. This
More informationInheritance. Notes Chapter 6 and AJ Chapters 7 and 8
Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg
More informationArrays Classes & Methods, Inheritance
Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value
More informationCMSC131 Final Exam Practice Questions
CMSC131 Final Exam Practice Questions Disclaimer: The following are questions that try to provide you with some practice material for the final exam. By no means do they represent the only material you
More informationIT101. Inheritance, Encapsulation, Polymorphism and Constructors
IT101 Inheritance, Encapsulation, Polymorphism and Constructors OOP Advantages and Concepts What are OOP s claims to fame? Better suited for team development Facilitates utilizing and creating reusable
More informationINHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U
C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes
More informationClasses and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?
Peer Instruction 8 Classes and Objects How can multiple methods within a Java class read and write the same variable? A. Allow one method to reference a local variable of the other B. Declare a variable
More informationFull file at Chapter 2 - Inheritance and Exception Handling
Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a
More informationCreate a Java project named week9
Objectives of today s lab: Through this lab, students will explore a hierarchical model for object-oriented design and examine the capabilities of the Java language provides for inheritance and polymorphism.
More informationCIS 110: Introduction to computer programming
CIS 110: Introduction to computer programming Lecture 25 Inheritance and polymorphism ( 9) 12/3/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Inheritance Polymorphism Interfaces 12/3/2011
More informationModule Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2016-17 PROGRAMMING FOR NON-SPECIALISTS CMP-5020B Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section
More informationJava Magistère BFA
Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt
More informationc) And last but not least, there are javadoc comments. See Weiss.
CSCI 151 Spring 2010 Java Bootcamp The following notes are meant to be a quick refresher on Java. It is not meant to be a means on its own to learn Java. For that you would need a lot more detail (for
More informationCS Programming I: Inheritance
CS 200 - Programming I: Inheritance Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Inheritance
More informationINHERITANCE. Spring 2019
INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose
More informationCS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.
CS 1331 Exam 1 Fall 2016 Name (print clearly): GT account (gpburdell1, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationAP CS Unit 6: Inheritance Notes
AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything
More informationInheritance. A key OOP concept
Inheritance A key OOP concept Setting the scene Why do we need inheritance? Inheritance enables you to define a new class based upon an existing class. The new class is similar to the existing class, but
More information