CS450-SUMMER
2008
Homework Assignment # 2
Due – JUNE
29 2008, 11:59
P.M U.S.A. TIME
The
following directions apply to all assignments:
IMPORTANT:
FOLLOW THE FOLLOWING DIRECTIONS OR YOU RISK OF HAVING YOUR SUBMISSION NOT
GRADED!!!!!!!!
1. Submit homework/project
assignments to BLACKBOARD’s DIGITAL DROP BOX only . Include your source code files, WHEN
APPLICABLE, compiled code, WHEN APPLICABLE, executables, WHEN APPLICABLE,
README file WHEN APPLICABLE, WORD file with your text type answers etc as
required (see 3 below).
2. At the top of each source
code file (if code is involved) include the following comments: //Author: Your
name //
Student
ID: your school ID// Assignment # : ___ //
Problem#___//Date:
3. All assignments should
include a WORD file named with the same name you use for the zipped name (see
item 4). In the WORD
file include : YOUR NAME, YOUR STUDENT ID, YOUR
ASSIGNMENT
#, DATE SUBMITTED.
This WORD file also has the text answers to assignments or answers to project questions other than code (i.e. text exercises).
Include any
data if the assignment requires it. Any additional comments can be included in
the WORD file
(for example special instructions as to how to execute your
program IN CASE OF A PROGRAM).
4. Create a folder and include
all the assignment files in that folder. Name that folder the same name as the
zipped file described next. Zip all files and use the following convention to
name the zipped file: yourlastname_assignment#.zip
(for projects use yourlastname_project#.zip). Upload
the zipped file to the digital drop box of Blackboard.
NOTE: ASSIGNMENTS ARE BASED ON BOTH THE TEXT AND ANY HANDOUTS PRESENT ON THE COURSE”S WEB SITE OR LECTURES GIVEN IN CLASS.
You must use the official USA 7TH EDITION OF THE TEXT!!!
Do exercise 3.8
Date, this is a Date object that captures the current time.
Fortune, a String that represents the fortune.
Gender, a String that has values “male” or “female”
Age, an int that identifies age.
FortuneID a static int that advances every time there is a new Fortune request.
The class Fortune has a default an a non default constructor. The default constructor initializes all attributes to either empty String or zero or null.
The non default constructor accepts as arguments the gender and age and fortune values. It initializes those variables as well as the Date (captures the Date at that time) and advances the id of the fortune and captures it with another variable). There are the proper accessor and mutator methods in this class as well as a toString method (thus this class acts as a template for a Fortune object).
The client passes a message with the client’s gender and age to the server. Make the gender and age a user input (command line) which is read via the scanner object. Have the scanner object constantly looking for a user input so that the client does not terminate after the first input. When user enters the Strings TERMINATE 0 (zero entry) the client orders the server to terminate and then terminates itself also.
The server
receives the message from the client creates a Fortune object for that client.
Before a call to the Forune ‘s class constructor it searches a Fortunes array of
Strings according to gender and age
in order to find the correct fortune statement to be passed to the constructor.
Indices 0-4 are for those who are male
and age is < 30, indices 5-9 are for
males with ages > 30, indices 10-14
for females, age <30 and indices 15-19 for females, age> 30. Note: You can
repeat the same statement 20 times with a slight variation of one or two words.
It uses sequentially the entries in
the array (first client call uses the first entry for that gender and age, then
the next client call uses the next entry for that gender and age and so on).
The server sends the Fortune
object to the client (it sends the entire object not the values of the
attributes).
The client receives the Fortune object and uses the toString method of class Fortune to display to the user the attributes (including the id of the fortune and the time).
Server terminates when it receives message TERMINATE, 0 from client.
The server programs should be in folder namaed: SERVER and the client programs in folder named: CLIENT. Notice that the client needs a copy of class Fortune also.
Upload you program on Blackboard only (NOT on UNIX server). Use Java 1.6.
Include batch files for the TA to start your server and client programs.
Do exercise 3. 10
Do exercise 3.11.
Note: Modified version of exercise 4.9: The user enters two numbers command lin (i.e > java 11 13). The first argument after the command is executed using one thread (i.e. prime numbers up to 11) and the second argument after the command is executed on a separate thread (i.e. prime numbers up to 13)
1. Do the modified version of exercise 4.9. using Java (jdk 1.6).
1. Do the modified version of exercise 4.9 using Pthreads.
Do not do W32.
Modify the Pthreads program illustrated in figure 4.6 of your text (page 133) as follows:
A parent process is created that forks and uses exec to activate the program on page 133.
The parent process asks the user to enter two integer numbers (command line) which are passed to argv[1] and argv[2] of the main function of the child process via the exec system call.
The child process activates two separate threads that calculate the sum based on the first number and the product based on the second number.
i.e. if
3 and 5 are entered by the user the output is : “sum= 6 product=120”.
NOTE:
1. Submit all files for all
problems to Blackboard. Make sure you have a WORD file with the answers
2. Also, upload all C executable
programs on the UNIX server (but not the java programs for exercise 1 and exercise
4 part 1).
3. DO NOT USE ANY SPECIAL IDE FOR
JAVA PROGRAMS. USE A SIMPLE TEXT EDITOR
LIKE EDIT PLUS (OR SOMETHING SIMILAR) THAT DOES NOT USE ITS OWN JDK OR ADDS
CODE UNDER THE HOOD.