19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Triangle class <strong>to</strong> throw an IllegalTriangleException object if a triangle<br />

is created with sides that violate the rule, as follows:<br />

<strong>Programming</strong> Exercises 555<br />

/** Construct a triangle with the specified sides */<br />

public Triangle(double side1, double side2, double side3)<br />

throws IllegalTriangleException {<br />

// Implement it<br />

}<br />

*14.6 (NumberFormatException) Listing 9.2 implements the hexToDecimal(String<br />

hexString) method, which converts a hex string in<strong>to</strong> a decimal number.<br />

Implement the hexToDecimal method <strong>to</strong> throw a NumberFormatException<br />

if the string is not a hex string.<br />

*14.7 (NumberFormatException) <strong>Programming</strong> Exercise 9.8 specifies the<br />

binaryToDecimal(String binaryString) method, which converts a<br />

binary string in<strong>to</strong> a decimal number. Implement the binaryToDecimal method<br />

<strong>to</strong> throw a NumberFormatException if the string is not a binary string.<br />

*14.8 (HexFormatException) Exercise 14.6 implements the hexToDecimal method<br />

<strong>to</strong> throw a NumberFormatException if the string is not a hex string. Define a<br />

cus<strong>to</strong>m exception called HexFormatException. Implement the hexToDecimal<br />

method <strong>to</strong> throw a HexFormatException if the string is not a hex string.<br />

*14.9 (BinaryFormatException) Exercise 14.7 implements the binaryToDecimal<br />

method <strong>to</strong> throw a BinaryFormatException if the string is not a binary string.<br />

Define a cus<strong>to</strong>m exception called BinaryFormatException. Implement the<br />

binaryToDecimal method <strong>to</strong> throw a BinaryFormatException if the string<br />

is not a binary string.<br />

*14.10 (OutOfMemoryError) Write a program that causes the JVM <strong>to</strong> throw an<br />

OutOfMemoryError and catches and handles this error.<br />

VideoNote<br />

HexFormatException<br />

Sections 14.10–14.12<br />

**14.11 (Remove text) Write a program that removes all the occurrences of a specified<br />

string from a text file. For example, invoking<br />

java Exercise14_11 John filename<br />

removes the string John from the specified file. Your program should get the<br />

arguments from the <strong>com</strong>mand line.<br />

**14.12 (Reformat <strong>Java</strong> source code) Write a program that converts the <strong>Java</strong> source code<br />

from the next-line brace style <strong>to</strong> the end-of-line brace style. For example, the<br />

following <strong>Java</strong> source in (a) uses the next-line brace style. Your program converts<br />

it <strong>to</strong> the end-of-line brace style in (b).<br />

public class Test<br />

{<br />

public static void main(String[] args)<br />

{<br />

// Some statements<br />

}<br />

}<br />

(a) Next-line brace style<br />

public class Test {<br />

public static void main(String[] args) {<br />

// Some statements<br />

}<br />

}<br />

(b) End-of-line brace style

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!