26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Chapter 16 Files and Streams 907<br />

4<br />

5 // <strong>Java</strong> core packages<br />

6 import java.io.Serializable;<br />

7<br />

8 public class AccountRecord implements Serializable {<br />

9 private int account;<br />

10 private String firstName;<br />

11 private String lastName;<br />

12 private double balance;<br />

13<br />

14 // no-argument construc<strong>to</strong>r calls other construc<strong>to</strong>r with<br />

15 // default values<br />

16 public AccountRecord()<br />

17 {<br />

18 this( 0, "", "", 0.0 );<br />

19 }<br />

20<br />

21 // initialize a record<br />

22 public AccountRecord( int acct, String first,<br />

23 String last, double bal )<br />

24 {<br />

25 setAccount( acct );<br />

26 setFirstName( first );<br />

27 setLastName( last );<br />

28 setBalance( bal );<br />

29 }<br />

30<br />

31 // set account number<br />

32 public void setAccount( int acct )<br />

33 {<br />

34 account = acct;<br />

35 }<br />

36<br />

37 // get account number<br />

38 public int getAccount()<br />

39 {<br />

40 return account;<br />

41 }<br />

42<br />

43 // set first name<br />

44 public void setFirstName( String first )<br />

45 {<br />

46 firstName = first;<br />

47 }<br />

48<br />

49 // get first name<br />

50 public String getFirstName()<br />

51 {<br />

52 return firstName;<br />

53 }<br />

54<br />

Fig. Fig. 16.5 16.5 Class AccountRecord maintains information for one account (part 2 of 3).

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

Saved successfully!

Ooh no, something went wrong!