Professional Documents
Culture Documents
Comprehensive Introduction to Object Oriented Programming with Java 1st Edition Wu Solutions Manual instant download all chapter
Comprehensive Introduction to Object Oriented Programming with Java 1st Edition Wu Solutions Manual instant download all chapter
Comprehensive Introduction to Object Oriented Programming with Java 1st Edition Wu Solutions Manual instant download all chapter
https://testbankdeal.com/product/introduction-to-java-
programming-comprehensive-version-10th-edition-liang-solutions-
manual/
https://testbankdeal.com/product/introduction-to-programming-
with-java-2nd-edition-dean-solutions-manual/
https://testbankdeal.com/product/object-oriented-approach-to-
programming-logic-and-design-4th-edition-joyce-farrell-solutions-
manual/
https://testbankdeal.com/product/introduction-to-java-
programming-comprehensive-version-10th-edition-liang-test-bank/
Introduction to Java Programming Comprehensive Version
9th Edition Liang Test Bank
https://testbankdeal.com/product/introduction-to-java-
programming-comprehensive-version-9th-edition-liang-test-bank/
https://testbankdeal.com/product/object-oriented-approach-to-
programming-logic-and-design-4th-edition-joyce-farrell-test-bank/
https://testbankdeal.com/product/introduction-to-javascript-
programming-with-xml-and-php-1st-edition-drake-solutions-manual/
https://testbankdeal.com/product/object-oriented-software-
engineering-an-agile-unified-methodology-1st-edition-kung-
solutions-manual/
https://testbankdeal.com/product/systems-analysis-and-design-an-
object-oriented-approach-with-uml-5th-edition-dennis-solutions-
manual/
Solutions to Chapter 8
1. Determine the output of the following code when the input is (a) –1, (b) 0, and (c) 12XY
try {
number = Integer.parseInt(
JOptionPane.showInputDialog(null, "input"));
if (number != 0) {
throw new Exception("Not Zero");
}
} catch (NumberFormatException e) {
System.out.println("Cannot convert to int");
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
2. Determine the output of the following code when the input is (a) –1, (b) 0, and (c) 12XY.
This is the same question as Exercise 1, but the code here has the finally clause.
try {
number = Integer.parseInt(
JOptionPane.showInputDialog(null, "input"));
if (number != 0) {
throw new Exception("Not Zero");
}
} catch (NumberFormatException e) {
System.out.println("Cannot convert to int");
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
} finally {
System.out.println("Finally Clause Executed");
}
We should throw an exception because the argument is invalid instead of using an assertion.
Remember: use assertions to detect internal errors and use exceptions to notify the client
programmers of the misuse of our class.
4. Modify the following code by adding the assert statement. The value of gender is either
MALE or FEMALE if the program is running correctly.
switch (gender) {
case MALE: totalFee = tuition + parkingFee;
break;
case FEMALE: totalFee = tuition + roomAndBoard;
break;
}
switch (gender) {
case MALE: totalFee = tuition + parkingFee;
break;
case FEMALE: totalFee = tuition + roomAndBoard;
break;
default: assert false:
"Value of gender " +
"is invalid. Value = " +
gender;
}
5. Modify the following method by adding the assert statement. Assume the variable factor is
a data member of the class.
6. Modify the getInput method of the InputHandler class from Section 8.7 so that the
method will throw an exception when an empty string is entered for the name, room, or
password. Define a new exception class EmptyInputException.
public void getInput( ) {
throws new EmptyInputException
name = JOptionPane.showInputDialog(null, "Enter Name:");
if (name.trim().equals(""))
throw new EmptyInputException("Name should not be empty");
room = JOptionPane.showInputDialog(null, "Enter Room No.:");
if (room.trim().equals(""))
throw new EmptyInputException("Room should not be empty");
pwd = JOptionPane.showInputDialog(null, "Enter Password:");
if (pwd.trim().equals(""))
throw new EmptyInputException("Password should not be
empty");
}
7. The user module of the keyless entry system in Section 8.7 does not include any logic to
terminate the program. Modify the program so it will terminate when the values Admin,
X123, and $maTrix%TwO$ are entered for name, room, and password, respectively.
This only requires changing the validate method in Ch8EntranceMonitor, and possibly
adding some new constants.
See Ch8EntranceMonitor.java
Development Exercises
8. In the sample development, we developed the user module of the keyless entry system. For
this exercise, implement the administrative module that allows the system administrator to
add and delete Resident objects and modify information on existing Resident objects. The
module will also allow the user to open a list from a file and save the list to a file. Is it
proper to implement the administrative module by using one class? Wouldn’t it be a better
design if we used multiple classes with each class doing a single well-defined task?
The solution here splits the problem into two classes, one to handle functionality and one to
handle the interface.
See files AdminHandler.java and Ch8EntranceAdmin.java
9. Write an application that maintains the membership lists of five social clubs in a dormitory.
The five social clubs are the Computer Science Club, Biology Club, Billiard Club, No Sleep
Club, and Wine Tasting Club. Use the Dorm class to manage the membership lists.
Members of the social clubs are Resident objects of the dorm. Use a separate file to store
the membership list for each club. Your program should be able to include a menu item for
each social club. When a club is selected, open a ClubFrame frame that will allow the user
to add, delete, or modify members of the club. The program can have up to five ClubFrame
frames opened at the same time. Make sure you do not open multiple instances of
ClubFrame for the same club.