Lesson 4 Input. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are using. The reason it is not.

Slides:



Advertisements
Similar presentations
Getting Input in Python Assumes assignment statement, typecasts.
Advertisements

1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Program Design. Objectives Students should understand the basic steps in the programming process. Students should understand the need for good design.
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Introduction to C Programming
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Scanner Pepper With credits to Dr. Siegfried. The Scanner Class Most programs will need some form of input. At the beginning, all of our input will come.
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology- George Koutsogiannakis.
Methods: a first introduction Two ways to make tea: 1: boil water; put teabag into cup;... etc : tell your younger brother: makeTea(1 milk, 0 sugar);
Hello, world! Dissect HelloWorld.java Compile it Run it.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Chapter 2 First Java Programs
Computer Programming Lab(4).
Using Java's Math & Scanner class. Java's Mathematical functions (methods) (1)
1.1 History of Computers 1940s: The ENIAC was one of the world’s first computers. Large stand-alone machine Used large amounts of electricity Contained.
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
Hello AP Computer Science!. What are some of the things that you have used computers for?
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Lesson 2: First Java Programs
Lesson 7: Improving the User Interface
Variable Declaration  It is possible to declare multiple variables of the same data type on the same line.  Ex. double hours, rate, total;  Variables.
VARIABLES Introduction to Computer Science 1- COMP 1005, 1405 Instructor : Behnam Hajian
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
Lesson 2: First Java Programs. Objectives: –Discuss why Java is an important programming language. –Explain the Java virtual machine and byte code. –Choose.
Sahar Mosleh California State University San MarcosPage 1 System.out.println for console output System.out is an object that is part of the Java language.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Java basics. Task  Display the supposed forecast I think there is a world market for maybe five computers. Thomas Watson, IBM, 1943.
CSC Programming I Lecture 6 September 4, 2002.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Java Variables, Types, and Math Getting Started Complete and Turn in Address/Poem.
Department of Computer Engineering Using Objects Computer Programming for International Engineers.
9/29/99B-1 CSE / ENGR 142 Programming I Variables, Values, and Types © 1998 UW CSE.
Week 2 Definitions Assignment Expressions Input. Variables Usually when problem solving multiple things need determining Without the ability to remember.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Java basics – part 2. Where are we Last week –Java basics Simple output program Started programs as calculators –Codelab –Lab procedures This week –Types,
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
Input Characters from the Keyboard tMyn1 Input Characters from the Keyboard We have been using console output, but not console (keyboard) input. The main.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
2.5 Edit, Compile, and Execute Figure 2-3 illustrates the edit, compile and execute steps. Java bytecode.
Text by: Lambert and Osborne
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II
Data types, Expressions and assignment, Input from User
Something about Java Introduction to Problem Solving and Programming 1.
Chapter 2.
BIT115: Introduction to Programming
Java Variables, Types, and Math Getting Started
Variables, Identifiers, Assignments, Input/Output
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Presentation transcript:

Lesson 4 Input

JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are using. The reason it is not straightforward, is that JAVA is a complete object-oriented package, whereas every method must be an object. In other words, there is not a simple built-in command that is universal amongst compilers (i.e. cin for C++, input for Basic)

Example Program with Input import TerminalIO.KeyboardReader; public class Convert { public static void main(String [] args) { KeyboardReader reader = new KeyboardReader(); double fahrenheit; double celsius; System.out.print(“Enter degrees Fahrenheit: “); fahrenheit = reader.readDouble(); celsius = (fahrenheit – 32.0) * 5.0/9.0; System.out.print(“The equivalent in Celsius is “); System.out.println(celsius); reader.pause(); }

Example Program Explanation The import statement incorporates a file from your computer into your program. The KeyboardReader class which is imported gives us the functionality to get input from the keyboard. Without this statement you will not be able to input information. Import TerminalIO.KeyboardReader;

Example Program Explanation This statement instantiates or creates a KeyboardReader object. It’s name “reader” is an arbitrary name and can be called anything that you want. NOTE: An object is always an instance of a class and must be created, or instantiated before being used. –i.e. SomeClass someobject = new SomeClass() KeyboardReader reader = new KeyboardReader();

Example Program Explanation This defines two numeric variables that will be used to hold the input and calculate the result for output. double means that the numbers are floating point numbers (i.e. they can contain decimals) double fahrenheit; double celsius;

Example Program Explanation This statement creates a prompt in the output window. Prompt – A print or println statement that tells the user at the console window that something is to be entered. You must always prompt the user for the input. System.out.print(“Enter degrees Fahrenheit: “);

Example Program Explanation This statement gets the value that is entered from the keyboard into the variable “fahrenheit” The reader object waits for a number to be input and the enter key to be pressed. Once that is done, it returns that value to “fahrenheit”. fahrenheit = reader.readDouble();

charreadChar() readChar doublereadDouble()readDouble intreadInt() readInt StringreadLine() readLine

Example Program Explanation This statement contains the actual calculation for converting fahrenheit to celsius. This is called an assignment statement. In an assignment statement, you cannot have any calculations on the left hand side of the =. You can only have variables. On the right hand side, you can have variables and math operators. celsius = (fahrenheit – 32.0) * 5.0/9.0;

Example Program Explanation These statements place the output in the console window. The first statement labels the data that is being output. The second statement prints out the value that is contained in the memory location for celsius. System.out.print(“The equivalent in Celsius is “); System.out.println(celsius);