23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

C-2.5<br />

Write a program that consists of three classes, A, B, <strong>and</strong> C, such that B extends<br />

A <strong>and</strong> C extends B. Each class should def<strong>in</strong>e an <strong>in</strong>stance variable named "x"<br />

(that is, each has its own variable named x). Describe a way for a method <strong>in</strong> C to<br />

access <strong>and</strong> set A's version of x to a given value, without chang<strong>in</strong>g B or C's<br />

version.<br />

C-2.6<br />

Write a set of <strong>Java</strong> classes that can simulate an Internet application, where one<br />

party, Alice, is periodically creat<strong>in</strong>g a set of packets that she wants to send to<br />

Bob. An Internet process is cont<strong>in</strong>ually check<strong>in</strong>g if Alice has any packets to<br />

send, <strong>and</strong> if so, it delivers them to Bob's computer, <strong>and</strong> Bob is periodically<br />

check<strong>in</strong>g if his computer has a packet from Alice, <strong>and</strong>, if so, he reads <strong>and</strong><br />

deletes it.<br />

Projects<br />

P-2.1<br />

Write a <strong>Java</strong> program that <strong>in</strong>puts a document <strong>and</strong> then outputs a bar-chart plot<br />

of the frequencies of each alphabet character that appears <strong>in</strong> that document.<br />

P-2.2<br />

Write a <strong>Java</strong> program that simulates a h<strong>and</strong>held calculator. Your program<br />

should be able process <strong>in</strong>put, either <strong>in</strong> a GUI or from the <strong>Java</strong> console, forthe<br />

buttons that are pushed, <strong>and</strong> then output the contents of the screen after each<br />

operation is performed. M<strong>in</strong>imally, your calculator should be able to process the<br />

basic arithmetic operations <strong>and</strong> a reset/clear operation.<br />

P-2.3<br />

Fill <strong>in</strong> code for the PersonPairDirectory class of Code Fragment 2.14,<br />

assum<strong>in</strong>g person pairs are stored <strong>in</strong> an array with capacity 1,000. The directory<br />

should keep track of how many person pairs are actually <strong>in</strong> it.<br />

P-2.4<br />

Write a <strong>Java</strong> program that can take a positive <strong>in</strong>teger greater than 2 as <strong>in</strong>put <strong>and</strong><br />

write out the number of times one must repeatedly divide this number by 2<br />

before gett<strong>in</strong>g a value less than 2.<br />

P-2.5<br />

135

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

Saved successfully!

Ooh no, something went wrong!