Humera Tariq
Hands on Lab Sessions: Ms. Sanya Yousuf
UML to represent and using single object
Practice writing code for class
Practice toString( ) function
Practice writing your own functions
Practice Debugging Feature
Practice building code logic
- Numerator: int
- Denominator : int
+ main (args : String[]) : void
+ RationalNumber( )
+ RationalNumber(n:int,d:int)
+ RationalNumber(RationalNumber r)
File
RationalNumber.java
is explicitly created by
developer
show( ) is user
defined
method
toString( ) is inherited
method from built-in toString( ) contains
java class Object class attributes
separated by + and
Put on your thinking cap again and start testing in
class RationalNumberDemo.java
Test/Run/call each
function of
RationalNumber.java
inside main.java
3- step Into
Using Debug Feature: step over
4- step over
5- step over
6- step over
7- step over
Using Debug Feature: Reading Variables
inside class add( ) function
Using Debug Feature: Reading Variables
inside class main
Memory
Before
step over
8- step over
Memory
after
step over
Task I: Write Code for
RationalNumber.java so that given
main( ) function executes successfully.
38 2
= +
24 1
381 + (224)
=
241
Is it function Overloading? (True/False) =
38+48
Explain why or why not ? 86
24
= 24
Write function equalTo (RationalNumber b) in class RationalNumber.java
and call it from main( ) function as follows so that it execute successfully
and gives accurate result.
Write function greaterThan (RationalNumber b) in class
RationalNumber.java and call it from main( ) function as follows so that
it execute successfully and gives accurate result.
1- What other important functions should be written in
RationalNumber.java so that it becomes the best for users.
Code any TWO such functions and discuss it in upcoming Theory Class.