Java Reference
In-Depth Information
Triangle class to throw an IllegalTriangleException object if a triangle
is created with sides that violate the rule, as follows:
/** Construct a triangle with the specified sides */
public Triangle( double side1, double side2, double side3)
throws IllegalTriangleException {
// Implement it
}
*14.6
( NumberFormatException ) Listing 9.2 implements the hexToDecimal(String
hexString) method, which converts a hex string into a decimal number.
Implement the hexToDecimal method to throw a NumberFormatException
if the string is not a hex string.
*14.7
( NumberFormatException ) Programming Exercise 9.8 specifies the
binaryToDecimal(String binaryString) method, which converts a
binary string into a decimal number. Implement the binaryToDecimal method
to throw a NumberFormatException if the string is not a binary string.
*14.8
( HexFormatException ) Exercise 14.6 implements the hexToDecimal method
to throw a NumberFormatException if the string is not a hex string. Define a
custom exception called HexFormatException . Implement the hexToDecimal
method to throw a HexFormatException if the string is not a hex string.
VideoNote
HexFormatException
*14.9
( BinaryFormatException ) Exercise 14.7 implements the binaryToDecimal
method to throw a BinaryFormatException if the string is not a binary string.
Define a custom exception called BinaryFormatException . Implement the
binaryToDecimal method to throw a BinaryFormatException if the string
is not a binary string.
*14.10
( OutOfMemoryError ) Write a program that causes the JVM to throw an
OutOfMemoryError and catches and handles this error.
Sections 14.10-14.12
**14.11
( Remove text ) Write a program that removes all the occurrences of a specified
string from a text file. For example, invoking
java Exercise14_11 John filename
removes the string John from the specified file. Your program should get the
arguments from the command line.
**14.12
( Reformat Java source code ) Write a program that converts the Java source code
from the next-line brace style to the end-of-line brace style. For example, the
following Java source in (a) uses the next-line brace style. Your program con-
verts it to the end-of-line brace style in (b).
public class Test
{
public class Test {
public static void main(String[] args) {
// Some statements
public static void main(String[] args)
{
}
}
// Some statements
}
}
(a) Next-line brace style
(b) End-of-line brace style
Search WWH ::




Custom Search