
Understanding Numerical Data in Object-Oriented Programming
Explore variables, data types, initialization, memory diagrams, declarations, arithmetic expressions, typecasting, and more in numerical data representation for object-oriented programming with Iksan Bukhori.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Lecture 3 Ch3. Numerical Data Object Oriented Programming Iksan Bukhori, M.Phil iksan.bukhori@president.ac.id 2018
Variables What are they? Declaration Syntax: Ex: What s Wrong? 1/2 Iksan Bukhori Object Oriented Programming
Numerical Data Types int is commonly used to represent integer long is commonly used to represent integer outside range of int For real numbers, double is commonly more preferable Precision Memory Space 1/3 Iksan Bukhori Object Oriented Programming
Initialization and Assignment Operator Initialization Assignment Assignment IS NOT mathematical equality 1/4 Iksan Bukhori Object Oriented Programming
Memory Diagram: Variable Initialization 1/5 Iksan Bukhori Object Oriented Programming
Numerical Data Declaration Vs Object Declaration 1/6 Iksan Bukhori Object Oriented Programming
Numerical Data Declaration Vs Object Declaration Primitive Data Types VS Reference Data Types 1/7 Iksan Bukhori Object Oriented Programming
Arithmetic Expressions 1/8 Iksan Bukhori Object Oriented Programming
Precedence Rules 1/9 Iksan Bukhori Object Oriented Programming
Arithmetic Promotion Rules Implicit Typecasting Explicit 1/10 Iksan Bukhori Object Oriented Programming
Explicit Typecasting Syntax: Ex: 1/11 Iksan Bukhori Object Oriented Programming
Shorthand Assignments 1/12 Iksan Bukhori Object Oriented Programming
Constants Good Practice: Naming Convention All Caps Words separated by underscores 1/13 Iksan Bukhori Object Oriented Programming
Literal Constant Integer Long Float Double 1/14 Iksan Bukhori Object Oriented Programming
1/15 Iksan Bukhori Object Oriented Programming
Displaying Numerical Values Operator Overloading TRY: How to obtain result3? 1/16 Iksan Bukhori Object Oriented Programming
DecimalFormat Class Format variable to have three decimal points DecimalFormat 1/17 Iksan Bukhori Object Oriented Programming
Control Characters New line Tab 1/18 Iksan Bukhori Object Oriented Programming
Getting Numerical Input (Scanner Class) 1/19 Iksan Bukhori Object Oriented Programming
Example: Single line input 1/20 Iksan Bukhori Object Oriented Programming
Example: Input Buffering Try to input all three integers at one before hitting ENTER 1/21 Iksan Bukhori Object Oriented Programming
Example: Implicit Conversion Try to input integer instead of double 1/22 Iksan Bukhori Object Oriented Programming
Bad Example: Implicit Conversion 1/23 Iksan Bukhori Object Oriented Programming
Example: Numerical+String Try to input horse name with single and more words 1/24 Iksan Bukhori Object Oriented Programming
Math Class Ex: 1/25 Iksan Bukhori Object Oriented Programming
Methods of Math Class 1/26 Iksan Bukhori Object Oriented Programming
Methods of Math Class 1/27 Iksan Bukhori Object Oriented Programming
Homework 1. Write a program that accepts the unit weight of a bag of coffee in pounds and the number of bags sold and displays the total price of the sale, computed as totalPrice = unitWeight * numberOfUnits * 5.99; totalPriceWithTax = totalPrice + totalPrice * 0.0725; where 5.99 is the cost per pound and 0.0725 is the sales tax. Display the result in the following manner: 1/28 Iksan Bukhori Object Oriented Programming
Homework Write a program to solve quadratic equations of the form ??2+ ?? + ? = 0 where coefficient A, B, and C, are real numbers. The two real number solutions (roots) are given by 2. ? = ? ?2 4?? 2? Assume that ? 0 and the relationship ?2 4?? holds. Please note that the three coefficients are all inputs from the user. 1/29 Iksan Bukhori Object Oriented Programming
Homework 3. Development Exercise. MyJava Coffee Outlet runs a catalog business. It sells only one type of coffee beans, harvested exclusively in the remote area of Irian Jaya. The company sells the coffee in 2-lb bags only, and the price of a single 2-lb bag is $5.50. When a customer places an order, the company ships the order in boxes. The boxes come in three sizes: the large box holds 20 bags of 2 lb, the medium 10 bags, and the small 5 bags. The cost of a large box is $1.80; a medium box, $1.00; and a small box, $0.60. The order is shipped in the least expensive manner. For example, the order of 52 bags will be shipped in four boxes: two large, one medium, and one small. The rule for packing is to fill the large and medium boxes completely; that is, the box is fully packed. Only the small boxes can have empty spaces. For example, to ship 52 bags, you could have used 3 large boxes, but that would leave the third box not fully packed. Develop a program that computes the total cost of an order. Display the output in the following format: 1/30 Iksan Bukhori Object Oriented Programming
Next Week Defining Your Own Class (Part 1) 1/31 Iksan Bukhori Object Oriented Programming