Problems


[Page 438]

12.1

Go to a page with a lot of text in it, like http://www.cnn.com and use your browser's menu to SAVE the file as something like mypage.html. Edit the file using an editor like Window's Notepad. Find some text in the page that you can see when you view the page, like a headline or article text. Change it! Instead of "protestors" rioting, make it "College students" or even "kindergarteners." Now OPEN that file in your browser. You've just rewritten the news!

12.2

Fill in the letter of the definition next to the appropriate phrase below. (Yes, you will have one unused definition.)

__ Domain Name Server __ Web Server  __ HTTP __ HTML __ Client __ IP Address __ FTP __ URL


  1. A computer that matches names like www.cnn.com to their addresses on the Internet.

  2. A protocol used to move files between computers, e.g., from your personal computer to a larger computer that acts as a Web server.

  3. A string that explains how (what protocol) and on what machine (domain name) and where on that machine (path) a particular file can be found on the Internet.

  4. A computer that offers files through HTTP.

  5. The protocol on which most of the Web is built, a very simple form aimed at rapid transmission of small bits of information.

  6. What a browser is (like Internet Explorer) when contacting a server like yahoo.com

  7. The tags that go into Web pages to identify parts of the page and how they should be formatted.

  8. A protocol that is used for transmitting e-mail between computers.

  9. The numeric identifier of a computer on the Internetfour numbers between 0 and 255, like 120.32.189.12

12.3

Write short essay responses to these questions.

  1. Give one example of a task for which you would not write a program, and give another example of a task for which you would write a program.

  2. What's the difference between an array, a matrix, and a tree? Give an example where we have used each to represent some data of interest to us.

  3. Why is a tree a better representation for files on a disk than an array? Why do you have many directories on your disk, and not just one gigantic one?

  4. What are some advantages that Vector-Based graphics have over Bitmap Graphical representations (like JPEG, BMP, GIF)?


[Page 439]
12.4

For each of the below, see if you can figure out the representation in terms of bits and bytes.

  1. Internet addresses are four numbers, each between 0 and 255. How many bits are in an Internet address?

  2. In the programming language Basic, lines can be numbered, each one between 0 and 65,535. How many bits are needed to represent a line number?

  3. Each pixel's color has three components: Red, green, and blue, each of which can be between 0 and 255. How many bits are needed to represent a pixel's color?

  4. A string in some languages can only be up to 1,024 characters. How many bits are needed to represent the length of a string?

12.5

Respond to the below Internet-related questions:

  1. What's a Domain Name Server? What does it do?

  2. What are FTP, SMTP, and HTTP? What are they each used for?

  3. What is HyperText?

  4. What's the difference between a client and a server?

  5. How does knowing how to manipulate text help you in gathering and creating information on the Internet?

  6. What is the Internet?

  7. What is an ISP? Can you give an example of one?

12.6

You've seen code to mirror pictures in Program 19 (page 135), and you've seen code to mirror sounds in Program 79 (page 306). It should be pretty easy to use the same algorithm to mirror text. Write a function to take a string, then return the mirrored string with the front mirrored to the back.

12.7

Write a method in the Picture class to convert a Picture object into a Sound object using the average of the color values. Map all values from 0 to 84 to the maximum negative sound value, map all values from 85 to 169 to 0 and all values above 170 to the maximum positive value.

12.8

Read a file of text and modify each character, such as change 'a' to 'b' and 'b' to 'c' and so on. Write a class, Encoder, that encodes the text and another class, Decoder, to decode the text.

12.9

Modify the Student class to implement the java.lang.Comparable interface. This means that you will need to provide the method compareTo(Object o) which should return 0 if the current student object is equal to the passed object, a negative number if the current student object is less than the passed object, and a positive number if the current student object is greater than the passed number. You can use the compareTo method of the String class to compare the student's names.

12.10

Write a program to read a list of words from a file and then output a new file with the letters scrambled using Random.


[Page 440]
12.11

