IC211 Lecture 8 I/O: Command Line And JOptionPane.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chapter 2: Using Data.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
1 Introduction to Console Input  Primitive Type Wrapper Classes  Converting Strings to Numbers  System.in Stream  Wrapping System.in in a Buffered.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
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.
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
1 Course Lectures Available on line:
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
Using Classes BCIS 3680 Enterprise Programming. Overview 2  Using Classes  Using premade classes for input and output  Display output: System, JOptionPane.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
Final Exam Review Closed book Closed laptop One sheet of notes permitted SE-0010 Dr. Mark L. Hornick 1.
Chapter 2 Elementary Programming
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.
JAVA PROGRAMMING BASICS CHAPTER 2. History of Java Begin with project Green in 1991 founded by Patrick Noughton, Mike Sheridan and James Gosling who worked.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
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.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Basics and arrays Operators:  Arithmetic: +, -, *, /, %  Relational:, >=, ==, !=  Logical: &&, ||, ! Primitive data types Byte(8), short(16), int(32),
Dialog Boxes.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
GUI Graphical User Interface Each onscreen component and window is an object Object interaction makes communication and scoping challenging Event-driven.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
CS-1010 Dr. Mark L. Hornick 1 Selection and Iteration and conditional expressions.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
Casting, Wrapper Classes, Static Methods, JOptionPane Class.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
INTERMEDIATE PROGRAMMING USING JAVA
Java Programming Lecture 2
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
3 Introduction to Classes and Objects.
Outline Creating Objects The String Class Packages Formatting Output
Data Types – Reference Types
John Hurley CS201 Cal State LA
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
Elementary Programming
2.5 Another Java Application: Adding Integers
CS116 OBJECT ORIENTED PROGRAMMING II LECTURE 1 Part II
Chapter 3 Java Input/Output.
Lecture Note Set 1 Thursday 12-May-05
Message, Input, Confirm, and Specialized Dialogs
OBJECT ORIENTED PROGRAMMING I LECTURE 7 GEORGE KOUTSOGIANNAKIS
Unit-2 Objects and Classes
An Introduction to Java – Part I, language basics
CS18000: Problem Solving and Object-Oriented Programming
Chapter 2 - Introduction to Java Applications
Chapter 3 Input/Output.
Message, Input, and Confirm Dialogs
Object Oriented Programming
JOptionPane class.
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

IC211 Lecture 8 I/O: Command Line And JOptionPane

Outline Review Project 1 Specification A Review of Scope Command Line Input –Wrapper Classes (Integer, Double, etc) I/O with JOptionPane

Scope Same as C++ Variable exists only within the block where it was declared Duplicate variable names within the same class file Example: execution class from Lab 4 Example: scope worksheet

Command Line Input Core Java 2 pg 84 public static void main (String[] args) args contains arguments from the command line Ex: MakeShape –c 3.5 args[0]: -c args[1]: 3.5 Both are Strings!

Converting Strings to Numbers (Wrapper Classes) Used to convert primitive types to Objects. Wrapper classes (Core Java pg 186) –Double, Float, Integer, Long, Short, Byte, Character, Boolean Some containers only hold objects, not primitives Can also be used to convert Strings to numbers Need to convert String representation 3.5 to numeric 3.5 –Double.parseDouble(String s) –Java SE 6 APIJava SE 6 API Ex: MakeShape.javaMakeShape.java

Output> Different! Comparing Integers, Doubles, etc. for Equality Scanner in = new Scanner(System.in); System.out.println("Enter two integers: "); Integer a = new Integer(in.nextInt()); Integer b = new Integer(in.nextInt()); if (a == b) System.out.println("Same!"); else System.out.println("Different!"); Enter two integers: Output> ??? Must use.equals() method vice ==, just like we do with Strings

JOptionPane Create message or dialog boxes without overhead of full GUI application Get input from the user with an input dialog box String name = JOptionPane.showInputDialog("What's your name?"); Part of the javax.swing package

JOptionPane Getting numeric input…must still use and input dialog box String input = JOptionPane.showInputDialog("Guess a number from 0 to 100"); Convert String input to numeric using wrapper classes int number = Integer.parseInt(input);

JOptionPane Display a message with a message dialog box JOptionPane.showMessageDialog(null, "Welcome to IC211!");

JOptionPane Getting a confirmation (yes/no) with a confirmation dialog box int done = JOptionPane.showConfirmDialog(null, “Are you finished?”); Returns an int equal to one of three static constants: –JOptionPane.YES_OPTION –JOptionPane.NO_OPTION –JOptionPane.CANCEL_OPTION

JOptionPane Example (Number Game) Guess a number from 0 to 100 –Version using console input (Scanner)Version using console input (Scanner) –JOptionPane versionJOptionPane version