Download presentation
Presentation is loading. Please wait.
Published byBarbara Marcia McLaughlin Modified over 8 years ago
1
CSE 1020:Using API Mark Shtern 1-1
2
Summary Delegation – Static Method, Object Client view vs Implementer view API, UML Errors Software Engineering Utility Class vs Object 1-2
3
Anatomy API Layout – The Class Section – The Field Section – The Construction Section – The Method Section 1-3
4
Fields public static final double PI Use the Integer class write a fragment that outputs the minimum value that an in can have 1-4 Answer: output.println (Integer.MIN_VALUE);
5
Methods public static double abs(double a) Write a fragment that prompts for and reads a real number from the end-user and outputs its absolute value using Math class. It is assumed that a Scanner instance with reference input and a PrintStream instance with reference output 1-5
6
Answer output.print (“Enter a real number: “); double number = input.nextDouble(); output.println(Math.abs(number)); 1-6
7
Method Overloading Binding with the Most Specific – Find the class – Find the method 1-7
8
Bind the invocation int x = Math.abs(2) 1-8
9
The Development Process Analysis phase – Input and Validation – Output and Formatting Design phase – Identifying the needed components – Coming up with Algorithm Implementation Testing and deployment 1-9
10
Input Print User friendly message Read user input (Scanner) 1-10
11
Output Formatting double x = 15.753 output.printf(“%.2f”,x); Format specify %[flags][width].[precision]conversion 1-11
12
Relation Operation int x = 7; int y = 5; boolean z = x < y; Relation operation in Java – Numeric, =, – Any type instanceof, ==, != 1-12
13
Input validation When input is invalid, then – Terminate the program and display a message – Explain the problem and ask the user to re-enter – Trigger an appropriate runtime error ToolBox.crash(boolean, String) 1-13
14
Assertion The assert statement does nothing if its condition is met but causes a runtime error if it is not assert y == 5; Recommendation: to use the assert statement whenever you believe that sometime is true To enable assertion java –ea App 1-14
15
Ex3.14 Provide a critique of the following fragment: int x = input.nextInt(); ToolBox.crash(x <= 0, “Invalid”); int y = input.nextInt(); ToolBox.crash(y <= 0, “Invalid”); boolean z = (x < y); boolean t = (x >=y); assert z != t; 1-15
16
Ex3.15 Is the syntax correct? What is the value of z? int x = 5; int y=-4; boolean z = x + y < 0; 1-16
17
Ex3.16 Is the syntax correct? What is the value of z? int x = 5; int y= x++; boolean z = x != y; 1-17
18
Ex3.18 Develop an application that converts Fahrenheit into Celsius 1-18
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.