Unit 1: Intro Lesson 3: Input.

Slides:



Advertisements
Similar presentations
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Advertisements

Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
Chapter 2: Using Data.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
IC211 Lecture 8 I/O: Command Line And JOptionPane.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
Chapter 2 Section 2.2 Console Input Using The Scanner CLASS Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska.
JOptionPane class. Dialog Boxes A dialog box is a small graphical window that displays a message to the user or requests input. A variety of dialog boxes.
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
Expressions, Data Conversion, and Input
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Object-Oriented Programming - Classes, Objects Methods, Strings 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Chapter 2 Elementary Programming
Java Programming: From Problem Analysis to Program Design, 3e Chapter 3 Introduction to Objects and Input/Output.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 3: Numerical Data Manipulating Numbers Variables.
9/6: Variable Types, Arithmetic Operators, Comparison Operators Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
Chapter 3 Java Input/Output.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
Lecture 2 Objectives Learn about objects and reference variables.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
Dialog Boxes.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 3 Introduction to Objects and Input/Output.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Strings and I/O. Lotsa String Stuff… There are close to 50 methods defined in the String class. We will introduce several of them here: charAt, substring,
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
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.
© A+ Computer Science - import java.util.Scanner; Try to be as specific as possible when using an import.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
JAVA 1.COMPARISON: JAVA AND C++ 2.KEYBOARD INPUT 3.OUTPUT 4.CONVERSION FROM STRING 5.OPERATORS AND EXPRESSIONS 6.DIALOG BOX – USER PROMPT January
Introduction to programming in java
Lecture 4.1: More on Scanner, Methods, and Codingbat Michael Hsu CSULA.
Foundations of Programming: Java
Java Programming Lecture 2
3 Introduction to Classes and Objects.
CS 201 Lecture 7: John Hurley Summer 2012 Cal State LA.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Elementary Programming
CSC305: COMPUTER PROGRAMMING II (JAVA)
2.5 Another Java Application: Adding Integers
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II
Data Conversion & Scanner Class
Chapter 3 Assignment Statement
Chapter 3 Java Input/Output.
Lesson 2: Program design process & Intro to code
الكلية الجامعية للعلوم التطبيقية
Chapter 3: Introduction to Objects and Input/Output
Computers & Programming Languages
Introduction to Classes and Methods
A+ Computer Science INPUT.
Chapter 3 Input/Output.
A+ Computer Science INPUT.
Object Oriented Programming
JOptionPane class.
Unit 1: Intro Lesson 4: Output.
Input, Variables, and Mathematical Expressions
Presentation transcript:

Unit 1: Intro Lesson 3: Input

Methods Input Input methods are statements which give the user an interface through which to modify variables within a program Input methods must be imported Input method 1: Scanner Input method 2: JOptionPane.showInputDialog(“ “);

Scanner Simple Input can be saved directly to any type of variable (int, float, double, etc.) Can only be used in an IDE or the Command Line

JOptionPane.showInputDialog(“ “); Slightly more complicated Works outside of the IDE or Command Line User – friendly interface Combines an Output dialog with an Input field (input box) Input can only be saved as Strings and must be converted (parsed) to a separate variable to be used as any other data type

Scanner Usage Import statement Variable to store Input of desired data type Variable to create the Scanner object in memory Statement to assign Input to the storage variable Import java.util.Scanner; int myVariable; Scanner myKeyboard = new Scanner(System.in); myVariable = scanner.nextInt();

variable = scanner.nextDatatype(); int myVariable; myVariable = scanner.nextInt(); int .nextInt(); float myVariable; myVariable = scanner.nextFloat(); float .nextFloat(); String myVariable; myVariable = scanner.nextLine(); String .nextLine(); Boolean myVariable; myVariable = scanner.nextBoolean (); Boolean .nextBoolean();

JOptionPane Input Usage Import statement String variable to store Input (optional) Variable of desired data type (for after parsing) Statement to assign Input to the storage variable (optional) Statement to parse (convert) Input to desired data type Import javax.swing.JOptionPane; String myVariable; float myParsedVar; (Optional) JOptionPane.showInputDialog(“Please input some data”); myVariable = Float.parseFloat(myParsedVar); (Optional)