Laboratory 4.  This algorithm reads two numbers, A and B and prints the largest value and the samllerest value.  [Input data values] Read(A,B)  [Determine.

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

Session 3 Algorithm. Algorithm Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm Example Check.
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.
Unit 201 FILE IO Types of files Opening a text file for reading Reading from a text file Opening a text file for writing/appending Writing/appending to.
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2008.
Unit 191 Recursion General Algorithm for Recursion When to use and not use Recursion Recursion Removal Examples Comparison of the Iterative and Recursive.
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.
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.
Review. By the end of today you should be able to- Know how to use args Know how to use the JOptionPane Know how to convert a String to a number.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Chapter 3b Standard Input and Output Sample Development.
Reading Input -- the Keyboard Class The Keyboard class is NOT part of the Java standard class library The Keyboard class is in package cs1. It provides.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
Computer Programming Lab(4).
Computer Programming Lab(5).
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.
Example 1 :- Handling integer values public class Program1 { public static void main(String [] args) { int value1, value2, sum; value1 = Integer.parseInt(args[0]);
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
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.
CS1101: Programming Methodology Recitation 3 – Control Structures.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
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.
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 的任何矩 形。
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.
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.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
9/20: The while Repetition Structure last time’s program repetition structures: what they are the while repetition structure homework due on Thursday program.
Mixing integer and floating point numbers in an arithmetic operation.
Introduction to Programming
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.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
5-Dec-15 Sequential Files and Streams. 2 File Handling. File Concept.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
The while-statement. Syntax and meaning of the while-statement The LOOP-CONTINUATION-CONDITION is a Boolean expression (exactly the same as in the condition.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
2/18: Assignment Operators About Average2.java –while loop use –explicit casting –twoDigits object Assignment Operators Increment & Decrement Operators.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Files Review For output to a file: –FileOutputStream variable initialized to filename (String) and append/not append (boolean) –PrintWriter variable initialized.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
I/O in java and Revision. 2 I/O in Java Many packages and libraries associated with Java provide sophisticated ways to input and output information, e.g.:
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
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.
TemperatureConversion
A Java Program: // Fig. 2.1: Welcome1.java // Text-printing program.
using System; namespace Demo01 { class Program
AP Java 10/4/2016.
2.5 Another Java Application: Adding Integers
Lecture Note Set 1 Thursday 12-May-05
TK1114 Computer Programming
SELECTION STATEMENTS (1)
Reading and Writing Text Files
AP Java 10/4/2016.
class PrintOnetoTen { public static void main(String args[]) {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Object Oriented Programming
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Applet 2019/4/23.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
JOptionPane class.
F II 2. Simple Java Programs Objectives
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

Laboratory 4

 This algorithm reads two numbers, A and B and prints the largest value and the samllerest value.  [Input data values] Read(A,B)  [Determine largest values] MAX MAX Then MAX <- B  [Determine smallest values] MIN <- A If B < MIN Then MIN <- B  [Output results] Write('Largest value is', MAX,',Smallest is',MIN)  [Finished] Halt

Black Box testing Black Box

Revision of Question 3 import java.io.*; public class lab33 { public static void main(String[] arg) throws IOException { int p, o; float g; final int OZS_PER_LB = 16; final int GRAM_PER_OZ = 28; final float KG_PER_GRAM = 0.001f; System.out.println("English - metric conversion program. ") ; System.out.println("Enter the weight in pounds and ounces.") ; System.out.print("Pounds:") ; p = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine()); System.out.print("") ; System.out.print("Ounces:") ; o = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine()); g = (p*OZS_PER_LB + o)*GRAM_PER_OZ; System.out.println("That's " + g + " grams or " + g*KG_PER_GRAM + " Kilograms"); }

import javax.swing.JOptionPane; public class lab41 { public static void main(String[] arg) { int age; String ageString; ageString = JOptionPane.showInputDialog( "How are you\nEnter the age " ); age =Integer.parseInt(ageString); //convert the string into an integer JOptionPane.showMessageDialog( null, "That's my age is " + age + "old."); }

The whole program

Java Box and Conversion poundString = JOptionPane.showInputDialog( "Eng lish - metric conversion program.\nEnter the weight in pounds. " ); …….. pound = Integer.parseInt(poundString);

Show Message JOptionPane.showMessageDialog( null, "That's " + grams + " grams, or " + kilograms + " kilograms. “