Object Oriented Programming

Slides:



Advertisements
Similar presentations
Taking Input Java Md. Eftakhairul Islam
Advertisements

Question from the last class What happens if we cast “too large” float/double to an int? int has range float a=1e10f; int b=(int)
More Java Syntax. Scanner class Revisited The Scanner class is a class in java.util, which allows the user to read values of various types. There are.
Chapter 2 - Introduction to Java Applications
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2008.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Introduction to Computers and Programming Lecture 3: Variables and Input Professor: Evan Korth New York University.
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.
IC211 Lecture 8 I/O: Command Line And JOptionPane.
Introduction to Computers and Programming Lecture 4: Mathematical and Relational Operators.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
Chapter 2 - Introduction to Java Applications
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2010.
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.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
1 Scanner objects. 2 Interactive programs We have written programs that print console output. It is also possible to read input from the console.  The.
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.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
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.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
Interactive Programs with Scanner. 2 Input and System.in interactive program: Reads input from the console. –While the program runs, it asks the user.
Dialog Boxes.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
CHAPTER 5 GC 101 Input & Output 1. INTERACTIVE PROGRAMS  We have written programs that print console output, but it is also possible to read input from.
Creating and Using Dialogs ● A dialog is a box that pops up and prompts the user for a value or informs them of something ● One way: directly create objects.
Casting, Wrapper Classes, Static Methods, JOptionPane Class.
Object Oriented Programming Object and Classes Lecture 3 MBY.
Building Java Programs Chapter 4 Lecture 4-1: Scanner ; cumulative algorithms reading: 3.3 – 3.4, 4.2.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
AP Java 10/1/2015. public class Rolling { public static void main( String [] args) public static void main( String [] args) { int roll; int roll; for.
Introduction to programming in java
Introduction to Computer Science and Object-Oriented Programming
Building Java Programs
Java Programming Lecture 2
TemperatureConversion
Elementary Programming
2.5 Another Java Application: Adding Integers
Chapter 3 Java Input/Output.
Chapter 2 - Introduction to Java Applications
Message, Input, Confirm, and Specialized Dialogs
JOptionPane Dialogs javax.swing.JOptionPane is a class for creating dialog boxes. Has both static methods and instance methods for dialogs. Easy to create.
الكلية الجامعية للعلوم التطبيقية
Introduction to Classes and Methods
CS18000: Problem Solving and Object-Oriented Programming
Chapter 2 - Introduction to Java Applications
A+ Computer Science INPUT.
Unit 1: Intro Lesson 3: Input.
Chapter 2 - Introduction to Java Applications
AP Java 10/4/2016.
Chapter 3 Input/Output.
Message, Input, and Confirm Dialogs
A+ Computer Science INPUT.
CS431 ws99 Half Text Half Graphics
Building Java Programs
Chapter 2 - Introduction to Java Applications
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
JOptionPane class.
F II 2. Simple Java Programs Objectives
Building Java Programs
Chapter 2: Java Fundamentals cont’d
Optional Topic: User Input with Scanner
Presentation transcript:

Object Oriented Programming www.hndit.com Object Oriented Programming Lecture 04

www.hndit.com Dialog Boxes A JOptionPane object represents a dialog box for several purposes: 1. Display a message (through the use of the showMessageDialog method) Ask for user's confirmation (using the showConfirmDialog method) Obtain the user's input (using the showInputDialog method) Do the combined three above (using the showOptionDialog method)

www.hndit.com import javax.swing.JOptionPane; public class Addition { public static void main( String args[ ] ) String firstNumber = JOptionPane.showInputDialog( "Enter first integer" ); String secondNumber = JOptionPane.showInputDialog( "Enter second integer" ); int number1 = Integer.parseInt( firstNumber ); int number2 = Integer.parseInt( secondNumber ); int sum = number1 + number2; // add numbers JOptionPane.showMessageDialog( null, "The sum is " + sum, "Sum of Two Integers", JOptionPane.PLAIN_MESSAGE ); }

Scanner class(for console input) www.hndit.com Scanner class(for console input) The Scanner class is a class in java.util, which allows the user to read values of various types. Scanner in = new Scanner(System.in);

Methods in scanner class www.hndit.com Methods in scanner class int nextInt() Returns the next token as an int. If the next token is not an integer, InputMismatchException is thrown. String nextLine() Returns the rest of the current line, excluding any line separator at the end. long nextLong() float nextFloat() double nextDouble() String next() Finds and returns the next complete token from this scanner and returns it as a string; a token is usually ended by whitespace such as a blank or line break. If not token exists, NoSuchElementException is thrown.

www.hndit.com Example Scanner ob=new Scanner(System.in); System.out.println("Enter your username: "); String name=ob.nextLine(); System.out.println("Enter the value of a"); int a=ob.nextInt();