BCS 2143 Object Oriented Programming Defining Your Own Classes (Part 1)

Slides:



Advertisements
Similar presentations
Chapter 6 Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and.
Advertisements

©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four Defining Your Own Classes.
Programmer-defined classes Part 2. Topics Returning objects from methods The this keyword Overloading methods Class methods Packaging classes Javadoc.
Discussion 3. Questions? Term test? Lectures? Labs?
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Road Map Introduction to object oriented programming. Classes
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes Part 1.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four: Defining Your Own Classes *Instantiable.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four: Defining Your Own Classes *Instantiable.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes Part 1 Animated.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Introduction to methods Chapter 5: Classes and Objects in Depth.
بسم الله الرحمن الرحيم CPCS203: Programming II. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display., Modifications by Dr.
Chapter Chapter 4 Defining Your Own Classes Part 1.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Chapter 3b Standard Input and Output Sample Development.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Sample Development Revisiting the Loan.
Chapter Four Defining Your Own Classes continued.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
CS1101X: Programming Methodology Recitation 2 Classes.
Develop Instantiable classes (continue). Exam 1 – section 02 Avg = 131 (87%). Max: 148.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Why Programmer-Defined Classes Using just the String,
Defining Your Own Classes Part 3. class { } Template for Class Definition Import Statements Class Comment Class Name Data Members Methods (incl. Constructor)
Writing Classes (Chapter 4)
Chapter 10 METHODS AND CONSTRUCTORS 1. Accessing Objects  Referencing the object’s data: objectReference.data myCircle.radius  calling the object’s.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 4 Defining Your Own Classes Part 1 Animated Version.
1 Objects and Classes. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object represents an entity.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Classes CS 21a: Introduction to Computing I First Semester,
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
CS1101X: Programming Methodology Recitation 1 Java Basics Numerical Data.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
1.  At the end of this slide, student able to:  Object-Oriented Programming  Research on OOP features.  Do a code walkthrough to examine the implementation.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Objects and Classes Mostafa Abdallah
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Methods: A Deeper Look. Template for Class Definition public class { } A.Import Statement B.Class Comments C.Class Name D.Data members E.Methods (inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Object- Oriented Programming (CS243) Dr Walid M. Aly lec4 1 Dr Walid M. Aly 1 Lecture 4 Object- Oriented Programming (CS243) Group home page:
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
DCS 2133 Object Oriented Programming Defining Your Own Classes Part 2.
Classes and Objects. Object Software objects are modeled after real-world objects in that they, too, have state and behavior. A software object maintains.
Introduction To Objects Oriented Programming Instructor: Mohammed Faisal.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 4 Defining Your Own Classes Part 1 Animated Version.
1 Class and Object Lecture 7. 2 Classes Classes are constructs that define objects of the same type. A Java class uses instance variables to define data.
Classes and Objects. How can one design a program?  Top-down structured design: uses algorithmic decomposition where each module denotes a major step.
Classes and Objects. Object vs. Class Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2  A class could be considered as a set of objects having.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
Dr. Majed Abdouli © Objects and Classes 1 Dr. Majed Abdouli © 2015, adapted from Liang, Introduction to Java Programming, Eighth Edition, (c) 2011.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Chapter 4 : Defining Your Own Classes Part 1 - Objectives After you have read and studied this chapter, you should be able to Define a class with multiple.
More About Objects and Methods
Chapter 4 Defining Instantiable Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
Defining Your Own Classes Part 1
Defining Your Own Classes
Chapter 5: Classes and Objects in Depth
OO Programming Concepts
Chapter 9 Introduction To Classes
Chapter 7 Objects and Classes
Presentation transcript:

BCS 2143 Object Oriented Programming Defining Your Own Classes (Part 1)

BCS 2143 Object Oriented Programming Objectives Define a class with multiple methods and data members Differentiate the local and instance variables Define and use value-returning methods Distinguish private and public methods Distinguish private and public data members Learn how to create an object of a class Understand the role of constructors when creating objects Pass both primitive data and objects to a method

BCS 2143 Object Oriented Programming 1. Why Programmer-Defined Classes Using just the String, GregorianCalendar, JFrame and other standard classes will not meet all of our needs. We need to be able to define our own classes customized for our applications. Learning how to define our own classes is the first step toward mastering the skills necessary in building large programs. Classes we define ourselves are called programmer- defined classes.

BCS 2143 Object Oriented Programming Example : Class Diagram for Bicycle Method Listing We list the name and the data type of an argument passed to the method. Method Listing We list the name and the data type of an argument passed to the method. Bicycle setOwnerName(String) Bicycle( ) getOwnerName( ) ownerName

BCS 2143 Object Oriented Programming The definition of the Bicycle class class Bicycle { // Data Member private String ownerName; //Constructor: Initializes the data member public Bicycle( ) { ownerName = "Unknown"; } //Returns the name of this bicycle's owner public String getOwnerName( ) { return ownerName; } //Assigns the name of this bicycle's owner public void setOwnerName(String name) { ownerName = name; }

BCS 2143 Object Oriented Programming Test class for the Bicycle class class BicycleRegistration { public static void main(String[] args) { Bicycle bike1, bike2; String owner1, owner2; bike1 = new Bicycle( ); //Create and assign values to bike1 bike1.setOwnerName("Adam Smith"); bike2 = new Bicycle( ); //Create and assign values to bike2 bike2.setOwnerName("Ben Jones"); owner1 = bike1.getOwnerName( ); //Output the information owner2 = bike2.getOwnerName( ); System.out.println(owner1 + " owns a bicycle."); System.out.println(owner2 + " also owns a bicycle."); }

BCS 2143 Object Oriented Programming MethodParameterDescription BicycleNoneInitializes the owner’s name to Unassigned getOwnerNameNoneReturns the owner’s name setOwnerNameName of the owner(String) Assigns the bicycle owner’s name to the passed value. The three methods of the Bicycle class. The first method is called a constructor.

BCS 2143 Object Oriented Programming Multiple Instances Once the Bicycle class is defined, we can create multiple instances. Bicycle bike1, bike2; bike1bike2 : Bicycle ownerName : Bicycle ownerName “Adam Smith” “Ben Jones” bike1 = new Bicycle( ); bike1.setOwnerName("Adam Smith"); bike2 = new Bicycle( ); bike2.setOwnerName("Ben Jones"); Sample Code

BCS 2143 Object Oriented Programming The Program Structure and Source Files BicycleRegistrationBicycle There are two source files. Each class definition is stored in a separate file. BicycleRegistration.javaBicycle.java

BCS 2143 Object Oriented Programming class { } Template for Class Definition Import Statements Class Comment Class Name Data Members Methods (incl. Constructor) Methods (incl. Constructor)

BCS 2143 Object Oriented Programming Class Declaration * class { * } * class { * } public class Person{ private String name; public Person() { } public void setName (String n) { name = n ; } Class definition structure Example

BCS 2143 Object Oriented Programming Data Member Declaration ; Private/public String ownerName ; Modifiers Data Type Name

BCS 2143 Object Oriented Programming Methods : Accessor and Mutators Accessor = a method that returns information about an object. Usually starts with word get……. Example : getOwnerName() Mutator = a method that sets a property of an object. Usually starts with word set…… Example : setOwnerName()

BCS 2143 Object Oriented Programming Method Declaration - set ( ){ } public void setOwnerName ( String name ) { ownerName = name; } Statements Modifier Return Type Method Name Parameter

BCS 2143 Object Oriented Programming Method Declaration - get ( ){ } public String getOwnerName ( ) { return ownerName; } Statements Modifier Return Type Method Name Parameter

BCS 2143 Object Oriented Programming Another example of get & set methods Public class Cat{ private int weight; public int getWeight(){ return weight; } public void setWeight(int newWeight){ if( newWeight > 0 ){ weight = newWeight ; } Public class Cat{ private int weight; public int getWeight(){ return weight; } public void setWeight(int newWeight){ if( newWeight > 0 ){ weight = newWeight ; }

BCS 2143 Object Oriented Programming Constructor A constructor is a special method that is executed when a new instance of the class is created. public ( ){ } public Bicycle ( ) { ownerName = "Unassigned"; } Statements Modifier Class Name Parameter

BCS 2143 Object Oriented Programming Constructors, cont.. A constructor with no parameters is referred to as a no-arg constructor. Constructors are a special kind of method with three differences : 1.Must have the same name as the class itself. 2.Do not have a return type—not even void. 3.Invoked using the new operator when an object. is created. Constructors play the role of initializing objects.

BCS 2143 Object Oriented Programming Default Constructor A class may be declared without constructors. In this case, a no-arg constructor with an empty body is implicitly declared in the class. This constructor is known as default constructor. It is provided automatically only if no constructors are explicitly declared in the class.

BCS 2143 Object Oriented Programming Declaring Object Reference Variables To reference an object, assign the object to a reference variable. To declare a reference variable, use the syntax: ClassName objectRefVar; e.g : Bicycle bike; Object can be declared and created in one line. ClassName objectRefVar = new ClassName(); e.g : Bicycle bike = new Bicycle();

BCS 2143 Object Oriented Programming Accessing Objects Referencing the object’s data: objectRefVar.data e.g: bike.ownerName Invoking the object’s method: objectRefVar.methodName(arguments) e.g: bike.setOwnerName(“Jon Java”)

BCS 2143 Object Oriented Programming bike : Bicycle ownerName “Unassigned” bike : Bicycle ownerName “Jon Java” bike Bicycle bike; bike = new Bicycle(); Bicycle bike; bike = new Bicycle(); bike.setOwnerName(“Jon Java”)

BCS 2143 Object Oriented Programming 2. Second Example: Using Bicycle and Account class SecondMain { //This sample program uses both the Bicycle and Account classes public static void main(String[] args) { Bicycle bike; Account acct; String myName = "Jon Java"; bike = new Bicycle( ); bike.setOwnerName(myName); acct = new Account( ); acct.setOwnerName(myName); acct.setInitialBalance(250.00); acct.add(25.00); acct.deduct(50); //Output some information System.out.println(bike.getOwnerName() + " owns a bicycle and"); System.out.println("has $ " + acct.getCurrentBalance() + " left in the bank"); }

BCS 2143 Object Oriented Programming The Account Class class Account { private String ownerName; private double balance; public Account( ) { ownerName = "Unassigned"; balance = 0.0; } public void add(double amt) { balance = balance + amt; } public void deduct(double amt) { balance = balance - amt; } public double getCurrentBalance( ) { return balance; } public String getOwnerName( ) { return ownerName; } public void setInitialBalance (double bal) { balance = bal; } public void setOwnerName (String name) { ownerName = name; } Page 1Page 2

BCS 2143 Object Oriented Programming The Program Structure for SecondMain SecondMainBicycle SecondMain.javaBicycle.javaAccount.java Account

BCS 2143 Object Oriented Programming 3. Arguments and Parameters An argument is a value we pass to a method class Account {... public void add(double amt) { balance = balance + amt; }... } class Sample { public static void main(String[] arg) { Account acct = new Account();... acct.add(400);... }... } argument parameter A parameter is a placeholder in the called method to hold the value of the passed argument.

BCS 2143 Object Oriented Programming Matching Arguments and Parameters The number or arguments and the parameters must be the same class Demo { public void compute(int i, int j, double x) {... } Demo demo = new Demo( ); int i = 5; int k = 14; demo.compute(i, k, 20); 3 arguments 3 parameters The matched pair must be assignment- compatible (e.g. you cannot pass a double argument to a int parameter) Arguments and parameters are paired left to right Passing Side Receiving Side

BCS 2143 Object Oriented Programming Memory Allocation Separate memory space is allocated for the receiving method. Passing Side i5 k Receiving Side i j x Values of arguments are passed into memory allocated for parameters. Literal constant has no name

BCS 2143 Object Oriented Programming 4. Passing Objects to a Method As we can pass int and double values, we can also pass an object to a method. When we pass an object, we are actually passing the reference (name) of an object –it means a duplicate of an object is NOT created in the called method

BCS 2143 Object Oriented Programming Sharing an Object We pass the same Student object to card1 and card2 Since we are actually passing a reference to the same object, it results in owner of two LibraryCard objects pointing to the same Student object

BCS 2143 Object Oriented Programming Passing a Student Object class LibraryCard { private Student owner; public void setOwner(Student st) { owner = st; } LibraryCard card2; card2 = new LibraryCard(); card2.setOwner(student); Passing Side Receiving Side : LibraryCard owner borrowCnt 0 : Student name “Jon Java” student card2 st 1 1 Argument is passed Value is assigned to the data member 2 State of Memory

BCS 2143 Object Oriented Programming 5. Constructors Problem occur on previous Account class class Account { private String ownerName; private double balance; public Account( ) { ownerName = "Unassigned"; balance = 0.0; } public void add(double amt) { balance = balance + amt; } public void deduct(double amt) { balance = balance - amt; } public double getCurrentBalance( ) { return balance; } public String getOwnerName( ) { return ownerName; } public void setInitialBalance (double bal) { balance = bal; } public void setOwnerName (String name) { ownerName = name; }

BCS 2143 Object Oriented Programming Construtors (cont.) Logically, it is inconsistent to initialize the starting balance more than once. Solution???!! 1 st, remove setInitialBalance() method 2 nd, create new appropriate constructor Account acct; acct = new Account(); acct.setInitialBalance(500); acct.setInitialBalance(300); Account acct; acct = new Account(); acct.setInitialBalance(500); acct.setInitialBalance(300); public Account (String name, double startingBalance) { ownerName = name; balance = startingBalance; } public Account (String name, double startingBalance) { ownerName = name; balance = startingBalance; }

BCS 2143 Object Oriented Programming Constructor (cont.) Overloaded constructor - Multiple constructor Overriding constructor – another chapter Default constructor Constructor that accepts no arguments and has no statements in its body Automatically added by the compiler if no single constructor defined for a class Should not rely on it

BCS 2143 Object Oriented Programming 6. Information Hiding and Visibility Modifiers The modifiers public and private designate the accessibility of data members and methods. If a class component (data member or method) is declared private, client classes cannot access it. If a class component is declared public, client classes can access it. Internal details of a class are declared private and hidden from the clients. This is information hiding.

BCS 2143 Object Oriented Programming Accessibility Example class Service { public int memberOne; private int memberTwo; public void doOne() { … } private void doTwo() { … } … Service obj = new Service(); obj.memberOne = 10; obj.memberTwo = 20; obj.doOne(); obj.doTwo(); … ClientService

BCS 2143 Object Oriented Programming Data Members Should Be private Data members are the implementation details of the class, so they should be invisible to the clients. Declare them private. Exception: Constants can (should) be declared public if they are meant to be used directly by the outside methods.

BCS 2143 Object Oriented Programming Guideline for Visibility Modifiers Guidelines in determining the visibility of data members and methods: –Declare the class and instance variables private. –Declare the class and instance methods private if they are used only by the other methods in the same class. –Declare the class constants public if you want to make their values directly readable by the client programs. If the class constants are used for internal purposes only, then declare them private.

BCS 2143 Object Oriented Programming Diagram Notation for Visibility public – plus symbol (+) private – minus symbol (-)

BCS 2143 Object Oriented Programming 7. Class Constants In Chapter 3, we introduced the use of constants. We illustrate the use of constants in programmer- defined service classes here. Remember, the use of constants –provides a meaningful description of what the values stand for. number = UNDEFINED; is more meaningful than number = -1; –provides easier program maintenance. We only need to change the value in the constant declaration instead of locating all occurrences of the same value in the program code

BCS 2143 Object Oriented Programming A Sample Use of Constants class Dice { private static final int MAX_NUMBER = 6; private static final int MIN_NUMBER = 1; private static final int NO_NUMBER = 0; private int number; public Dice( ) { number = NO_NUMBER; } //Rolls the dice public void roll( ) { number = (int) (Math.floor(Math.random() * (MAX_NUMBER - MIN_NUMBER + 1)) + MIN_NUMBER); } //Returns the number on this dice public int getNumber( ) { return number; }

BCS 2143 Object Oriented Programming 8. Local Variables Local variables are declared within a method declaration and used for temporary services, such as storing intermediate computation results. public double convert(int num) { double result; result = Math.sqrt(num * num); return result; } local variable

BCS 2143 Object Oriented Programming Local, Parameter & Data Member An identifier appearing inside a method can be a local variable, a parameter, or a data member. The rules are –If there’s a matching local variable declaration or a parameter, then the identifier refers to the local variable or the parameter. –Otherwise, if there’s a matching data member declaration, then the identifier refers to the data member. –Otherwise, it is an error because there’s no matching declaration.

BCS 2143 Object Oriented Programming class MusicCD { private String artist; private String title; private String id; public MusicCD(String name1, String name2) { String ident; artist = name1; title = name2; ident = artist.substring(0,2) + "-" + title.substring(0,9); id = ident; }... }

BCS 2143 Object Oriented Programming 9. Calling Methods of the Same Class So far, we have been calling a method of another class (object). It is possible to call method of a class from another method of the same class. –in this case, we simply refer to a method without dot notation

BCS 2143 Object Oriented Programming 10. Changing Any Class to a Main Class Any class can be set to be a main class. All you have to do is to include the main method. class Bicycle { //definition of the class as shown before comes here //The main method that shows a sample //use of the Bicycle class public static void main(String[] args) { Bicycle myBike; myBike = new Bicycle( ); myBike.setOwnerName("Jon Java"); System.out.println(myBike.getOwnerName() + "owns a bicycle"); }

BCS 2143 Object Oriented Programming Problem Statement Problem statement: Write a loan calculator program that computes both monthly and total payments for a given loan amount, annual interest rate, and loan period.

BCS 2143 Object Oriented Programming Overall Plan Tasks: –Get three input values: loanAmount, interestRate, and loanPeriod. –Compute the monthly and total payments. –Output the results.

BCS 2143 Object Oriented Programming Required Classes LoanCalculator Loan JOptionPanePrintStream inputcomputationoutput

BCS 2143 Object Oriented Programming Development Steps We will develop this program in five steps: 1.Start with the main class LoanCalculator. Define a temporary placeholder Loan class. 2.Implement the input routine to accept three input values. 3.Implement the output routine to display the results. 4.Implement the computation routine to compute the monthly and total payments. 5.Finalize the program.

BCS 2143 Object Oriented Programming Step 1 Design The methods of the LoanCalculator class MethodVisibilityPurpose startpublicStarts the loan calcution. Calls other methods computePaymentprivateGive three parameters, compute the monthly and total payments describeProgramprivateDisplays a short description of a program displayOutputprivateDisplays the output getInputprivateGets three input values

BCS 2143 Object Oriented Programming Step 1 Code Directory: Chapter4/Step1 Source Files: LoanCalculator.java Loan.java Directory: Chapter4/Step1 Source Files: LoanCalculator.java Loan.java Program source file is too big to list here. From now on, we ask you to view the source files using your Java IDE.

BCS 2143 Object Oriented Programming Step 1 Test In the testing phase, we run the program multiple times and verify that we get the following output inside describeProgram inside getInput inside computePayment inside displayOutput

BCS 2143 Object Oriented Programming Step 2 Design Design the input routines –LoanCalculator will handle the user interaction of prompting and getting three input values –LoanCalculator calls the setAmount, setRate and setPeriod of a Loan object.

BCS 2143 Object Oriented Programming Step 2 Code Directory: Chapter4/Step2 Source Files: LoanCalculator.java Loan.java Directory: Chapter4/Step2 Source Files: LoanCalculator.java Loan.java

BCS 2143 Object Oriented Programming Step 2 Test We run the program numerous times with different input values Check the correctness of input values by echo printing System.out.println("Loan Amount: $" + loan.getAmount()); System.out.println("Annual Interest Rate:" + loan.getRate() + "%"); System.out.println("Loan Period (years):" + loan.getPeriod());

BCS 2143 Object Oriented Programming Step 3 Design We will implement the displayOutput method. We will reuse the same design we adopted in Chapter 3 sample development.

BCS 2143 Object Oriented Programming Step 3 Code Directory: Chapter4/Step3 Source Files: LoanCalculator.java Loan.java Directory: Chapter4/Step3 Source Files: LoanCalculator.java Loan.java

BCS 2143 Object Oriented Programming Step 3 Test We run the program numerous times with different input values and check the output display format. Adjust the formatting as appropriate

BCS 2143 Object Oriented Programming Step 4 Design Two methods getMonthlyPayment and getTotalPayment are defined for the Loan class We will implement them so that they work independent of each other. It is considered a poor design if the clients must call getMonthlyPayment before calling getTotalPayment.

BCS 2143 Object Oriented Programming Step 4 Code Directory: Chapter4/Step4 Source Files: LoanCalculator.java Loan.java Directory: Chapter4/Step4 Source Files: LoanCalculator.java Loan.java

BCS 2143 Object Oriented Programming Step 4 Test We run the program numerous times with different types of input values and check the results.

BCS 2143 Object Oriented Programming Step 5: Finalize We will implement the describeProgram method We will format the monthly and total payments to two decimal places using DecimalFormat. Directory: Chapter4/Step5 Source Files (final version): LoanCalculator.java Loan.java