Write a program to ask the user for a word to check the spelling of and then use a dictionary on the Internet to check the spelling. Tell the user whether the word is spelled correctly or not. You can use the class SimpleInput to get the word from the user and the class SimpleOutput to tell the user whether the word is spelled correctly or not. Both SimpleInput and SimpleOutput are classes that come with the book.

12.12

Modify the Student class to use an ArrayList instead of an array to hold the grades. Change the method getAverage to walk through the ArrayList.

12.13

Read the nouns, verbs, and phrases for the SentenceGenerator class from files. Use an ArrayList instead of an array for each of these.

12.14

Extend the form letter recipe to take an input of a pet's name and type, and reference the pet in the form letter. "Your pet "+petType+", "+petName+" will love our offer!" might generate "Your pet poodle, Fifi, will love our offer!".

12.15

Imagine that you have a list of all the genders (as single characters) of the students in your class, in order of their last name. The list will look something like "MFFMMMFFMFMMFFFM" where "M" is Male and "F" is Female. Write a function (below) percentageGenders(string) to accept a string that represents the genders. You are to count all of the "M"'s and "F"'s in the string, and print out the ratio (as a decimal) of the each gender. For example, if the input string were "MFFF," then the function should print something like "There are 0.25 Males, 0.75 Females." (Hint: Better multiply something by 1.0 to make sure that you get floats not integers.)

12.16

You worked late into the night on an assignment and didn't realize that you wrote a huge section of your term paper with your fingers on the wrong home keys!

Where you mean to type: "This is an unruly mob." You actually typed: "Ty8s 8s ah 7hr7o6 j9b."

Basically you swapped: 7 for U, 8 for I, 9 for O, 0 for P, U for J, I for K, O for L, H for N, and J for M. (Those were the only keystrokes that you got wrongyou caught yourself before you got much further.) You also never touched the shift key, so it's all lowercase letters that you care about.

Knowing Java as you do, you decide to write a quick program to fix your text. Write a method fixItUp that takes a string as input and returns a string with the characters put the way that they ought to have been.

12.17

The government has data for baby names from 1879 up to the previous year at http://www.ssa.gov/OACT/babynames/. Get the top 1,000 names for the year you were born and save it to a file. Write a method that will find the popularity of a passed name for that year for a given gender (some names are used for both boys and girls).

12.18

You can get historical weather data from http://www.ndbc.noaa.gov/Maps/northeast_hist.shtml. Use this site to get data for a location and write methods to find the hottest and coldest date for that location.


[Page 441]
12.19

In sleep research a patient is hooked up to electrodes and data is recorded for the eight hours or so that the patient sleeps. This results in a large file of numbers. One way that researchers work with this data is to map it to sounds and then listen for repetitions. Find a file of large numbers on the Internet and see if you can map it to sound sample values in such a way that you can hear repetition.

12.20

Write a simple Eliza program. You can use the class SimpleInput to ask questions and the class SimpleOutput to show responses. Both SimpleInput and SimpleOutput are classes that come with the book.

12.21

Write a class GraphicsInterpreter that reads in a file of graphics commands. The class GraphicsInterpreter should have a method interpret that takes a filename as input (a String), reads the graphics commands from the file, and then returns a Picture with the graphics commands executed on it. The method interpretCommands starts out by creating a 640x480 blank picture, then draws on that, and returns it.

There are two kinds of commands:

  • "line 10 20 300 400" should draw a line from (10,20) to (300,400). You can assume that those are single spaces between the coordinates.

  • "circle 100 200 10" draws a circle whose upper-left hand corner is (100,200) with a diameter for 10.

An input graphics command might look like:

circle 20 20 100 circle 300 20 100 line 210 120 210 320 line 210 320 310 320 line 20 350 400 350


The main method for GraphicsInterpreter might look like this:

public static void main(String[] args) {   GraphicsInterpreter interpreter =      new GraphicsInterpreter();   String fileName =     FileChooser.getMediaPath("graphics-commands.txt");   Picture p = interpreter.interpretCommands(fileName);   p.show(); }




Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net