SlideShare a Scribd company logo
Unit 2 Lesson 2
Defining, Writing and
Instantiating Classes
Remember your Class Diagram?
2
• We are going to turn your Class Diagram from the
last assignment into a working JavaScript Program!
A Couple things about Classes
• When writing pseudocode for classes
• Class definition starts with keyword Class
– Ends with keyword End Class
3
• Defining classes in JavaScript
– Differs from true object-oriented languages
– Define own classes with variables and methods:
• In the <head> section
– Create objects from those classes:
• In the <body> section
• Note: if you use JavaScript in both the <head> and
<body> sections of your HTML file, you need a
separate <script> section for each one
A Couple things about Methods/Functions
• Constructor method should be the listed as first
method - after variables are declared
• Pseudocode for the constructor method starts with
the keywords Constructor Method and ends
with the keywords End Method
• Functions in JavaScript
– Begin with keyword function
• Followed by function name and parameter list
• Statements in the function bod are enclosed with { }
• All statements in a function are indented 3 spaces
• Closing brace lines up under the f in function
• All should be documented (commented)
• Statements are enclosed in braces: { }
4
5
Your task in this lesson is to take your design from the previous lesson and
work it into a working JavaScript program.
Write into your class all properties and methods included in your class design
from Unit 2 Assignment 1.
•Make sure your class makes use of a constructor and appropriate accessor
and mutator methods.
•Make all your methods output some data. (i.e your walk method outputs the
string "The name of the object is walking".)
•At least one of your methods must include the value of one or more of the
object's properties in its output.
•Output the values of all your properties using your accessor methods.
•Call all other methods for your class to generate their output.
Image source: http://www.wpclipart.com/
So, how to start this assignment?
• Open your shell in
Notepad.
• Don’t have a shell?
• Make your life easier
– save some time–
make one.
• This is what mine
looks like, now – it
changes as we add
more.
• I open it and save it
as the current project
name. 6
So, now what?
7
• Add your comments
• Declare your class
variables
• Create your
constructor
• Link the current
object to the class
methods you
created in your
U2A1 Class Diagram
And now…?
8
• Add the methods
you listed in your
U2A1 Class Diagram
• Make sure to
comment each
function.
• Make sure to indent
the function
statements 3 spaces
• Make sure you add
blank lines between
functions for
readability
• Close the head
section
Finally…
9
• In the body welcome
the user and explain
the purpose of the
program.
• Make sure you put a
script tag in the body,
too.
• Create an object
• Call each of your
methods.
• Thank the user and
end the program
• Run your program –
debug and save in
Cloud 9 Unit 2 folder
as U2A2 – Write a Class.
•Submit the U2L1 Class Diagram to the BB Link for comparison.
10
Questions?
Problems?
Concerns?

More Related Content

What's hot

Java
JavaJava
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
Jdbcconnectivitytojava 190804164056
Jdbcconnectivitytojava 190804164056Jdbcconnectivitytojava 190804164056
Jdbcconnectivitytojava 190804164056
SowmyaM45
 
Jdbc connectivity to java
Jdbc connectivity to javaJdbc connectivity to java
Jdbc connectivity to java
SSN College of Engineering, Kalavakkam
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)
David Coulter
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operators
Vivek Kumar
 
MTA understanding java script and coding essentials
MTA understanding java script and coding essentialsMTA understanding java script and coding essentials
MTA understanding java script and coding essentials
Dhairya Joshi
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
Thinkful
 
Functional js class
Functional js classFunctional js class
Functional js class
Brian Lonsdorf
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Marlon Jamera
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
Muhammad Hammad Waseem
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
TJ Stalcup
 
[OOP - Lec 03] Programming Paradigms
[OOP - Lec 03] Programming Paradigms[OOP - Lec 03] Programming Paradigms
[OOP - Lec 03] Programming Paradigms
Muhammad Hammad Waseem
 
