Java Reference
In-Depth Information
owner of a barbershop would be pleased to know that the shop's telephone number, 424-7288, cor-
responds to “HAIRCUT.” A veterinarian with the phone number 738-2273 would be pleased to
know that the number corresponds to the letters “PETCARE.” An automotive dealership would be
pleased to know that the dealership number, 639-2277, corresponds to “NEWCARS.”
Write a program that, given a seven-digit number, uses a PrintStream object to write to a file
every possible seven-letter word combination corresponding to that number. There are 2,187 (3 7 )
such combinations. Avoid phone numbers with the digits 0 and 1.
15.8 (Student Poll) Figure 7.8 contains an array of survey responses that's hard coded into the
program. Suppose we wish to process survey results that are stored in a file. This exercise requires
two separate programs. First, create an application that prompts the user for survey responses and
outputs each response to a file. Use a Formatter to create a file called numbers.txt . Each integer
should be written using method format . Then modify the program in Fig. 7.8 to read the survey
responses from numbers.txt . The responses should be read from the file by using a Scanner . Use
method nextInt to input one integer at a time from the file. The program should continue to read
responses until it reaches the end of the file. The results should be output to the text file "out-
put.txt" .
15.9 (Adding Object Serialization to the MyShape Drawing Application) Modify Exercise 12.17
to allow the user to save a drawing into a file or load a prior drawing from a file using object serial-
ization. Add buttons Load (to read objects from a file) and Save (to write objects to a file). Use an
ObjectOutputStream to write to the file and an ObjectInputStream to read from the file. Write the
array of MyShape objects using method writeObject (class ObjectOutputStream ), and read the array
using method readObject ( ObjectInputStream ). The object-serialization mechanism can read or
write entire arrays—it's not necessary to manipulate each element of the array of MyShape objects
individually. It's simply required that all the shapes be Serializable . For both the Load and Save
buttons, use a JFileChooser to allow the user to select the file in which the shapes will be stored or
from which they'll be read. When the user first runs the program, no shapes should be displayed on
the screen. The user can display shapes by opening a previously saved file or by drawing new shapes.
Once there are shapes on the screen, users can save them to a file using the Save button.
Making a Difference
15.10 (Phishing Scanner) Phishing is a form of identity theft in which, in an e-mail, a sender pos-
ing as a trustworthy source attempts to acquire private information, such as your user names, pass-
words, credit-card numbers and social security number. Phishing e-mails claiming to be from
popular banks, credit-card companies, auction sites, social networks and online payment services
may look quite legitimate. These fraudulent messages often provide links to spoofed (fake) websites
where you're asked to enter sensitive information.
Search online for phishing scams. Also check out the Anti-Phishing Working Group
( www.antiphishing.org ) , and the FBI's Cyber Investigations website ( www.fbi.gov/about-us/
investigate/cyber/cyber ), where you'll find information about the latest scams and how to pro-
tect yourself.
Create a list of 30 words, phrases and company names commonly found in phishing messages.
Assign a point value to each based on your estimate of its likeliness to be in a phishing message
(e.g., one point if it's somewhat likely, two points if moderately likely, or three points if highly
likely). Write an application that scans a file of text for these terms and phrases. For each occur-
rence of a keyword or phrase within the text file, add the assigned point value to the total points for
that word or phrase. For each keyword or phrase found, output one line with the word or phrase,
the number of occurrences and the point total. Then show the point total for the entire message.
Does your program assign a high point total to some actual phishing e-mails you've received? Does
it assign a high point total to some legitimate e-mails you've received?
 
Search WWH ::




Custom Search