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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Modify the CreditCard class from Code Fragment 1.5 to charge <strong>in</strong>terest on<br />

each payment.<br />

R-1.3<br />

Modify the CreditCard class from Code Fragment 1.5 to charge a late fee<br />

for any payment that is past its due date.<br />

R-1.4<br />

Modify the CreditCard class from Code Fragment 1.5 to <strong>in</strong>clude modifier<br />

methods, which allow a user to modify <strong>in</strong>ternal variables <strong>in</strong> a CreditCard<br />

class <strong>in</strong> a controlled manner.<br />

R-1.5<br />

Modify the declaration of the first for loop <strong>in</strong> the Test class <strong>in</strong> Code<br />

Fragment 1.6 so that its charges will eventually cause exactly one of the three<br />

credit cards to go over its credit limit. Which credit card is it?<br />

R-1.6<br />

Write a short <strong>Java</strong> function, <strong>in</strong>putAllBaseTypes, that <strong>in</strong>puts a different<br />

value of each base type from the st<strong>and</strong>ard <strong>in</strong>put device <strong>and</strong> pr<strong>in</strong>ts it back to the<br />

st<strong>and</strong>ard output device.<br />

R-1.7<br />

Write a <strong>Java</strong> class, Flower, that has three <strong>in</strong>stance variables of type Str<strong>in</strong>g,<br />

<strong>in</strong>t, <strong>and</strong> float, which respectively represent the name of the flower, its<br />

number of pedals, <strong>and</strong> price. Your class must <strong>in</strong>clude a constructor method that<br />

<strong>in</strong>itializes each variable to an appropriate value, <strong>and</strong> your class should <strong>in</strong>clude<br />

methods for sett<strong>in</strong>g the value of each type, <strong>and</strong> gett<strong>in</strong>g the value of each type.<br />

R-1.8<br />

Write a short <strong>Java</strong> function, isMultiple, that takes two long values, n <strong>and</strong><br />

m, <strong>and</strong> returns true if <strong>and</strong> only if n is a multiple of m, that is, n = mi for some<br />

<strong>in</strong>teger i.<br />

R-1.9<br />

Write a short <strong>Java</strong> function, isOdd, that takes an <strong>in</strong>t i <strong>and</strong> returns true if <strong>and</strong><br />

only if i is odd. Your function cannot use the multiplication, modulus, or<br />

division operators, however.<br />

R-1.10<br />

85

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

Saved successfully!

Ooh no, something went wrong!