Download presentation
Presentation is loading. Please wait.
1
Laboratory 4
2
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
3
Black Box testing Black Box
4
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"); }
5
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."); }
6
The whole program
7
Java Box and Conversion poundString = JOptionPane.showInputDialog( "Eng lish - metric conversion program.\nEnter the weight in pounds. " ); …….. pound = Integer.parseInt(poundString);
8
Show Message JOptionPane.showMessageDialog( null, "That's " + grams + " grams, or " + kilograms + " kilograms. “
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.