CS 302 Week 9 Jim Williams.

Slides:



Advertisements
Similar presentations
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Advertisements

1 SSD3 - Unit 2 Java toString & Equals Presentation Class Website:
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Road Map Introduction to object oriented programming. Classes
CPSC150 Inheritance Details Chapter 9. CPSC150 Print in Entertainment ver 2 (with inheritance): public void print() { System.out.print("title: " + title.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Scanner class for input Instantiate a new scanner object Scanner in = new Scanner(System.in); Getting input using scanner – int i = scanner.nextInt() –
Writing a Class (defining a data-type). Create a new project : Project (uncheck the “Create Main Class”)
UML Basics & Access Modifier
Encapsulation CMSC 202. Types of Programmers Class programmers – Developers of new classes – Goal: Expose the minimum interface necessary to use a new.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
ECE122 Feb. 22, Any question on Vehicle sample code?
10-Nov-15 Java Object Oriented Programming What is it?
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Objects & Classes Weiss ch. 3. So far: –Point (see java.awt.Point) –String –Arrays of various kinds –IPAddress (see java.net.InetAddress) The Java API.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes Modeling the Object. Objects model the world Classes are programmer defined types that model the parts of a system Class serve as blueprints for.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Classes and Objects CS177 Rec 10. Announcements Project 4 is posted ◦ Milestone due on Nov. 12. ◦ Final submission due on Nov. 19. Exam 2 on Nov. 4 ◦
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Recitation 8 User Defined Classes Part 2. Class vs. Instance methods Compare the Math and String class methods that we have used: – Math.pow(2,3); – str.charAt(4);
More on Objects Mehdi Einali Advanced Programming in Java 1.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
CS1101 Group1 Discussion 6 Lek Hsiang Hui comp.nus.edu.sg
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
Topics Instance variables, set and get methods Encapsulation
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Advanced Programming in Java
CS Week 14 Jim Williams, PhD.
CS 302 Week 11 Jim Williams, PhD.
Advanced Programming in Java
CS Week 13 Jim Williams, PhD.
CS 200 Creating Classes Jim Williams, PhD.
CS 302 Week 10 Jim Williams.
CS Week 8 Jim Williams, PhD.
CS 200 More Classes Jim Williams, PhD.
Week 6 CS 302 Jim Williams, PhD.
Today’s topics UML Diagramming review of terms
Inheritance Inheritance is a fundamental Object Oriented concept
CS 200 Additional Topics and Review
Simple Classes in Java CSCI 392 Classes – Part 1.
Assessment – Java Basics: Part 1
Basics of OOP A class is the blueprint of an object.
CS 200 Additional Topics and Review
Object-Oriented Programming
CIS 199 Final Review.
CS 200 Creating Classes Jim Williams, PhD.
Web Design & Development Lecture 4
Chapter 11 Inheritance and Polymorphism Part 2
CS 200 More Classes Jim Williams, PhD.
CS 200 Creating Classes Jim Williams, PhD.
Barb Ericson Georgia Institute of Technology Oct 2005
CS302 Week 6 Jim Williams.
CS 200 Additional Topics and Review
CS 240 – Advanced Programming Concepts
CSG2H3 Object Oriented Programming
Chapter 5 Classes.
Presentation transcript:

CS 302 Week 9 Jim Williams

Note: For this correlation, we can't claim TopHat causes higher midterm score simply because it occurred before midterm. There could be something else (e.g., attendance) that influences both. https://learnuw.wisc.edu/toolbox/tophat.html

Mid term Evaluations: Other Resources 30 min delay

This Week Program 3 Pants on Fire Focus Partners & Milestone 1 due by Thursday Objects (Instances) and Classes Conceptual Level and Code Level

Classes and Objects public, private, protected, <package> accessors (getters),mutators (setters) state of an object constructor overloading this constructor, no-arg, default

Visibility Modifiers For members of a class: public private protected <package> Demo

Can methodA call methodB? //classes in different files in same package class A { public void methodA() { methodB(); } class B { void methodB() { yes no depends error

Can a method outside the package call methodA()? //classes in different files in same package class A { public void methodA() { methodB(); } class B { void methodB() { yes no depends error

Accessors (getters) class Pizza { private String toppings; public String getToppings() { if ( toppings == null) toppings = "no toppings"; return toppings; }

Mutators (setters) class Pizza { private String toppings; public void setToppings( String tops) { if ( tops != null && tops.length() > 0) toppings = tops; }

Can a setter also get? yes class Pizza { no private String toppings; public String setToppings( String tops) { String previous = toppings; toppings = tops; return previous; } yes no depends error

Object/Instance State enum Color {GREEN,YELLOW, RED}; class TrafficLight{ private Color color = Color.RED; public void change() { if ( color == Color.GREEN) color = Color.YELLOW; else if ( color == Color.YELLOW) color = Color.RED; else color = Color.GREEN; } public Color getColor() { return color; } public String toString() { return color.name(); }

What variables are used for the state of "instance who's reference is in p"? class Person { private static count = 0; private boolean amHungry = false; public Person( String name) { } } public static void main(String []args) { Person p = new Person("Fred"); count name amHungry error/other

this class Picture { private boolean hasFrame; public Picture( boolean hasFrame) { this.hasFrame = hasFrame; }

Does this print true or false? class Person { static count = 0; private boolean something = false; boolean getThing(boolean something) { return this.something; } Person p = new Person(); System.out.println( p.getThing( true)); true false error/other

Does this print 0, 1, other or error? class Person { static count = 0; private boolean something = false; Person(boolean something) { this.something = something; count++; } System.out.println( Person.count); 1 other error

Default Constructor class Person { private String name; } Can we create an instance? Person p = new Person();

Constructor Overloading class Person { private String name; Person() { this("no name"); } Person(String name) { this.name = name;

Constructors yes - the default, no argument constructor yes - a really good one. no error If there is no constructor in a class is a constructor automatically provided by the compiler?

Will the no-argument constructor be provided in this case? class Cup { private String contents; Cup(String contents) { this.contents = contents; } yes - there is not a no-arg constructor no yes - why not? error

More Classes and Objects class, instance, object field, attribute, instance variable toString() instance method, overriding this, super printing object