Object Oriented Programming (OOP) LAB # 3 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.

Slides:



Advertisements
Similar presentations
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Advertisements

Chapter 2 - Introduction to Java Applications
Chapter 2: Using Data.
 2003 Prentice Hall, Inc. All rights reserved. 1 Lecture 3 Variables Primitive Data Types calculations & arithmetic operators Readings: Chapter 2.
Dialogs. Displaying Text in a Dialog Box Windows and dialog boxes –Up to this our output has been to the screen –Many Java applications use these to display.
Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2008.
Session #8 Dynamic HTML March 22, 2004
CS 106 Introduction to Computer Science I 09 / 14 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 01 / 29 / 2008 Instructor: Michael Eckmann.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
● Basic Computation Recitation – 09/(04,05)/2008 CS 180 Department of Computer Science, Purdue University.
Introduction to Computers and Programming Lecture 3: Variables and Input Professor: Evan Korth New York University.
 2003 Prentice Hall, Inc. Modified for use with this class. All rights reserved. 1 Introduction to Computers and Programming in JAVA: V Primitive.
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
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Chapter 2 Getting Started with Java Part B. Topics Components of a Java Program –classes –methods –comments –import statements Declaring and creating.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
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.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A First Program in Java: Printing.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
9/6: Variable Types, Arithmetic Operators, Comparison Operators Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic.
习 题 4.23 编写一个 applet ,读取一个矩形的边长,然后 用在 paint 方法中使用 drawString 方法画出用星组成 的空心矩形。程序应能画出边长从 1 到 20 的任何矩 形。
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
1 Java Programming 1 Introduction to Basic GUI Lesson 4.
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.
9/20: The while Repetition Structure last time’s program repetition structures: what they are the while repetition structure homework due on Thursday program.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
Chapter 3 Java Input/Output.
1/23: Java Modular Components Identifiers: naming requirements for Java variables & objects Stepping out of the MS-DOS window: The Java Modular Component:
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
CSC Programming I Lecture 6 September 4, 2002.
Dialog Boxes.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java Fundamentals Part Integer Division Division can be tricky. In a Java program, what is the value of 1/2? You might think the answer is.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
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.
InterestRate Create an InterestRate class and InterestRateViewer client class to do the following: A person is purchasing an item with their credit card.
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
A Sample Program #include using namespace std; int main(void) { cout
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.
1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A First Program in Java: Printing a Line of Text 2.2.1Compiling and Executing.
2.5 Another Java Application: Adding Integers
Section 64 – Manipulating Data Using Methods – Java Swing
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.
Command Line Arguments
Object Oriented Programming (OOP) LAB # 8
Chapter 2 - Introduction to Java Applications
Object Oriented Programming (OOP) LAB # 5
MSIS 655 Advanced Business Applications Programming
Chapter 2 - Introduction to Java Applications
AP Java 10/4/2016.
Message, Input, and Confirm Dialogs
CS431 ws99 Half Text Half Graphics
Chapter 2 - Introduction to Java Applications
JOptionPane class.
F II 2. Simple Java Programs Objectives
Unit 1: Intro Lesson 4: Output.
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

Object Oriented Programming (OOP) LAB # 3 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal

JOptionPane  JOptionPane is an easy way to do dialog boxes, messages or inputs. You have to import it at the beginning of the program:  Java: import javax.swing.JOptionPane;

The arguments for JOptionPane  for a simple message box: Java: JOptionPane.showMessageDialog ( null, "Put your message here" ); JOptionPane  to show text in different rows: JOptionPane.showMessageDialog ( null, "Put \nyour \nmessage \nhere" ); JOptionPane  the \n switches to next line

The arguments for JOptionPane  An example of using the simple message box

The arguments for JOptionPane  To show different messages with different icons, you'll need 4 arguments instead of 2.  Java: JOptionPane.showMessageDialog ( null, "Messagehere", "Title here", JOptionPane.IconName); JOptionPane  There are different kinds of icons for a dialog box, just replace the last argument:

The arguments for JOptionPane  You can also use JOptionPane for dialog boxes for input, and assign them to variables, just put:  Java: name= // The variable JOptionPane.showInputDialog ( "put your message here" ); JOptionPane  Notice that the variable here is String and you can convert it to integer as the following:  int x=Integer.parseInt(name);  note: after using JOptionPane, Dont forget to exit System.exit(0);

Example#1  Using JOptionPane, Write a program that asks a user to insert two numbers and displays the summation of them.

More Exercises on Java

Exercise #1  Develop a Java application that will determine whether a department- store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:  a) account number,  b) balance at the beginning of the month,  c) total of all items charged by the customer this month,  d) total of all credits applied to the customer’s account this month and  e) allowed credit limit.  The program should input each of these facts from input dialogs as integers, calculate the new balance (= beginning balance + charges – credits), display the new balance and determine whether the new balance exceeds the customer’s credit limit. For those customers whose credit limit is exceeded, the program should display the message “Credit limit exceeded.”

Solution#1

Testing #1

Exercise #2  A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, and Write an application that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message dialog indicating the problem to the user. When the user dismisses the error dialog, allow the user to enter a new value.

Solution #2

Testing #2

Exercise#3 (Homework)  A company wants to transmit data over the telephone, but is concerned that its phones may be tapped. It has asked you to write a program that will encrypt its data so that the data may be transmitted more securely. All of its data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user in an input dialog and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Write a separate application that inputs an encrypted four-digit integer and decrypts it to form the original number.