Javascript 01 (js)
Javascript 01 (js)Javascript 01 (js)
Javascript 01 (js)
AbhishekMondal42
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Bhanuka Uyanage
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
James Johnson
 
Web development basics (Part-7)
Web development basics (Part-7)Web development basics (Part-7)
Web development basics (Part-7)
Rajat Pratap Singh
 
OCLC Connexion Client Efficiency Tools
OCLC Connexion Client Efficiency ToolsOCLC Connexion Client Efficiency Tools
OCLC Connexion Client Efficiency Tools
Georgia Libraries Conference (formerly Ga COMO).
 

What's hot (20)

Java
JavaJava
Java
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
Jdbcconnectivitytojava 190804164056
Jdbcconnectivitytojava 190804164056Jdbcconnectivitytojava 190804164056
Jdbcconnectivitytojava 190804164056
 
Jdbc connectivity to java
Jdbc connectivity to javaJdbc connectivity to java
Jdbc connectivity to java
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operators
 
MTA understanding java script and coding essentials
MTA understanding java script and coding essentialsMTA understanding java script and coding essentials
MTA understanding java script and coding essentials
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
 
Functional js class
Functional js classFunctional js class
Functional js class
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
 
[OOP - Lec 03] Programming Paradigms
[OOP - Lec 03] Programming Paradigms[OOP - Lec 03] Programming Paradigms
[OOP - Lec 03] Programming Paradigms
 
Javascript 01 (js)
Javascript 01 (js)Javascript 01 (js)
Javascript 01 (js)
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
 
Web development basics (Part-7)
Web development basics (Part-7)Web development basics (Part-7)
Web development basics (Part-7)
 
OCLC Connexion Client Efficiency Tools
OCLC Connexion Client Efficiency ToolsOCLC Connexion Client Efficiency Tools
OCLC Connexion Client Efficiency Tools
 

Similar to U2A2

Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
agorolabs
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objects
kjkleindorfer
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Srikrishnan Suresh
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
Connex
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Sachintha Gunasena
 
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Intro To C++ - Class 07 - Headers, Interfaces, & PrototypesIntro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Blue Elephant Consulting
 
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class pptCore Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
Mochi263119
 
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class pptCore Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
Mochi263119
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
Jan Niño Acierto
 
Java
JavaJava
Java Script
Java ScriptJava Script
Java Script
Sarvan15
 
Java Script
Java ScriptJava Script
Java Script
Sarvan15
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
Muhammad Younis
 
Chap01
Chap01Chap01
Chap01
Jotham Gadot
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 
New operator and methods.15
New operator and methods.15New operator and methods.15
New operator and methods.15
myrajendra
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
Hemlathadhevi Annadhurai
 
Java Programming Fundamentals
Java Programming Fundamentals Java Programming Fundamentals
Java Programming Fundamentals
Dr. Rosemarie Sibbaluca-Guirre
 
CONSTRUCTORS.pptx
CONSTRUCTORS.pptxCONSTRUCTORS.pptx
CONSTRUCTORS.pptx
SaraswathiVelmurugan1
 

Similar to U2A2 (20)

Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Week10 packages using objects in objects
Week10 packages using objects in objectsWeek10 packages using objects in objects
Week10 packages using objects in objects
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1
 
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Intro To C++ - Class 07 - Headers, Interfaces, & PrototypesIntro To C++ - Class 07 - Headers, Interfaces, & Prototypes
Intro To C++ - Class 07 - Headers, Interfaces, & Prototypes
 
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class pptCore Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
 
Core Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class pptCore Java unit no. 1 object and class ppt
Core Java unit no. 1 object and class ppt
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
 
Java
JavaJava
Java
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
 
Chap01
Chap01Chap01
Chap01
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
New operator and methods.15
New operator and methods.15New operator and methods.15
New operator and methods.15
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
 
Java Programming Fundamentals
Java Programming Fundamentals Java Programming Fundamentals
Java Programming Fundamentals
 
