ISM 3232 - Intermediate Business Programming. 

Chapter 5 Student Learning Objectives.

You should be able to:


Review: Data Types

The concept of different data types and how they are stored and represented in memory is familiar from previous programming classes. We will focus on how various types of data, and arithmetic and relational expressions, are implemented in Java. This chapter demonstrates several examples of these implementations, as well as how they can be used to create good programming practices.

 

Programming = Representation + Action

Representation:

Action:


Review: Boolean Data and Operators

Boolean Operator Precedence

 

The Boolean-based CyberPet Model is impractical, because it is not easily extensible:

 

Design Principles

Effective Design: Scalability Principle. A well-designed model or representation should be easily extensible. It should be easy to add new functionality to the model.

Effective Design: Modularity Principle. A well-designed representation will allow us to extend the model without having to modify existing design methods.

We'll now review numeric data types and then see how to re-design the CyberPet using a different data type that allows it to be more extensible and modular.


Numeric Data Types

 

Effective Design: Platform Independence. In Java, a data type’s size is part of its definition and therefore remains consistent across all platforms.

Numeric Data: Limitations

Numeric types are representations of number systems, so there are tradeoffs:

Debugging Tip: A round-off error is the inability to represent certain numeric values exactly. A float can have at most 8 significant digits. So 12345.6789 would be rounded off to 12345.679.

Debugging Tip: Significant Digits. In using numeric data the data type you choose must have enough precision to represent the values your program needs.


Review: Standard Arithmetic Operators

Promotion:

 

Review: Numeric Operator Precedence

 

Increment/Decrement Operators

Java Language Rule:

 

Shortcut Assignment Operators.

 

Review: Relational Operators

Note: = is an assignment operator, while == is a relational operator.

 

Review: Numeric Operator Precedence


Case Study: Fahrenheit to Celsius

Design an applet that converts Fahrenheit to Celsius temperatures.

Note the following objects and interactions:

Problem Decomposition.

Temperature Class Design (data, methods, type of data).

Implementation: Temperature Class

 

Implementation: Testing and Debugging

It is important to develop good test data. For this application the following tests would be appropriate:

These data test all the boundary conditions.

Testing Principle: The fact that your program runs correctly on some data is no guarantee of its correctness. Testing reveals the presence of errors, not their absence.

 

Implementation: TemperatureTest Class

Purpose: Serve as a user interface to Temperature class.

Algorithm Design:

User Interface Design:

 

Implementation: Data Conversion

public static Double valueOf(String);

public static doubleValue();

...

double d = Double.valueOf(inputString).doubleValue();

same as:

We can then just pass a string to the method and receive a numeric result, without worrying about how the conversion is done.

Effective Design: Modularity Principle. Method Abstraction.

 

Design: TemperatureApplet

Implementation: TemperatureApplet (Data)

Implementation: TemperatureApplet (Methods)


Integer-based CyberPet Model (Data)

Maintainability Principle: Constants should be used instead of literal values in a program to make the program easier to modify and maintain.

Integer-based CyberPet Model (Constructors)

 

Integer-based CyberPet Model (Methods)

Advantages of the Integer-based CyberPet Model

Class Constants.

 


Review: Character Data and Operators

The char type is a primitive data type.

The ASCII Characters

Character to Integer Conversions

Type Conversions

 

Review: Relational Operators in Characters

Example Character Conversions

Conversion Methods


From the Java Library: java.lang.Math

Math Class Methods

Math Class Example: Rounding


From the Java Library: NumberFormat

Example: Calculating Compound Interest

The CDInterest Application

CDInterest.getInput() Method

CDInterest.calcAndReportResult() Method

Leap Year Problem

Objectives:

Leap Year Applet: Design Specification

 


Review Exercises: #4, 6, 10, 12, 14