Constructing Objects Lab. Log into Wiley Plus Read the problem Write a BankAccountTester class whose main method constructs a bank account, deposits.

Slides:



Advertisements
Similar presentations
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
***** SWTJC STEM ***** Chapter 4-1 cg 42 Object Oriented Program Terms Up until now we have focused on application programs written in procedural oriented.
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
1 Objects, Classes, and Packages “Static” Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Chapter 3 – Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To.
Chapter 3 Implementing Classes. Instance Variables Instance variables store the data of an object; the fields of an object. Instance of a class: an object.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Assignment I, part 1. Groups of three students. Specify one as group leader. group names to TA and me. Create an object-oriented conceptualization.
Chapter 2 – An Introduction to Objects and Classes Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Chapter 14: Overloading and Templates
Basic Logarithms A way to Undo exponents. Many things we do in mathematics involve undoing an operation.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Chapter 3 Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
Basic Logarithms A way to Undo exponents. Many things we do in mathematics involve undoing an operation.
Introduction to Objective-C and Xcode (Part 2) FA 175 Intro to Mobile App Development.
Glenn David Blank Computer Science & Engineering Department Lehigh University, Bethlehem, PA, USA With support from the National Science Foundation (Grants.
Introduction to Object-Oriented Programming
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Introduction to Object Oriented Design Version 1.1.
An OOP Example ACO 101: Intro to CS. Engineer the illusion of simplicity.
Object-Oriented Programming in C++
Classes CS 21a: Introduction to Computing I First Semester,
Chapter 3 Implementing Classes. Assignment Read 3.1 – 3.5 and take notes complete Self Check Exercises 1-10; Due September 24 th Read 3.6 – 3.8 and take.
ACO 101 Instantiating Graphic Objects. Review: 4 Phases to the Development Lifecycle Inception (Analysis & Design) – Business Requirements Business Analyst.
Copyright © 2002, Systems and Computer Engineering, Carleton University a-JavaReview.ppt * Object-Oriented Software Development Unit.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
Lesson 2 – Adding Fraction Pictures
Session 02 and 03: C# OOP 1 OOP in C#: Classes and Objects in C#. Object-Oriented Design. UML Class Diagram. Object Interaction. FEN AK IT:
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
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.
Constructors & Garbage Collection Ch. 9 – Head First Java.
Using Objects. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L7: Objects Slide 2 Java.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Problem 1 Bank.  Manage customers’ bank account using the following operations: Create a new account given a customer’s name and initial account. Deposit.
Scheme -> Java Conversion Course 2001 Lab Session 2/2.
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 Introduction to Object Oriented Programming Chapter 10.
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Chapter 3 Implementing Classes
Designing Classes Lab. The object that you brought to class Put it in the basket we will exchange them now.
Solving Equations A-REI.B.3:Solving equations with a variable on one side, using inverse operations.
Python programming - Defining Classes
Lecture 3 John Woodward.
CSSE 120—Rose Hulman Institute of Technology
Introduction to Objects
Math in C The math blocks you've used in Scratch can all be recreated in C!
Chapter Three - Implementing Classes
Writing Methods AP Computer Science A.
February , 2009 CSE 113 B.
Classes CS 21a: Introduction to Computing I
Introduction to Object-Oriented Programming
Nate Brunelle Today: Functions again, Scope
References Revisted (Ch 5)
Lecture 20 – Practice Exercises 4
Introduction to Computer Science and Object-Oriented Programming
Introduction to Objects
Presentation transcript:

Constructing Objects Lab

Log into Wiley Plus

Read the problem Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result. Your tester class should be called BankAccountTester. Use the following class in your solution: [Wplus gives you the BankAccount class code here]

Now You probably feel overwhelmed. You think: What do I do next? You react: Somebody tell me what to do. Professor reaction: take a deep breath, clear your mind and remember…..

….what Eric Berlow said: “Hone in on the sphere of influence that matters most.”

What matters most? There are 2 classes Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result. Your tester class should be called BankAccountTester. Use the following class in your solution: [Wplus gives you the BankAccount class code here]

What matters about the BankAccountTester? You have to write it and BankAccountTester has a main method that constructs a BankAccount and then invokes the methods of the Bank Account and then prints the results. Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result. Your tester class should be called BankAccountTester. Use the following class in your solution: [Wplus gives you the BankAccount class code here]

What matters about the BankAccount class? It is already written for you. You need to understand its structure {You gotta know what is in it.} How do we understand class structures? – Make a UML Class Diagram

Writing a UML Class Diagram to reverse engineer code: Remember the 3 parts of Object Anatomy: name, attributes, methods What is the name of the class?

Name in a Class Diagram

What are the Attributes?

What are the methods

Where is the constructor and are there any overloads?

Where does the constructor go in the class diagram? A constructor is a method that is called when you create a NEW object; the scope is “classifier” instead of “instance”

To add parameters: Click on Properties with the desired constructor highlighted

Go to Parameters and add the name of the parameter, the datatype and kind

Class diagram completed

Remember there are 2 classes The BankAccount and the BankAccountTester

What does the BankAccountTester class look like? What do the words in the problem tell us? “Write a BankAccountTester class whose main method” We know the name of the class and a method name

Now ask yourself… How do these 2 classes interact? What type of diagram will help me understand how they interact? – Sequence Diagram

Put in the object lifelines for each of the objects; there is no instance name for the tester

Why isn't there a instance name for the Tester? Because a tester class is a class with a main method that contains statements to run methods of another class It is the class that makes the calls to the instance of classes [objects] It will occupy space in memory when running but we will not create NEW The main method kicks off the program

Just like a carburetor cant run all by itself and must live in a car to work; a class needs to live in a program Tester class Instance of a class AKA an object

Back to the problem: what is the first thing the tester does? Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result.

What is the second thing the tester does? Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result.

What is the third thing the tester does? Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result.

What is the fourth thing the tester does? Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result.

What is the Fifth thing the tester does? Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result. Question: is there a dependent operation that must be performed to print the balance? Answer: yes, you have to get the balance before you can print it.

Fifth: Get the balance

And print it

What is the sixth thing the tester does? Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result.

Now you have a picture of the program and it is time to code.

Launch LabRat and make the file BankAccountTester.java

Construct a new bank account object

Make a deposit [if you don’t remember how to invoke a method go back to object anatomy and look at the method ppt again]

Withdraw

withdraw

Get balance and assign to a variable if you don’t remember how to declare and add value to a variable go back and look at the API lecture

Print balance

Print expected result

Now submit to LabRat and see what happens.