JAVA PROGRAMMING 9TH
EDITION JOYCE FARRELL
SOLUTIONS MANUAL
cP
Tough Questions and Up for
Discussion Questions
There is more to being a successful programmer than writing programs that execute without
generating errors. To truly be a professional, you need more than a knowledge of Java syntax.
For example:
Your programs might work, but be inefficient. Throughout this book, you have been
encouraged to understand that there are often multiple ways to tackle the same problem, and
that some ways are more efficient or more elegant. For example, storing related values in an
array is almost always more elegant that storing them in a series
of separate variables.
Your programs might work, but not adhere to your organization’s coding standards.
For example, throughout this book you have been encouraged to use reasonable names for
variables rather than shorter, but cryptic, ones. Similarly, you have learned to use named
constants rather than to use unnamed constant values in your programs. Your employer might
have many more such standards.
Achieving success at a job interview involves being able to think on your feet, but
you can still be prepared. The Tough Questions presented here are organized by chapter. They
are similar to questions that an interviewer might ask at a technical job interview. Some require
you to write a program that is more difficult than those presented in the end-of-chapter
exercises in the book. After completing each chapter, you have the knowledge needed to write
the programs suggested here, but the thought process required might be a little deeper or
trickier.
Job interview success also sometimes depends on how articulate you are in
expressing opinions on a variety of topics. You can read many books on career advice that
describe typical generic interview questions such as “Where do you want to be five years from
now?” and “Tell me about a problem you had with a former boss and how you were able to
solve it”. The Up for Discussion questions presented here, and organized by chapter, are meant
to probe your thoughts on topics that are more
cP
specifically relevant to computer programmers and other business professionals. A particular
question might have several good answers. If you can’t think of an answer right away, try
doing some research on the Web or in other Java books.
Chapter 1
Tough Questions
1. Describe Java and how it differs from other programming languages.
For a job interview, you might start my memorizing this sentence:
Java is a simple, object-oriented, network-savvy, interpreted, robust, secure, architecture
neutral, portable, high-performance, multithreaded, dynamic language. Although the
meaning of all these terms won’t become clear until you have studied the language
further, you should at least appreciate that unlike older languages, it is object- oriented,
that it has a built-in library of routines that facilitate creating network connections, and
that it is interpreted meaning Java bytecodes are translated into machine instructions
while a program is running, giving Java its “write once; run anywhere” capability.
You might also mention that Java is a compiled language.
2. What is the difference between a compiler and an interpreter? Which does Java use? Why?
Compilers and interpreters both translate source code. A compiler translates the entire
program at once, then executes it. An interpreter, translates one statement, executes it,
translates the next statement, executes it, and so on.
Interpreted programs can start running faster – as soon as one statement is translated.
However, to run the program a second time, or to repeat a group of instructions, the
whole interpretation must take place again.
Compiled programs run faster, after the initial time is taken translate the whole program.
When a compiled program is run the second time, or a group of instructions is repeated,
it is very fast, because it is already compiled.
When a language is interpreted, the interpreter must be loaded into memory while the
cP
program runs, so there is less space available during execution. A compiler must only be
in memory when the program is being compiled.
Unlike other compiled languages that produce machine code for a specific computer, the
Java compiler produces bytecode that is not machine dependent. Any computer that has
the Java interpreter(The Java Virtual Machine) installed can read and understand the
bytecode.
3. What are the conventions for naming classes and variables in Java? What are the
advantages to using these conventions?
Class and variable names can have no embedded spaces and cannot be reserved words.
By convention, classes start with an uppercase letter and variables start with a lowercase
one. Following coding conventions helps the programmer stay organized. Additionally,
those who read the program have a clearer sense of the programmer’s intentions.
4. Can you store two public Java classes in the same file? How do you know?
No, because a filename must match the name of the class it contains.
Up for Discussion
1. Have you written programs in any programming language before starting this book?
If so, what do you think the advantages and disadvantages of using Java will be? If not, how
difficult do you think writing programs will be compared to other new skills you have
mastered?
Student answers will vary. Advantages of Java include being object-oriented and useful
for Web applications. Disadvantages include being less English-like than some other
languages.
2. Using the Web, try to discover which computer game is the most popular one ever
sold. Have you played this game? Would you like to? What makes this game so appealing?
Many Web sites provide different answers to what is the best selling or most popular
game, partially because games run on so many different platforms. Certainly, the families
of games featuring the Sims, Mario Brothers, and Halo are among the biggest
cP
sellers. In simulation games like the Sims, the player manages a group of people in
everyday situations. In particular women and older game players like them because
there is little violence and the games resemble everyday life; also unlike many other
games, you do not win or lose. (Because of the nature of book publishing, you might be
reading this several years after it was written. If other games have become more
popular, student answers will vary.)
3. Obviously, learning Java is useful to a Computer Information Systems major. List
several other major courses of study and discuss how programming skills might be useful to
them.
Many Web sites provide different answers to what is the best selling or most popular
game, partially because games run on so many different platforms. Certainly, the
families of games featuring the Sims, Mario Brothers, and Halo are among the biggest
sellers. In simulation games like the Sims, the player manages a group of people in
everyday situations. In particular women and older game players like them because
there is little violence and the games resemble everyday life; also unlike many other
games, you do not win or lose. (Because of the nature of book publishing, you might be
reading this several years after it was written. If other games have become more
popular, student answers will vary.)
4. Most programming texts encourage students to use many comments in their
programs. Many students feel that writing program comments is a waste of time. What is your
opinion? Why? Are there circumstances under which you would take the opposite stance?
Student answers will vary. Writing comments is time-consuming and seems to detract
from the “real” task of programming. However, good comments can help to clarify a
programmer’s intentions for readers and may help in debugging programs. If an
application must be completed quickly, many programmers would forego comments in
order to complete the project on schedule.
Chapter 2
cP
Tough Questions
1. In a single sentence, describe the relationship between associativity and precedence.
Associativity describes the order of operations with the same precedence.
2. Write Java statements that would round a numeric value to the nearest whole number. You
cannot use a prewritten round() method.
You can add 0.5 to a floating-point number, then cast it to an integer, and the result is
the rounded number. For example, if the starting value is 8.3, add 0.5 giving 8.8, then cast
to an integer, leaving 8. As another example, if the starting value is 8.5, then add
0.5, giving 9.0. When you cast to an integer, the result is 9. So the java statements are
similar to:
double tempResult = startingFloat + 0.05;
int finalRoundedResult = (int)tempResult;
3. Suppose you need to display the last digit of a four-digit number. You can use the
remainder operator (%) to extract the remainder when the number is divided by 10. Suppose
the “%” key is broken on your computer, but the program must be written immediately. What
would you do?
An interviewer will appreciate clever answers such as “Go find another computer,” and
“Copy a % operator out of another document and paste it into my program,” as long as
you follow up with a programming solution that shows you understand how the
remainder operator works.
To get a remainder without using the remainder operator you can perform integer
division, and then subtract that answer times the divisor from the original number. For
example, the value of 32 % 5 is the same as 32 – (32 / 5) * . The value of 32 % 5 is 2. The
value of 32 – (32 / 5) * 5 is the same as 32 - 6 * 5, which is the same as 32 – 30, which is 2.
The code is:
remainder = dividend – (dividend / divisor) * divisor;
cP
4. Write a series of Java statements that interchange the values of two numeric variables
without using a third variable.
This is very tricky! To reverse the values of num1 and num2, you can use the following
code
num1 = num1 + num2; num2 = num1 – num2; num1 = num1 – num2;
For example, assume num1 is 10 and num2 is 3.
After the first statement, num1 is 13 and num2 is still 3. After the second statement, num2
is 10 and num1 is 13. After the last statement, num1 is 3 and num2 is 10.
5. In many programming languages, a named constant must be assigned a value when it is
declared. This isn’t true in Java. Provide some examples of how this restriction might be
advantageous.
You might want a value to be constant throughout a program, yet not know the value
when the program starts. For example, in a biological simulation you might want
POPULATION_GROWTH_RATE to be a randomly-generated number, yet be constant
after it is generated. As another example, you might want a
EURO_TO_DOLLAR conversion rate figure to be constant throughout a program, but,
because it is a figure that changes constantly, allow a user to enter today’s conversion rate
at the start of the program.
Up for Discussion
cP
1. What advantages are there to requiring variables to have a data type?
It is easier for a person to distinguish between different types of data than it is for a
computer. For example, if a friend says, “The book cost twelve thirty-four” you recognize
the value as dollars and cents; if the friend says “Let’s meet for lunch at twelve thirtyfour,”
you
might
think
the
friend
is
a
little
too precise,
but
you recognize
the value
as
a
time
of
day.
Computer
data
is
stored
without
such
clues,
so declaring
a
data
type
provides
meaning
as to how
the values
should
be
used.
Major
functions
that type
systems
provide
include
the
following:
Error detection. Use of data types allows a compiler to detect some meaningless or
invalid code. For example, “cat” * 3is invalid -- a string cannot be multiplied
Optimization. Type-checking provides useful information to a compiler, allowing it to
use more efficient instructions to handle data.
Documentation. Types can make the programmer’s intent clearer.
2. Some programmers use a system called Hungarian notation when naming their variables.
What is Hungarian notation, and why do many object-oriented programmers feel it is not a
valuable style to use? What do you think?
Hungarian notation is a naming convention in computer programmer in which part of the
name of an object indicates its data type intended use. For example, an integer that holds
can account number might be named iAccountNum. Hungarian notation makes many
object names less readable and less pronounceable. Object-oriented programmers usually
create short methods in which there are few variables in a module. With code in clearly
named, short, concise modules, many object-oriented programmers feel there is no need
for the complexity that Hungarian notation adds.
3. Some languages do not require explicit type casting when you want to perform an unlike
assignment, such as assigning a double to an int. Instead, the type casting is performed
automatically, the fractional part of the double is lost, and the whole-number portion is simply
stored in the int result. Are there any reasons this approach is superior or inferior to the way
Java works? Which do you prefer?
An automatic type cast saves the programmer the keystrokes needed to create the cast
explicitly. However, without explicit casting, it is easier to make a mistake in which the
programmer does not realize a cast has occurred and significant data is lost.
cP
4. Did you have a favorite computer game when you were growing up? Do you have one
now? How are they similar and how are they different? Did you have a favorite board game?
What does it have in common with your favorite computer game?
Student answers will vary. Possibly students will see similarities and differences in games
that appeal to them in “real life” and on a computer. For example, some will prefer
games that emphasize cooperation whether playing a board game or a computer game.
Others will prefer heated competition no matter which genre of game is played. Some
game players prefer action, others prefer testing their recall or mental skills, and others
prefer games of pure chance.
Chapter 3
cP
Tough Questions
1. Describe some situations in which passing arguments to a method in the wrong order would
not cause any noticeable errors.
If a method accepts two parameters of the same type and returns their sum or product,
you would not notice if arguments were passed to it in the wrong order.
2. Suppose you have created a class named Employee. Further suppose that you have an
application that declares the following:
final Employee myEmployee = new Employee();
Can myEmployee’s fields be altered?
When final is used with an object, it refers to the reference to (address of) that object.
This means that you cannot assign another object to that address. However, you can use
methods such as setIdNumber() to alter the contents of the fields within the object.
3. Describe a chicken using a programming analogy. (This question is purposely vague and
even silly. Be creative.)
If a chicken is a method, you can describe its header as:
egg chicken(feed x)
In other words, you put feed into a chicken and get an egg.
If a chicken is a class, then it has fields such as weight and color, and contains methods to
get and set those fields as well as methods such as layEgg(), walk(), and peck().
4. Consider the real-life class named StateInTheUnitedStates. What are some real- life
attributes of this class that are static attributes, and what attributes are instance attributes?
Create another example of a real-life class and discuss what its static and instance members
might be.
cP
Each StateInTheUnitedStates, such as Alaska or Alabama, has its own name,
population, governor, average educational level, area in square miles, capitol, and so on.
Each of these is an instance variable. A field that has the same value for every
StateInTheUnitedStates, such as numberOf Senators (which is always
2), could be static. As another example, a class named Circlemight have instance
variables for radius or color, but diameterFactor(2) or
circumferenceFactor(3.14) can be static. A class named Bird can have
instance variables for name and color, but a static field to
hold numberOfLegs(2) or reproductionMethod(egg).
5. Can you think of any circumstances in which program comments would be a detriment?
This might be a tricky question to answer in a job interview because the interviewer
might have strong feelings about good commenting. However, to provide a thoughtful
answer, after you assure the interviewer that you believe in documenting programs
thoroughly, you could mention some drawbacks. For example, probably the biggest
drawback to documentation is when it is wrong, either because it was originally wrong, or
because program changes have made the existing, unchanged documentation obsolete. If
users or other programmers rely on incorrect documentation, they might misinterpret
output, make bad business decisions, and lose money. If no documentation exists, then at
least future programmers will have to look more closely at the code and figure out exactly
what is taking place. Additionally, at times, a program must be produced very quickly,
and you must skimp on documentation to get the needed results. Also, if you are
instructing someone on a fine point of programming, you might prefer
to just show them the code so as not to confuse the issue with embedded comments.
Up for Discussion
1. One of the advantages to writing a program that is subdivided into methods is that such a
structure allows different programmers to write separate methods, thus dividing the work.
Would you prefer to write a large program by yourself, or to work on a team in which each
programmer produces one or more modules? Why?
cP
Student answers will vary. Some students will prefer the team approach whereas others
will prefer the autonomy of developing a major system on their own.
2. Suppose you wrote a program that designed a building that collapsed. Would you rather have
been the only programmer who worked on the program and be totally responsible for one death,
or would you rather have worked with a team of 20 programmers, but the collapse caused 20
fatalities?
Student s will be divided on whether fewer deaths or less responsibility is more important
to them.
3. Hidden implementations are often said to exist in a black box. What are the advantages to
this approach in both programming and real life? Are there any disadvantages?
When implementation exists in a black box, you do not need to be concerned with the
details. In real life, when you use a device such as a television set, you do not have to be
concerned how the signals are transmitted from a far-off location to your living room.
In programming, you can use a module written by someone else, get correct results, and
not worry about how the results were achieved. However, when something goes wrong,
either in programming or real life, if you do not understand the hidden details, you are
less likely to know how to go about resolving problems.
Chapter 4
cP
Tough Questions
1. Give an example of a situation in which you would want a class’s field to be final but not
static. Give another example of when you would want a field to be static but not final.
Consider an Automobile class. You might want a VIN (Vehicle Identification
number) to be nonstatic because there is a different one for each instantiation. However,
the field should be final once an object is constructed. You might want a field like
countOfAutos to be static so that there is only one count that all objects share, but not
final so that it can be incremented or decremented when you add or remove an
Automobile.
2. Suppose class A contains a main() method that instantiates an object of class B. Can class
B also have a main() method? Explain your answer.
Yes. When you run a program using the java command and a class name, the JVM looks
for a main() method only in the class you have named. There is no conflict if there is also
a main() method (with the header public static void main(String[] args))in the other
class.
3. Can a single class contain two main() methods? Explain your answer.
Yes a class can contain two or more methods with the identifier main, but only one can
have the header public static void main(String[] args).
Up For Discussion
1. Java supports many prewritten classes such as Math and GregorianCalendar. Explore the
Java documentation at http://www.oracle.com/technetwork/java/index.html and find at least
three other built-in classes you think would be useful. Describe these classes and
cP
discuss the types of applications in which you would employ them.
Student answers should vary. Interesting classes include: Box, Color, Robot,
Window, and so on.
2. So far, the Game Zone sections at the ends of the chapters in this book have asked you to
create extremely simple games that rely on random-number generation. However, most
computer games are far more complex. If you are not familiar with them, find descriptions of
the games Grand Theft Auto and Stubbs the Zombie. Why are some people opposed to these
games? Do you approve of playing them? Would you impose any age restrictions on players?
People often are opposed to these games because of their violence. For example, they
might encourage players to kill prostitutes using a chain saw (Grand Theft Auto) or to eat
opponents’ brains (Stubbs the Zombie). Student answers about approval and age
restrictions will vary.
Chapter 5
Tough Questions
cP
1. What is a quick way to determine whether a value is even or odd?
Use the modulus operator. If number % 2 is 0 then the number is even; otherwise it is
odd.
2. What is the output of the following code?
public static void main(String args[])
{
int num = 5;
if(num > 0) System.out.println("true");
else; System.out.println("false");
}
The output is both “true” and “false” because of the semicolon that follows else. The
“false” statement is a stand-alone statement that always executes.
3. What is the output of the following code?
int x = 5;
boolean isNumBig = (x > 100);
if(isNumBig = true) System.out.println("Number is big");
else
System.out.println("Number is not big");
The output is “Number is big” because true is assigned to isNumBig within the if
statement because an assignment operator (the single equal sign) is used instead of the
comparison operator (two equals signs).
4. What is the output of the following code?
public static void main(String[] args)
{
cP
if(thisMethod() && thatMethod()) System.out.println("Goodbye");
}
public static boolean thisMethod()
{
System.out.println("Hello");
return false;
}
public static boolean thatMethod()
{
System.out.println("How are you?");
return true;
}
The output is just “Hello”. First, thisMethod() executes and displays “Hello”. The
method returns false, so the if is not evaluated any further. The thatMethod() method
never executes, and because the first part of the if expression was false. “Goodbye” is not
displayed.
5. Rewrite the following method to work exactly the same way as it does now, using as few
words as possible in the method body:
public static boolean interesting(boolean value)
{
if(value == true)
{
if(value == false)
value = false;
else
value = true;
}
else
if(value == false)
value = false;
else
value = true;
return value;
}
The method is simply:
public static boolean interesting(boolean value)
{
return value;
}
cP
6. What is the output of the following code, assuming that department = 1?
switch(department)
{
case 3: System.out.println("Manufacturing");
case 1: System.out.println("Accounting");
case 2:
System.out.println("Human Resources");
}
The output is as follows:
Accounting
Human Resources
The first case is bypassed because department is not 3. Without any break statements, all the
subsequent cases execute after a match is found.
Up for Discussion
1. Insurance companies use programs to make decisions about your insurability as well as the
rates you will be charged for health and life insurance policies. For example, certain preexisting
conditions may raise your insurance premiums considerably. Is it ethical for insurance companies
to access your health records and then make insurance decisions about you?
Student opinions should vary. If insurance companies cannot make decisions about
individuals, then everyone’s premiums are higher, or coverage is lower. Those who maintain
good health
cP
and avoid specific health risks such as smoking or skydiving would have to pay as much as
those who do choose to accept the risks of those behaviors. On the other hand, as medical
technology improves, minor conditions are more likely to be discovered. If you have an MRI
or similar test, a small cyst might be discovered that would have been overlooked 20 years
ago. This condition might never have any negative effect on your health, but now that it is
discovered, it puts you into a group at higher risk for other disorders, and your premiums
are higher for the rest of your life.
2. Job applications are sometimes screened by software that makes decisions about a candidate’s
suitability based on keywords in the applications. For example, when a help-wanted ad lists
“management experience,” the presence of those exact words might determine which résumés are
chosen for further scrutiny. Is such screening fair to applicants?
Student opinions should vary. If part of the application process is being smart enough to
realize what keywords to include, then shouldn’t those who include the correct words be
rewarded? Isn’t this skill similar to knowing how to dress appropriately for an interview or
having good grammar? On the other hand, a very good applicant who does not understand
the importance of using precise keywords might be overlooked, and the ability to recognize
the importance of including appropriate keywords might have no bearing on the applicant’s
future success on the job.
3. Medical facilities often have more patients waiting for organ transplants than there are
available organs. Suppose you have been asked to write a computer program that selects which
of several candidates should receive an available organ. What data would you want on file to use in
your program, and what decisions would you make based on the data? What data do you think others
might use that you would not use?
Student opinions should vary. Typical responses might consider the age of the patient and the
presence or absence of other existing medical conditions. Students might disagree with others
on attributes such as gender, occupation, ability to pay for the procedure, whether the
patient’s
parents have other children, whether the patient himself is a parent or otherwise responsible
for other people, probable quality of life after the procedure, and so on.
Chapter 6
Tough Questions
cP
1. Suppose that the multiplication operator did not exist. Write a method that would accept
two integers and return their product.
The student demonstrate an understanding that multiplication is simply a series of
addition operations as follows:
int multiply(int a, int b)
{
int answer = 0;
for(int count = 0; count < b; ++count)
answer += a;
return answer;
}
2. Suppose that the division operator did not exist. Write a method that would accept two
integers and produce the result when the first integer is divided by the second.
The student should demonstrate an understanding that division is simply a series of
subtraction operations as follows:
int divide(int a, int b)
{
int count = 0;
while(a >= b)
{
a -= b;
++count;
}
return count;
}
3. If you need a variable inside a loop, should it be declared before the loop, or inside it? For
example, which of the following is better?
double money;
for(int x = 0; x < LIMIT; ++x)
{
money = input.nextDouble(); System.out.println(“You
entered “ + money);
The variable money is
declared outside the
loop.
}
for(int x = 0; x < LIMIT; ++x)
{
The variable money is
declared inside the loop.
cP
double money = input.nextDouble(); System.out.println(“You entered “ + money);
}
This question is controversial, so your best answer at an interview would present both
sides of the answer. Many programmers believe that the variable should be declared
outside the loop to avoid the overhead of redeclaring it for each loop repetition. However,
studies have shown, that no extra machine code is generated using the second method.
Proponents of declaring the variable inside the loop argue that the loop is easier to debug
because the declaration “goes with” the code that uses it. If money is an object instead of
a primitive data type, then continually redeclaring it within the loop will require time
and resources.
4. What is the output of the following? Why? final int STOP = Integer.MAX_VALUE;
final int START = STOP - 10;
int count = 0;
for(int x = START; x < STOP; ++x)
{
++count; System.out.println(count);
}
count = 0;
for(int x = START; x = values.length / 2)
{
System.out.println("The majority value is " +
values[x]);
x = values.length;
y = values.length;
}
}
}
}
Up for Discussion
cP
1. A train schedule is an everyday, real-life example of an array. Think of at least four more.
Student answers will vary but might include:
tax table
life expectancy table based on year of birth
insurance company height and weight table
loan amortization schedule
company salary schedule
instructor’s grading scale
shipping charges based on distance
sliding fees for a service based on income
2. In the “You Do It” section of Chapter 8, an array is used to hold a restaurant menu. Where
else do you use menus?
Menus are used in software and telephone systems. You are presented with a menu when
programming a VCR. Movies on DVDs usually have a menu from which you can select
specific movie scenes or other features. In business, the term can be used to mean “an
agenda”. (Besides meaning a list of food choices in a restaurant, the term “menu” also
means the specific list of foods being served, as in “She planned her menu for the week.”)
3. Fifty or 60 years ago, most people’s paychecks were produced by hand; now it is most likely
that yours is produced by a computer, or not printed at all but deposited into an account
electronically. Forty years ago, most grocery store checkers keyed item prices
into the cash register; now it is most likely your items are scanned. Police officers used to
cP
direct traffic at many major urban intersections; now the traffic flow is often computer
controlled. Are there any tasks now that are mostly done by people that you think would be
better handled by a computer? Are than any tasks you hope never become computerized?
Student answers should vary widely and be creaive. Students might agree that dangerous
jobs such as coal mining might be better carried out by computers. Computers could
better locate people in a burning building, saving the lives of firefighters. Students might
not agree on whether the following would be beneficial:
College classes could be taught by computers, eliminating teachers.
Court cases could be judged by computers, eliminating lawyers and judges.
Medical diagnoses and surgery could be performed by computers, eliminating some
doctors; medicine can be dispensed by computers, eliminating some nurses.
Movies could all be produced using computerized actors, eliminating the
need for real-life actors.
All sorts of scheduling can be computerized – medical appointments, turnover of
restaurant tables, salon services.
Robots can clean, houses, office buildings, hotel rooms, and so on.
Chapter 9
Tough Questions
1. Write a method that returns true or false to indicate whether a passed integer array
contains any duplicates.
public static boolean findDuplicates(int[] values)
{
int x;
int y;
boolean duplicates = false;
for(x = 0; x < values.length - 1 &&
duplicates == false; ++x)
{
y = x + 1;
while(y < values.length)
{
if(values[x] == values[y])
{
duplicates = true;
}
++y;
}
}
return duplicates;
}
Up for Discussion
cP
1. This chapter discusses sorting data. Suppose you are hired by a large hospital to write a
program that displays lists of potential organ recipients. The hospital’s doctors will consult this
list if they have an organ that can be transplanted. You are instructed to sort potential recipients
by last name and display them sequentially in alphabetical order. If more than 10 patients are
waiting for a particular organ, the first 10 patients are displayed; the user can either select one
of these or move on to view the next set of 10 patients. You worry that this system gives an
unfair advantage to patients with last names that start with A, B, C, and D. Should you write
and install the program? If you do not, many transplant opportunities will be missed while the
hospital searches for another programmer to write the program.
Student answers will vary. They should realize that controlling something as trivial as the
order in which patients are displayed can change lives dramatically. Some students will
feel that a programmer is paid to program and does not have a right to offer an opinion
on medical issues. They might also feel that if they do not write the program someone else
will. Others will discuss the fact that if patients are not listed in alphabetical order, they
will be listed in some other order, which might be worse. Perhaps doctors should assign
an urgency ranking to the patients, or the patients should be displayed by geographical
distance from the donor organ.
2. This chapter discusses sorting data. Suppose your supervisor asks you to create a report
that lists all employees sorted by salary. Suppose you also know that your employer will use
this report to lay off the highest-paid employee in each department. Would you agree to write
the program? Instead, what if the report’s purpose was to list the worst performer in each
department in terms of sales? What if the report grouped employees by gender? What if the
cP
report grouped employees by race? Suppose your supervisor asks you to sort employees by the
dollar value of medical insurance claims they have in a year, and you fear the employer will
use the report to eliminate workers who are driving up the organization’s medical insurance
costs. Do you agree to write the program even if you know that the purpose of the report is to
eliminate workers?
Student answers will vary. Some students will write the programs because they reason, if
they do not, someone else will write it anyhow. Some will argue that the company owns
the data and their job is to do what they are told. Others might not object to the high
paid workers being dismissed but might struggle with the concept if workers are
categorized by race or gender. Some students might not object to the high-claims
employees being dismissed; others will argue that the reason for group insurance is to
spread the risk of claims and employees should not be eliminated just because they are
unfortunate enough to need extra services.
Chapter 10
cP
Tough Questions
1. Describe the difference between overloading and overriding in an inheritance situation.
When a child class method overloads a parent class method, it has the same name but a
different parameter list. An object of the child class can call either method depending
on the arguments used. When a child class method overrides a parent class method, it has
the same name and arguments list; it hides the parent class method.
2. Suppose a base class contains a default constructor. Can you call it explicitly from within a
derived class constructor?
When a child class method overloads a parent class method, it has the same name but a
different parameter list. An object of the child class can call either method depending
on the arguments used. When a child class method overrides a parent class method, it has
the same name and arguments list; it hides the parent class method.
3. Within a child class you can call a parent class method using the keyword super, a dot, and
the method name. Can you also call a parent method using the parent class name, a dot, and
the method name? Why or why not?
You can call a static parent class method using the class name, a dot, and the method
name, but you cannot call a nonstatic method because a nonstatic method requires an
object instantiation.
Up for Discussion
1. In this chapter, you learned the difference between public, private, and protected class
members. Some programmers are opposed to classifying class members as protected. Why do
they feel that way? Do you agree with them?
2. Some purists believe that all class members should be public or private. Creating
protected members is convenient for using them in child classes, but child classes could
cP
also access data using public methods just like any other class. Some feel that if data
should be private then it should always be private.
3. Some programmers argue that, in general, superclasses are larger than subclasses. Others
argue that, in general, subclasses are larger. How can both be correct?
In general you can think of a subclass as larger than a superclass because it usually has
additional fields and methods. A subclass object contains all the fields and methods of its
parent plus new ones. However, the subclass description might look small, because it
might have only a few unique attributes in addition to its parents’.
4. Playing computer games has been shown to increase the level of dopamine in the human
brain. High levels of this substance are associated with addiction to drugs. Suppose you work
for a game manufacturer that decides to research how its games can produce more dopamine in
the brains of players. Would you support the company’s decision?
Student answers will vary. Some may be outraged that a company would alter brain
chemicals. Others would argue that all pleasant products from movies to songs to games
probably alter brain chemistry to some extent. Most advertising is based on creating
pleasing images and causing desire for the product in the viewer.
5. In one of the exercises at the end of this chapter, you store an employee’s Social Security
number. Besides using it for tax purposes, many organizations also use this number as an
identification number. Is this a good idea? Is a Social Security number unique?
Contrary to the popular conception, Social Security numbers are not unique. Although
the Social Security Administration (SSA) intended that Social Security numbers be
unique, it occasionally has given a previously issued number to someone with the same
name and birth date. In addition, identity thieves sometimes use an existing number. For
example, 078-05-1120 was a Social Security number that was printed on “sample” cards
inserted in thousands of new wallets sold in the 1940s and 50s. Many people just started
using this sample card, and it has been so widely used that government agencies
immediately recognize it immediately as invalid. At least 40 people were once listed in the
Selective Service database as having this number as their Social Security Number. The
SSA recommends that fictional Social Security cards in advertisements use numbers in
the range of 987-65-4320 through 987-65-4329.
Chapter 11
Tough Questions
cP
1. Describe the signature of the Object class constructor and explain how you know your
answer is correct.
The Object class constructor requires no parameters. You know because when you create
classes, you are not required to call super(). Of course like all constructors, its identifier is
the same as its classname and it has no return type.
2. Can an abstract class have a final method? Why or why not?
An abstract class cannot have a final method because abstract classes are meant to be
extended and their methods are required to be overridden in child classes. However, final
methods cannot be overridden.
3. Write the Object class equals() method to match as closely as possible the original
version written by Java’s creators.
The method must look close to this:
public boolean equals(Object obj)
{
return (this == obj);
}
The original creators might have used a different local name for obj and they might have
stored the result of this == obj in a variable before returning it, but the access modifier,
return type, method identifier, and parameter list must be as shown here.
Up for Discussion
1. Programming sometimes can be done from a remote location. For example, as a
professional programmer, you might be able to work from home. Does this appeal to you?
What are the advantages and disadvantages? If you have other programmers working for you,
would you allow them to work from home? Would you require any “face time”—that is, time
in the office with you or other workers?
cP
Student answers will vary. Advantages to working at home might include lowered (or
absent) wardrobe, childcare, and commuting expenses. Other lowered expenses are eating
lunch at home, and not needing to contribute to office gifts, pools, and fundraisers.
Besides the cost, commuting time is saved. Disadvantages include lack of social contact,
and the potential distractions caused by children, friends, television, and even the home
refrigerator.
2. Programming sometimes can be done from a remote location. For example, your
organization might contract programmers who live in another country, where wages are
considerably lower than in the United States. Do you have any objections to employers using
these workers? If not, what objections do you think others might have?
Some will object to the possibility of lost jobs, or, if employees keep their jobs, the
difficulties in communicating effectively with the new workers. Outsourcing is an
economic decision, and if a company’s mission can be achieved at a lower cost, the
company has an obligation to stockholders to pursue that goal. However, if cultural and
language differences become a hindrance and prevent the functions of the organization
from being done better (or at all), then outsourcing might be a poor economic decision.
Some students may also consider increased security threats from foreign workers.
3. Suppose your organization hires programmers to work in another country. Suppose you
also discover that working conditions there are not the same as in your country. For example,
the buildings in which the workers do their jobs might not be subject to the same standards for
ventilation and fire codes as the building where you work. Is your company under any
obligation to change the working conditions?
Student answers will differ. Some will say that as long as local ordinances are met,
everything is fine. Others will hold their country’s businesses to a higher standard.
Students might mention that if higher standards are enforced, and assuming the higher
standards have a cost, some companies might choose to not continue to do business in the
country. Some students will see this positively as business will move from the remote
country back to their own more prosperous countries. Others will see this negatively, as
the business provide needed emloyment for workers in the poorer countries.
cP
Chapter 12
Tough Questions
)
cP
1. Many Java Exception classes are located in the package java.lang. Why is the
InputMismatchException class located in java.util?
InputMismatchException is located in the same package as the Scanner class because it is
the exception thrown when Scanner input fails.
2. Under what circumstances will a finally block not execute or not execute completely?
A finally block will not execute if a System.exit() statement executes in before it, if an
exception arises in the finally block, or if the CPU loses power. Additionally, students
might find information about thread death.
3. What is output by the following method?
public class Test
{
public static void main(String[] args)
{
System.out.println(method());
}
public static boolean method()
{
try
{
return true;
}
finally
{
return false;
}
}
}
The output is false. Even though there is a return statement in the try block, the
finally block executes before the method finishes.
)
cP
4. Write a loop that assigns the number 15 to every element in an array without using any
comparison operators such as or !=. (Remember, this chapter covers Exceptions.)
One possibility is as follows:
try
{
for(int x = 0; ; ++x)
array[x] = 15;
}
catch(ArrayIndexOutOfBoundsException e)
{
}
Up for Discussion
1. The terms syntactic sugar and syntactic salt were described in this chapter. There are no
hard and fast rules to assigning these terms to language features; it is somewhat a matter of
opinion. From your knowledge of the Java programming language, list as many syntactic sugar
and salt features as you can.
Some examples of syntactic sugar include:
You can use the AND and OR operators in Boolean expressions instead of harder-toread
nested
if
statements
You can use a switch structure instead of nested ifs
You can use the conditional operator (?) instead of an if
You can use the arithmetic shortcut operators ++ and --
You can use a for loop or a do…while if either is more convenient than a while loop
You do not need to use the keyword new when instantiating a String as you do with
other class objects
You do not have to call a function such as add(x, y) to perform arithmetic. Instead,
built-in
operators, such as + have been defined.
You are not required to explicitly write a constructor for a class if you want the
default one.
You are not required to explicitly provide values for class member if you want the
default values.
Some examples of syntactic salt include:
You must use a return type with a method
)
cP
You must use opening and closing curly braces with a block
You must use two semicolons in a for statement, even if a section is left blank
2. In the programming community, there is controversy over whether Java’s requirement of
specifying checked exceptions is a good policy. Investigate the controversy and explain your
opinion.
Some programmers feel that programmers are tempted to write code that throws only
unchecked exceptions because it is “less work.” (Java does not require methods to catch
or to specify unchecked exceptions.) Others feel that requiring checked exceptions
provides more information to a methods’ clients.
3. Have you ever been victimized by a computer error? For example, were you ever
incorrectly denied credit, billed for something you did not purchase, or assigned an incorrect
grade in a course? How did you resolve the problem? On the Web, find the most outrageous
story you can involving a computer error.
Student answers will vary, and, hopefully, be entertaining. Some stories from the news
have included:
Consumers have been billed repeatedly billed by computers for $0 balances.
Airplanes have been shot down due to misleading air traffic tracking software.
Motor vehicle operators have been repeatedly stopped for driving a stolen vehicle
when, in fact, the vehicle had been stolen but was recovered and returned to the
legitimate owner.
Several 1985-7 deaths of cancer patients were due to overdoses of radiation resulting
from a race condition between concurrent tasks in the Therac-25 software.
The IRS uncovered an unintended side effect of its effort to eliminate the Year 2000
computer bug: About 1,000 taxpayers who were current in their tax installment
agreements were suddenly declared in default due to a programming error.
4. Search the Web for information about educational video games in which historical
simulations are presented in an effort to teach students about history. For example,
)
cP
Civilization III is a game in which players control a society as it progresses through time. Do
you believe such games are useful to history students? Does the knowledge gained warrant the
hours it takes to master the games? Do the makers of the games have any obligations to present
history factually? Do they have a right to penalize players who choose options of which the
game writers disapprove (such as using nuclear weapons or allowing slavery)? Do game
creators have the right to create characters who possess negative stereotypical traits— for
example, a person of a specific nationality portrayed as being stupid, weak, or evil? Would you
like to take a history course that uses similar games?
Many students who have used games in courses felt they better understood what it takes
to balance a country and advance a civilization. However, some instructors report
historical inaccuracies and misunderstandings. Research suggested that gamers develop
better rapid problem solving skills than non-gamers, and the United States military uses
simulation trainers. Some students will feel that true knowledge needs to be acquired with
more “pain,” that is, studying the old-fashioned way. Others might feel that such
simulations help to engage
otherwise disinterested students.
Chapter 13
)
cP
Tough Questions
1. Does the Path class contain any methods for reading from or writing to files? Why? No.
The Path class is intended to be a means to locate and access files. The file referenced is
not even required to exits.
2. If a program must use a file several times, is it better to open and close it each time or keep it
open for the duration of the program?
Interviewers will have different opinions on this question, so it is probably safest to
show that you know the advantages of each approach. If you keep a shared file open for
the duration of a long program, it is not available to other applications. However, you
save the overhead of repeatedly opening and closing the file.
2. In Chapter 13 you learned to create random access files into which records were placed based
on an ID number. Create a random access file into which records are placed based on an
alphabetic field. Assume records contain a last name and first name. Allow a user to
continuously enter records and store them in a file based on the first letter of the last
name. Leave room for up to 10 records that start with each initial. Figure TQ-1 shows a typical
output file. Notice the names are not necessarily in alphabetical order; instead, they are grouped
by initial letter.
cP
Figure TQ-1 Typical random access file created alphabetically
The tricky arts are converting the letter to a number, and increasing the file pointer
position when a record has already been stored for a letter.
import java.nio.file.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.ByteBuffer;
import static java.nio.file.StandardOpenOption.*;
import java.util.Scanner;
import java.text.*;
public class AlphaRandomRecords
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); Path file =
Paths.get("C:\\Java\\Chapter.13\\People.txt");
String delimiter = ",";
String blankName = " ";
String sample = blankName + delimiter + blankName +
System.getProperty("line.separator");
byte[] data = sample.getBytes(); String s, s2;
Downloaded by Clare Kemmy (clarekemmy@gmail.com)
cP
final int RECSIZE = sample.length(); FileChannel fc = null;
ByteBuffer buffer = ByteBuffer.wrap(data); final int LENGTH =
blankName.length(); final int NUM_FOR_EACH_LETTER = 10;
final int NUMRECS = 26 * NUM_FOR_EACH_LETTER;
long pos;
int firstChar;
String first; String last;
String[] array = new String[2];
final String QUIT = "XXX";
try
{
OutputStream output = new
BufferedOutputStream(file.newOutputStream(CREATE)); BufferedWriter
writer = new
BufferedWriter(new OutputStreamWriter(output));
for(int count = 0; count < NUMRECS; ++count)
writer.write(sample, 0, sample.length());
writer.close();
}
catch(Exception e)
{
}
try
{
System.out.println("Error message: " + e);
fc = (FileChannel)file.newByteChannel(WRITE, READ);
System.out.print("Enter first name >> "); first = input.nextLine();
while(!(first.equals(QUIT)))
{
System.out.print("Enter last name >> ");
last = input.nextLine();
StringBuilder sb = new StringBuilder(first);
sb.setLength(LENGTH);
first = sb.toString();
sb = new StringBuilder(last);
sb.setLength(LENGTH);
last = sb.toString();
s = last + delimiter + first +
System.getProperty("line.separator");
firstChar = last.charAt(0);
firstChar -= 'A';
pos = firstChar * RECSIZE * NUM_FOR_EACH_LETTER;
fc.position(pos);
fc.read(buffer);
buffer= ByteBuffer.wrap(data);
s2 = new String(data);
while(!s2.equals(sample))
{
Downloaded by Clare Kemmy (clarekemmy@gmail.com)
fc.read(buffer);
buffer = ByteBuffer.wrap(data);
s2 = new String(data);
pos += RECSIZE;
}
data = s.getBytes();
cP
buffer = ByteBuffer.wrap(data); pos -= RECSIZE; fc.position(pos); fc.write(buffer);
System.out.print
("Enter next first name or " + QUIT + " to quit >> ");
first = input.nextLine();
}
fc.close();
}
catch (Exception e)
{
System.out.println("Error message: " + e);
}
}
}
Up for Discussion
1. In an exercise at the end of this chapter, what did you discover about the size difference of
files that held the same contents but were created using different software (such as Word and
Notepad)? Why do you think the file sizes are so different, even though the files contain the
same data?
Applications like Word are “memory hogs” because so much information is contained in
them. Every letter in a document has a font, size, color, and so on. The text in a program
like Notepad is stored in a much simpler format.
2. Locate several .class files that resulted from compiling any Java programs you have written.
(If you have deleted all your .class files, simply compile a few of your Java programs to
recreate them.) Using a text editor, such as Notepad, open these files. Confirm that the first four
characters (Êþº¾) are the same in each of the compiled files. Find an online program
that translates characters to their hexadecimal values and discover the translated value of this
character set. What is the significance of the value? Why do all .class files start with the same set
of characters?
cP
The hexadecimal values spell CAFÉ BABE. The developers of Java wanted a way to
distingush compiled class files and wanted to use a reference to coffee (café) and the
hexadecimal “alphabet” is limited to the letters A through F.
3. Suppose your employer asks you to write a program that lists all the company’s employees,
their salaries, and their ages. You are provided with the personnel file to use as input. You
decide to take the file home so you can create the report over the weekend. Is this acceptable?
What if the file contained only employees’ names and departments, but not more sensitive data
such as salaries and ages?
Student answers will vary. Students might feel that because they are allowed to work
with the file, the location where they work is of little importance. Their answers might
also depend on the company’s past practices.
Chapter 14
cP
Tough Questions
1. What happens when you use the following Font in a JLabel?
Font newFont = new Font("Arial ", 12, Font.BOLD);
The program compiles and runs, but because the point size and style are in the wrong
order, the point size becomes 1 (which is the value of Font.BOLD), and it is too small to
see.
2. The AWT provided for UI objects before Swing was invented. What are the advantages and
disadvantages of using Swing components over those defined in the AWT?
The AWT uses heavyweight components. This means AWT is usually slightly faster,
though with modern hardware, you probably won’t notice the difference. AWT
applications look different
on different platforms, but Swing applications look the same on all platforms. The main
advantage of Swing is it gives you finer control over the look and feel of your components.
Swing is bigger and more complicated, and is not supported by earlier versions of Java.
Up for Discussion
1. Suppose you are asked to create a Web application that allows users to play online
gambling games in which they can win and lose real money after providing a credit card
number. Would you want to work on such a site? Would you impose any restrictions on users’
losses or the amount of time they can play in a day? If your supervisors asked you to create a
Web site that would be so engaging that gamblers would not want to leave it, would
you agree to write the application? If a family member of an addicted gambler contacted you
(as the webmaster of the site) and asked that their relative be barred from further gambling,
would you block the user?
Student answers will vary. Student answers might depend on whether they are personally
acquainted with someone who gambles excessively. Students might be
cP
concerned about legal ramifications of denying access to someone based on another’s
opinion, or, on the other hand, allowing access to someone who is known to have a
gambling problem.
2. Would you ever use a computer dating site? Would you go on a date with someone you met
over the Web? What precautions would you take before such a date?
Student answers will vary. Precautions might include asking for references, checking out
the date beforehand, and meeting in a public place.
3. At least one lawsuit has been filed by a Web user who claims a Web site discriminated
against him on the basis of marital status. The Web site is a dating service that does not allow
married participants. How do you feel about this case?
Many students will object to frivolous lawsuits; they understand that a dating service site
implies single participants.
Chapter 15
cP
Tough Questions
1. In this chapter you learned there is no built-in ActionAdapter class. If there was one, what
would the code look like?
The ActionAdapter class would implement ActionListner and contain an abstract
actionPerformed method as follows:
package java.awt.event;
import java.awt.event.*;
public abstract class ActionAdapter extends Object implements
ActionListener
{
public ActionAdapter()
{}
public abstract void actionPerformed(ActionEvent e);
}
2. Describe some general guidelines for developing professional GUI applications.
In general, GUI applications should be simple, not too busy, and not crowded. Fewer fonts
and colors are better than too many. Any graphic images should be selected carefully. The
user should be kept in mind; if a user cannot navigate your application easily, he will quit.
Up for Discussion
1. If you are completing all the programming exercises in this book, you know that working
programs require a lot of time to write and test. Professional programs require even more hours
of work. In the workplace, programs frequently must be completed by strict deadlines; for
example, a tax-calculating program must be completed by year’s end, or an advertising Web
site must be completed by the launch of the product. Programmers often find themselves
working into the evenings or on weekends to complete “rush” projects. How do you feel
about having to do this? What types of compensation would make the hours worthwhile for
you?
cP
In the author’s experience, younger students tend to think monetary rewards are most
important, and they are willing to work long hours to attain them. Older students more
frequently value time over money.
2. Suppose your organization asks you to develop a code of ethics for the Information
Technology Department. What would you include?
Student answers might include any of the following and more:
Employment practices, including workplace harassment, equal opportunity and
discrimination, diversity, fair treatment of employees, use of illegal substances and
organizational property including Internet access.
Employee, and client information, including maintaining records, privacy, and
disclosure issues.
Public information including advertising
Conflicts of interest including gifts to employees, employees’ political activity,
financial interests, and outside employment
Environmental issues, including employee safety and health
Ethical management practices including accuracy of accounting practices
Chapter 16
cP
Tough Questions
1. Write a program that displays two rectangles. Then, in another color, show the
overlapping portion whose dimensions you calculate based on the arguments to the original
rectangles.
Here is one possibility:
import javax.swing.*;
import java.awt.*;
public class OverlappingRectangles extends JFrame
{
int x, y, w, h, x1, y1, w1, h1;
int right, left, bottom, right1, left1, bottom1;
int newx, newy, neww, newh;
public OverlappingRectangles()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField xField = new
JTextField();
x = 20; y = 20; w = 50; h = 50;
x1 = 40; y1 = 40; w1 = 50; h1 = 50;
right = x + w; bottom = x + h; right1 = x1 + w1; bottom1 = x1 + h1;
overlap();
}
public void paint(Graphics g)
{
super.paint(g); g.setColor(Color.BLUE); g.drawRect(x, y, w, h); g.drawRect(x1, y1,
w1, h1); g.setColor(Color.RED); g.drawRect(newx, newy, neww, newh);
}
public void overlap()
{
newx = ( x > x1 ? x : x1 );
newy = ( y > y1 ? y : y1 );
neww = ( right < right1 ? x + w - x1 : x1);
cP
newh = ( bottom < bottom1 ? y + h - y1 : y1 );
}
public static void main(String[] args)
{
OverlappingRectangles frame = new OverlappingRectangles();
frame.setSize(500, 500);
frame.setVisible(true);
}
}
2. Java has a setIgnoreRepaint() method that you can use to ignore a repainting request in
a graphics program. Why would you do so?
If a program must redraw many components, the screen appears to flicker. You might
want to temporarily turn off redrawing until all the components are rerendered.
Up for Discussion
1. Should you be allowed to store computer games on your computer at work? If so,
should you be allowed to play the games during working hours? If so, should there be any
restrictions on when you can play them?
Student opinions will vary. Some will feel that if the employee restricts game playing to
break times, there is no harm in having them installed. Others will decide that games are
an “attractive nuisance” and have the potential of keeping employees from their intended
jobs.
2. Suppose you discover a way to breach security in a Web site so that its visitors might
access information that belongs to the company for which you work. Should you be allowed to
publish your findings? Should you notify the organization? Should the organization pay you a
reward for discovering the breach? If they did, would this encourage you to search for more
potential security violations? Suppose the newly available information on the Web site is
relatively innocuous—for example, office telephone numbers of company executives. Next,
suppose that the information is more sensitive—for example, home telephone numbers for the
same executives. Does this make a difference?
Students will have to decide whether freedom of speech is more important than rights
of ownership. For some students, the nature of the information will not matter and they
cP
will feel it should be kept private. Most likely, these students will recommend notifying
the organization, whether or not payment is involved.
3. Suppose you have learned a lot about programming from your employer. Is it ethical
for you to use this knowledge to start your own home-based programming business on the
side? Does it matter whether you are in competition for the same clients as your employer?
Does it matter whether you use just your programming expertise or whether you also use
information about clients’ preferences and needs gathered from your regular job? Suppose you
know your employer is overcharging clients and you can offer the same services for less
money; does this alter your opinion?
Student opinions will vary. Many might allow a programmer to use gained knowledge to
start a side business but draw the line using proprietary information, even if the
employer is overcharging clients. Some students might suggest asking the employer for
permission—either to start the business, or to use specific skills and information.
Chapter 17
Tough Questions
cP
1. You can write to a file in an application, but not in a standard applet. Why?
Applets are designed for distribution over the Internet, and because applets that write to
a client’s file could destroy a client’s existing data, writing files is usually prohibited. It is
possible to create a signed applet, which is one that contains a digital signature, to prove
that it came from a trusted source and so has more privileges than an ordinary applet.
See http://java.sun.com for details.
2. You can use HTML to write Web pages, so why would you need applets?
HTML describes the content and layout of Web pages but it does not perform
programming tasks such as arithmetic calculations.
Up for Discussion
1. Why are applets not as popular in the programming community as applications? Applets
are used within a web page just like a browser plug-in, but writing them requires more
programmer training than writing in HTML. Java applets provide more interactivity and
flexibility than HTML, but starting a Java applet can be slow, and once an applet is
loaded, the performance is often poor. The look and feel of Java applets are limited to a
Windows-style standard (unless the programmer does a lot of
work to customize the applet). Java’s support of media other than bitmaps is weak, as is
its support of notification. There is comparatively little industry momentum behind
client-side Java, and sites consider the use of Java applets as part of their web offering
because of its reputation for poor reliability and performance in the IT community.
2. Making exciting and professional-looking applets becomes easier once you learn to include
graphics images. You can copy graphics images from many locations on the Web. Should there
be any restrictions on what graphics you use? Does it make a difference if you
cP
are writing programs for your own enjoyment as opposed to putting them on the Web where
others can see them? Is using photographs different from using drawings? Does it matter if the
photographs contain recognizable people? Would you impose any restrictions on images posted
to your organization’s Web site?
Student opinions will differ. Some will see the Web as a sharing community in which there
should be no restrictions. Others will say users should include only images that are freely
distributed by the creator. Students might approve of different guideline depending on
whether the applet is for personal use or for business use and depending on whether
people are recognizable. Students might object to using images that are disrespectful to
political or religious leaders.
3. Think of some practice or position to which you are opposed. For example, you might have
objections to organizations on the far right or left politically. Now suppose such an organization
offered you twice your annual salary to create Web sites for them. Would you do it? Is there a
price at which you would do it? What if the organization was not so extreme,
but featured products you found mildly distasteful? What if the Web site you designed was not
objectionable, but the parent company’s policies were objectionable? For example, if you are
opposed to smoking, is there a price at which you would design a Web site for a tobacco
company, even if the Web site simply displayed sports scores without promoting smoking
directly?
Of course student answers will vary. Many will say there is no price at which they would
support organizations that promote ideas that are objectionable to them.