Day 5. Task: Implement your vending machine code into the program with JOptionPane I/O (modify it) E-mail it to me.

Slides:



Advertisements
Similar presentations
DONT PANIC!! Lots of new notions coming in these slides Dont worry if not all of it makes perfect sense Well meet most of this stuff again in detail later.
Advertisements

The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Chapter 4 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference l Parameter passing Classes, Objects, and Methods.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
What is an object? Your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior;
Classes, Objects, and Methods
COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Chapter 9: Classes with Instance Variables or Classes=Methods+Variables Asserting Java © Rick Mercer.
Week 3 Recap CSE 115 – Spring Constructor Special capability of a class that sets up the initial state of the object. Constructor definitions are.
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
Java Objects and Classes. 3-2 Object Oriented Programming  An OO program models the application as a world of interacting objects.  A typical Java program.
Intro to CS – Honors I Classes and Methods GEORGIOS PORTOKALIDIS
COMP Classes Yi Hong May 22, Announcement  Lab 2 & 3 due today.
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Writing Classes (Chapter 4)
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
The Java Programming Language
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Bryce Canyon, Utah CSE 114 – Computer Science I Objects and Reference.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 4Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 4 l Class and Method Definitions l Information Hiding and Encapsulation.
Classes, Objects, and Methods. Overview n What are classes, objects, and methods? n Using objects and methods n Declaring classes and methods n Information.
Lecture 9 Using Objects. Remember: 3 Different Kinds of Classes 1.Application Class – what we've been doing – Has public static void main ( String []
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
COMP 150: Introduction to Object-Oriented Programming Lecturer: Dr. AJ Bieszczad 4-1 Chapter 4 l Class and Method Definitions l Information Hiding and.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Introduction To Scientific Programming Chapter 4 – Defining Classes and Methods.
Identifiers Identifiers in Java are composed of a series of letters and digits where the first character must be a letter. –Identifiers should help to.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Methods. Overview Class/Library/static vs. Message/non-static return and void Parameters and arguments.
COMP 110 Worksheet review, debugger Luv Kohli September 29, 2008 MWF 2-2:50 pm Sitterson 014.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
COMP 110 Classes Luv Kohli October 1, 2008 MWF 2-2:50 pm Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 16, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Class and Method Definitions. UML Class Diagram Automobile - fuel: double - speed: double - license: String + increaseSpeed(double howHardPress): void.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Class Definitions: The Fundamentals Chapter 6 3/30/15 & 4/2/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
CS16: UML’s Unified Modeling Language. UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has.
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 21, 2011
3 Introduction to Classes and Objects.
Interface, Subclass, and Abstract Class Review
CompSci 230 Software Construction
OBJECT ORIENTED CONCEPTS
Winter 2018 CMPE212 9/21/2018 CMPE212 – Stuff…
Dr Shahriar Bijani Winter 2017
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Unit-2 Objects and Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Defining Classes and Methods
Examples of Primitive Values
Implementing Classes Chapter 3.
Object Oriented Programming in java
Defining Classes and Methods
Defining Classes and Methods
Classes, Objects and Methods
Announcements Assignment 2 and Lab 4 due Wednesday.
Presentation transcript:

Day 5

Task: Implement your vending machine code into the program with JOptionPane I/O (modify it) it to me

4.1 Class and Method Definitions Objects can represent objects in the real world, like automobiles, houses, employee records, and so forth

4.1 Class and Method Definitions Objects can represent objects in the real world, like automobiles, houses, student records, and so forth. A class is the definition of a kind of object. The class is a general description of what an automobile (or object) can do.

A Class as an Outline Class Name: Automobile Data: amount of fuel ____________ speed ___________ license plate ____________ Methods (actions) increase Speed: How: Press on gas pedal. stop: How: Press on brake pedal.

An object that satisfies the class definition of an Automobile is said to instantiate the Automobile class. Thus, objects are individual automobiles, while the Automobile class is a description of what an automobile is and does.

A Class as an Outline Class Name: Automobile Data: amount of fuel ____________ speed ___________ license plate ____________ Methods (actions) increase Speed: How: Press on gas pedal. stop: How: Press on brake pedal.

Instantiations of the Class Automobile: Object Name: SamsCar Data: amount of fuel: 10 gallons speed: 55 mph license plate: “135 XJK” First Instantiation

Instantiations of the Class Automobile: Object Name: SamsCar Data: amount of fuel: 10 gallons speed: 55 mph license plate: “135 XJK” Object Name: WillsCar Data: amount of fuel: 12 gallons speed: 51 mph license plate: “153 ZSA” First Instantiation Second Instantiation

In a program that uses the class Automobile, the only actions an Automobile can take are increaseSpeed and stop. These actions are called methods. All objects of the class Automobile have the same methods.

UML class diagram There’s no way we are gonna keep writing out large descriptions of Automobile as we just did. There’s quick way of describing the task to the programmer: UML stands for Universal Modeling Language, or we can simply call it a class diagram.

A Class Outline as a UML Class Diagram Automobile -fuel: double -speed: double -License: String + increaseSpeed(double howHardPress): void + stop(double howHardPress): void Class Name Data Methods (actions)

Instance Variables The data is referred to as instance variables We will call the methods methods

Instance Variables The following lines from the start of the class definition define three instance variables: public double fuel; public double speed; public String license;

Let’s write out the class Automobile

Now let’s write the main program In a new file with a different class name, which includes the line public static void main (String [] args) we will create an object of Automobile

In File #2 To create our first object, we write in the body Automobile SamsCar = new Automobile();

In File #2 To create our first object, we write in the body Automobile SamsCar = new Automobile();

Using Methods When you use a method, you are said to invoke or call it. You have already invoked methods. For example, your programs have invoked nextInt() with objects of the class Scanner.

Types of Methods There are two kinds of methods: (1) those that return a single value (2) those that perform some action other than returning a single value

Quotation “There are two kinds of people in the world, those that divide the world into two and those that don’t”

Finish the main file together

Write out the class and its methods.. Give it a shot we’ll take it up later