Java Reference
In-Depth Information
Programming Assignments (continued)
To simulate this action, write a method to wrap a given number of
occurrences of a character at the beginning and the end of a string. For example,
wrap(message, 4, '!')
should add 4 exclamation marks to the beginning and the end of the string,
message. The program should continue to wrap as long as the user enters a wrap
character. So, a subsequent call to wrap(message, 2, '?') should result in the mes-
sage being wrapped by ??!!!! at the beginning and !!!!?? at the end. When the user
no longer enters a wrap character, the program should prompt for another string
and continue as long as the user enters a string to wrap. Figure 9-51 displays
sample output.
ENTER key pressed
with no wrap
character entered
new string
entered
FIGURE 9-51
J ava 2
v 5 . 0
J ava 2
5 Simulating User Logon Tracking with an ArrayList
v 5 . 0
Computer systems typically track the number of users logged on to the system at
any point in time. Some systems do not allow more than one simultaneous
logon by a given user.
Write an application to simulate user logon tracking as shown in Figure 9-52.
The application should keep a list of users logged on to the system. A user name
always must be entered in the User text box to log on or log off. The program also
should ensure that only users not already logged on to the system can log on, and
only those already logged on can log off. Keep track of the number of users
logged on at any point in time, and display this number in a text box that the user
cannot modify. Display appropriate messages when a user successfully logs on or
off and appropriate error messages when an action fails. For Java 5.0, use a
typesafe ArrayList and any other features, such as static imports, as appropriate.
 
Search WWH ::




Custom Search