CONSTRUCTORS.pptx
CONSTRUCTORS.pptxCONSTRUCTORS.pptx
CONSTRUCTORS.pptx
 

More from pfefferteacher

Standard form solve equations
Standard form solve equationsStandard form solve equations
Standard form solve equations
pfefferteacher
 
Croatia
CroatiaCroatia
Travel slide share
Travel slide shareTravel slide share
Travel slide share
pfefferteacher
 
Grade bumps
Grade bumpsGrade bumps
Grade bumps
pfefferteacher
 
Grade bumps
Grade bumpsGrade bumps
Grade bumps
pfefferteacher
 
How to check your grades
How to check your gradesHow to check your grades
How to check your grades
pfefferteacher
 

More from pfefferteacher (6)

Standard form solve equations
Standard form solve equationsStandard form solve equations
Standard form solve equations
 
Croatia
CroatiaCroatia
Croatia
 
Travel slide share
Travel slide shareTravel slide share
Travel slide share
 
Grade bumps
Grade bumpsGrade bumps
Grade bumps
 
Grade bumps
Grade bumpsGrade bumps
Grade bumps
 
How to check your grades
How to check your gradesHow to check your grades
How to check your grades
 

Recently uploaded

BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
Celine George
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 

Recently uploaded (20)

BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 

U2A2

  • 1. Unit 2 Lesson 2 Defining, Writing and Instantiating Classes
  • 2. Remember your Class Diagram? 2 • We are going to turn your Class Diagram from the last assignment into a working JavaScript Program!
  • 3. A Couple things about Classes • When writing pseudocode for classes • Class definition starts with keyword Class – Ends with keyword End Class 3 • Defining classes in JavaScript – Differs from true object-oriented languages – Define own classes with variables and methods: • In the <head> section – Create objects from those classes: • In the <body> section • Note: if you use JavaScript in both the <head> and <body> sections of your HTML file, you need a separate <script> section for each one
  • 4. A Couple things about Methods/Functions • Constructor method should be the listed as first method - after variables are declared • Pseudocode for the constructor method starts with the keywords Constructor Method and ends with the keywords End Method • Functions in JavaScript – Begin with keyword function • Followed by function name and parameter list • Statements in the function bod are enclosed with { } • All statements in a function are indented 3 spaces • Closing brace lines up under the f in function • All should be documented (commented) • Statements are enclosed in braces: { } 4
  • 5. 5 Your task in this lesson is to take your design from the previous lesson and work it into a working JavaScript program. Write into your class all properties and methods included in your class design from Unit 2 Assignment 1. •Make sure your class makes use of a constructor and appropriate accessor and mutator methods. •Make all your methods output some data. (i.e your walk method outputs the string "The name of the object is walking".) •At least one of your methods must include the value of one or more of the object's properties in its output. •Output the values of all your properties using your accessor methods. •Call all other methods for your class to generate their output. Image source: http://www.wpclipart.com/
  • 6. So, how to start this assignment? • Open your shell in Notepad. • Don’t have a shell? • Make your life easier – save some time– make one. • This is what mine looks like, now – it changes as we add more. • I open it and save it as the current project name. 6
  • 7. So, now what? 7 • Add your comments • Declare your class variables • Create your constructor • Link the current object to the class methods you created in your U2A1 Class Diagram
  • 8. And now…? 8 • Add the methods you listed in your U2A1 Class Diagram • Make sure to comment each function. • Make sure to indent the function statements 3 spaces • Make sure you add blank lines between functions for readability • Close the head section
  • 9. Finally… 9 • In the body welcome the user and explain the purpose of the program. • Make sure you put a script tag in the body, too. • Create an object • Call each of your methods. • Thank the user and end the program • Run your program – debug and save in Cloud 9 Unit 2 folder as U2A2 – Write a Class. •Submit the U2L1 Class Diagram to the BB Link for comparison.