Data Type & Input/Output Session 3 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2010.

Slides:



Advertisements
Similar presentations
Simulation Examples in EXCEL Montana Going Green 2010.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Iterations for loop. Outcome Introduction to for loop The use of for loop instead of while loop Nested for loops.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
For(int i = 1; i
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Review BP Dari slide pak cahyo pertemuan 7 dan pertemuan 2 dengan sedikit modifikasi.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
SORTING Matakuliah: T0974 / Algoritma dan Metode Object Oriented Programming I Tahun: 2008 Versi: 1/0.
TNPL JoongJin-Cho Runge-kutta’s method of order 4.
Logical and Relational Operation Session 5 Course: T-0974 Algorithm & Object-Oriented Programming I Year: 2010.
1 Convert this problem into our standard form: Minimize 3 x x 2 – 6 x 3 subject to 1 x x 2 – 3 x 3 ≥ x x 2 – 6 x 3 ≤ 5 7 x 1.
SORTING AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Spring 2014 File searchSortAlgorithms.zip on course website (lecture notes for lectures 12, 13) contains.
Soal latihan java. Soal 1 public class MyClass { public static void main() { int arrmul [] [] = new int [4] [5]; int k = 0; for (int i=0;i
Arrays Session 05 Mata kuliah: M0874 – Programming II Tahun: 2010.
04 WeightLoss program1May WeightLoss program CE : Fundamental Programming Techniques.
Matakuliah: G0922/Introduction to Linguistics Tahun: 2008 Session 5 Phonetic Transcriptions.
Java Planning our Programs Flowcharts Arithmetic Operators.
Object Orientated Concepts. Overview  The world is objects  Defining an object  Not a function, it’s a method  Lets inherit want we can  Objects.
Outcome: Project teams will be able to  Identify opportunities and issues for Task-oriented transformations  Commence work on the Task-oriented section.
Review. By the end of today you should be able to- Know how to use args Know how to use the JOptionPane Know how to convert a String to a number.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
10 ThinkOfANumber program1July ThinkOfANumber program CE : Fundamental Programming Techniques.
Java Classes Methods Objects. Classes Classes We have been using classes ever since we started programming in Java Whenever we use the keyword class.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
CSC1401 Strings (text). Learning Goals Working with Strings as a data type (a class) Input and output of Strings String operations.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 45 – 90 seconds per question. Determine the output.
Building java programs, chapter 3 Parameters, Methods and Objects.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Classes - Intermediate
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
JOptionPane. Import javax.swing.JOptionPane Use showInputDialog() for input. Only string values can be input. To convert an input value from a string.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
NILAI WAKTU DARI UANG (Time Value of Money) Pertemuan 11
Exercise Java programming
Advanced Programming TA Session 2
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Training for Hospitality Week 11
Case Project Presentation and Review Lecture 13
Introduction to Methods in java
Make Your Own Quiz.
Something about Java Introduction to Problem Solving and Programming 1.
Lesson 2: Program design process & Intro to code
Computing Adjusted Quiz Total Score
شاخصهای عملکردی بیمارستان
TO COMPLETE THE FOLLOWING:
مدل زنجیره ای در برنامه های سلامت
فرق بین خوب وعالی فقط اندکی تلاش بیشتر است
AP Java Warm-up Boolean Array.
Java Lesson 36 Mr. Kalmes.
Transp Course 2014 Overview.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Java for Beginners University Greenwich Computing At School DASCO
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Variables and Java vs C++
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
Lecture 22: Number Systems
Random Numbers while loop
Computer Science Club 1st November 2019.
Presentation transcript:

Data Type & Input/Output Session 3 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2010

Bina Nusantara Learning Outcomes After taking this course, student should be expected to be able to apply data types depend on the need of the programs and using syntax for Input – Output Operation

JAWABAN QUIZ Bina Nusantara University 4 public class Gaji { public static void main(String [] args) { Hitung h= new Hitung(); //membuat obyek dari //kelas Hitung h.basic= ; h.tunjangan= ; h.bolos=2; h.hitung(); } } class Hitung{ int bolos=0; int total=0; int basic=0; int tunjangan=0; String nama="RINA"; void hitung() { if (bolos<=3) { total=basic+tunjangan; } else { total=basic; } System.out.println ("Nama " + nama+ " Jumnlah bolos:" + bolos); System.out.println ("Gaji :" + total); } }

Bina Nusantara Outline Materi •Data Types •Input/Output (I/O) •Output Format •Type Casting (Conversion) •ASCII •Import •Constant

Bina Nusantara Data Type •An attribut that has range value and type. •To be used as a value storage from execution process. •Based on its data type : –Boolean (boolean) –Numeric (byte, short, int, long, float, double) –Character (char) –String (String)

Bina Nusantara Data Type •Based on Complexity : –Atomic DT (boolean, byte, char, short, int, long, float, double) –Composite DT (Array, Struct, List, Queue, Stack, String, Tree) •Based on Source: –Native / primitive / basic DT –Abstract DT •Based on Customization: –Built-in DT –User-defined DT

Bina Nusantara Data Type NameRangeSizeClass booleantrue, false1 bitBoolean byte-2 7 (-128) to 2 7 – 1 (127)8 bitByte char0 to 65,53516 bitCharacter short-2 15 (-32,768) to 2 15 – 1 (32,767) 16 bitShort int-2 31 (-2,147,483,648) to 2 31 (2,147,483,647) 32 bitInteger long-2 63 to 2 63 – 164 bitLong float-3.4E38 to 3.4E3832 bitFloat double-1.798E308 to 1.798E30864 bitDouble

Bina Nusantara Data Type Filename : TipeData.java Output:

Bina Nusantara Input / Output (I/O) •A Communication between computer to other entity (Human / Machine) •Input: Signal/Data will be recevied by system. •Output: Signal/Data will be sent from system. •I/O perform or I/O operation.

Bina Nusantara Input / Output (I/O) •Input Devices e.g. : keyboard, mouse •Output Devices e.g. : monitor, printer •I/O Devices e.g. : disk, file

Bina Nusantara Input / Output (I/O) •Get input from console using Scanner. •Library java.util.Scanner. •It needs to import declaration : import java.util.Scanner; •Afterward declare an object creation : Scanner input = new Scanner(System.in);

Bina Nusantara Input / Output (I/O) MethodUse next();Input String (word) nextLine();Input String (sentence) nextByte();Input number (byte) nextShort();Input number (short) nextInt();Input number (int) nextLong();Input number (long) nextFloat();Input number (float) nextDouble();Input number (double)

Bina Nusantara Input / Output (I/O)

Bina Nusantara Input / Output (I/O)

Bina Nusantara Input / Output (I/O) SpecifierDescriptionExampleOutput %bboolean%6b false true %ccharacter%5c a %dinteger%5d %fFloating-point%5.2f %escientific%10.2e 3.14e+02 %sstring%10s hello •Note :  spasi

Bina Nusantara Input / Output (I/O) SpecifierDescriptionExampleOutput %bboolean%-6b false true %ccharacter%-5c a %dinteger%-5d %fFloating-point%-5.2f %escientific%-10.2e 3.14e+02 %sstring%-10s hello •Note :  spasi

Bina Nusantara Input / Output (I/O)

Bina Nusantara Input / Output (I/O) •System.out.print  print into console without linefeed (newline). •System.out.println  print into console with linefeed (newline) •System.out.printf  same as System.out.print, supports format output

Bina Nusantara Type Casting (Conversion) •Convert a value to different type. •Type casting conversion : –Widening a type: convert a value from smaller data to bigger data. (Automatically done by Java). –Narrowing a type: convert a value from bigger data to smaller data. •Size of data type (smallest to biggest) byte, short, int, long, float, double

Bina Nusantara Type Casting (Conversion) •Parentheses is use as a syntax for narrowing. •Example 1: –float f = (float) 10.1; –int i = (int) f; •Example 2 : –double d = 4.5; –int i = (int) d; •As depicted from example 1-2 above, f and d values haven’t been changed.

Bina Nusantara Type Casting (Conversion)

Bina Nusantara Type Casting (Conversion) •Conversion from String to Atomic data type can be done by class helper. ClassKonversi ke tipe dataPemakaian BooleanbooleanBoolean.parseBoolean(…); BytebyteByte.parseByte(…); CharactercharString.charAt( ); ShortshortShort.parseShort(…); IntegerintInteger.parseInt(…); LonglongLong.parseLong(…); FloatfloatFloat.parseFloat(…); DoubledoubleDouble.parseDouble(…);

Bina Nusantara Type Casting (Conversion)

Bina Nusantara Type Casting (Conversion)

Bina Nusantara Type Casting (Conversion)

Bina Nusantara ASCII •American Standard Code for Information Interchange •7-bit, 128 characters (000 s/d 127) •uppercase/lowercase letters, digits, punctuation marks, dan control characters •Next development of ASCII  Unicode has 1,112,064 characters.

Bina Nusantara ASCII

Bina Nusantara ASCII

Bina Nusantara ASCII

Bina Nusantara Type Casting (Conversion) cont. •ASCII characters from ‘0’ s/d ‘9’ –‘0’  48 –‘1’  49 –‘9’  57 •Convert character to number can be done by substracting 48. •Convert number to character can be done by adding 48.

Bina Nusantara Type Casting (Conversion) cont.

Bina Nusantara Constant •a constant variable is a variable that is always constant •Example : –π (PHI) = –g (gravitation) = 9.8 •Constant should have been declared and initialized. •Final is a keyword in Java to declare constant. •Declaration : –final datatype CONSTANTNAME = VALUE; –Example: final double PHI = ;

Bina Nusantara Constant

Bina Nusantara Did You Know? •For every Scanner use, it should need “import java.util.Scanner;”. •Because Scanner is a class that should be included. •Contrary to System library, it doesn’t use “import java.lang.System;” declaration which Java automatically import all of “java.lang” content to its new code.

Bina Nusantara Did You Know? •Content of java.lang which is usually used : –Boolean –Byte –Character –Double –Float –Integer –Long –Math –Short –String –System –Thread

Bina Nusantara Advanced Learning •Instead of scanner, BufferedReader can be used for handling input from console. •It needs import from java.io.BufferedReader & java.io.InputStreamReader; •And do object creation : –BufferedReader input = new BufferedReader (new InputStreamReader(System.in)); •Either use read() method for reading single character or readLine() method for reading word.

Bina Nusantara Advanced Learning

Bina Nusantara Advanced Learning •Import declaration like : import java.io.BufferedReader; import java.io.InputStreamReader; can be shortened to: import java.io.*; •try and catch are going to be disscussed next lecture (Exception Handling)

Latihan Kembangkan jawaban quiz untuk terima input dari keyboard menggunakan Kelas Scanner Bina Nusantara University 40

Bina Nusantara References •Introduction to Java. 7ed Liang. p60, p67-71, p79- 81, p , p •Java Software Solutions. 5ed Lewis. p99-103, p •The Complete Reference: Java. 5ed Herbert. p33-48 •Dasar Pemrograman Java Abdul Kadir. p66-73 •Composite Data Types. •Data Type. •Primitive Data types. /datatypes.html /datatypes.html •Primitive Data types.