Download Question One 4 points

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
ARAB OPEN UNIVERSITY
Faculty of Computer Studies
M301A, Software Systems and their
Development
TMA
Cut-off date 30 July 2011
Note: This TMA comprises of three questions. All questions should
be answered.
Plagiarism Warning
As per AOU rules and regulations, all students are required to
submit their own TMA work and avoid plagiarism. The AOU has
implemented sophisticated techniques for plagiarism detection. You
must provide all references in case you use and quote another
person's work in your TMA. You will be penalized for any act of
plagiarism as per the AOU's rules and regulations.
Declaration of No Plagiarism by Student (to be signed and
submitted by student with TMA work):
I hereby declare that this submitted TMA work is a result of my
own efforts and I have not plagiarized any other person's work. I
have provided all references of information that I have used and
quoted in my TMA work.
ID and Name of Student
Signature
Date
………………………………………………………………………………
……………………………………………………………
………………………………………
Question One
4 points
What is the output of the following code?
public static void main(String [] args){
String name = "Happy";
String shortName = name.substring(1);
System.out.println(name + "," + name + ",bo-B" + shortName);
System.out.println("Banana-Fana Fo-F" + shortName);
System.out.println("Fee, Fie, mo-M" + shortName);
System.out.println(name + "!");
}
Question two
26 points
Here is a class that describes a disk object, some parts of this
class are omitted. Read it carefully and then answer the questions
below.
// missing import statement
public class Disk {
private Point location;
private int radius;
private Color col;
public Disk(/*missing formal parameters*/) {
location = p;
radius = r;
col = c;
}
public /*type missing#1*/ getLocation() {
return location;
}
public /*type missing#2*/ setLocation(Point p5) {
location = /*variable missing#1*/;
}
public void paint (Graphics toto) {
/*variable missing#2*/.setColor(col);
/*variable missing#3*/.fillOval(location.x – radius, location.y –
radius, 2*radius, 2*radius);
}
}
1. Fill in the table below with the appropriate java code of the missing
parts of the Disk class shown above. [9 points]
Missing parts clues
1
// missing import statement
2
/*missing formal parameters*/
The java code of the missing parts
2
3
/*type missing#1*/
4
/*type missing#2*/
5
/*variable missing#1*/
6
/*variable missing#2*/
7
/*variable missing#3*/
2. Write a java statement to create a Disk object such that:
a. It is referenced by the variable d3
b. Its center is located at the coordinates (50, 70);
c. Its color is blue
d. Its radius length = 30
[3 points]
3. Which class the fillOval method belongs to? [1 point]
4. Write a Disk method to change the color of the Disk object, name this
method as setColor. [3 points]
5. Now there are two setColor methods, one in the paint body and the
other that you have written as the answer of the previous question,
what the best term (word) is used to describe the two setColor
methods. [1 point]
6. From point of view why the value of radius is deducted from location.x
and from location.y in fillOval(location.x – radius, location.y –
radius, 2*radius, 2*radius); [1 point]
7. From point of view why the value of radius is multiplied by 2 in
fillOval(location.x – radius, location.y – radius, 2*radius,
2*radius); [1 point]
8. From point of view why the value of 3rd and 4th parameters are equals
in fillOval(location.x – radius, location.y – radius, 2*radius,
2*radius); [1 point]
9. Write an application class to draw a class inside a window that
satisfy the requirements shown in the table below
1
2
3
4
5
6
requirements
Frame height
600
Frame width
500
Frame title
My Disk
Disk location
(200, 300)
Disk radius
50
Disk color
Red
[6 points]
3
Question three
30 points
Assume that there are a set of concurrent processes; P1, P2, P3, P4 and
P5 need to work (interact) together to achieve the goal of a system.
a. Why P1, P2, P3, P4 and P5 might need to interact? [2 points]
b. How P1, P2, P3, P4 and P5 interactions might be supported in a
system. [2 points]
c. Assume that P1, P2 and P3 need to hold a shared data structure. A
semaphore is used to manage their interaction.
1. Write a java statement to create a semaphore object, referenced
by ‘sem1’. [1 point]
2. Write a pseudo java code to show where the invocation
semaphore’s methods will be placed in P1’s code, P2’s code or
P3’s code. [5 points]
3. Illustrate by drawing how P1, P2 and P3 will work together for
holding the shared data structure. Assume P3 will hold the
shared data structure first, then P1 and finally P2. [5 points]
d. Assume that P4 need to make a request for a service of P5, P4 has
to wait for this service to be done. A semaphore is used to manage
their interaction.
1. Write a java statement to create a semaphore object, referenced
by ‘sem2’. [1 point]
2. Write a pseudo java code to show where the invocation
semaphore’s methods will be placed in P4’s code and P5’s code.
[8 points]
3. Illustrate by drawing how P4 and P5 will work together for
holding the shared data structure. [6 points]
The End
4