Thursday, November 29, 2012

tigger query

trigger for when user delete his account (when he do that every photo and albums, and comments must be deleted)

Tuesday, November 13, 2012

ques

I don't know it says it at the end of the explanation of the ERD

Sunday, May 24, 2009

Registraation form




JSP Page



Online Book Shop




My Account Information














Usre ID
Password
Gender
Name
Address
Zip Code
E-mail
Telephone Number








Thursday, May 14, 2009

Dog

  1. Create a new class called Dog that is derived from the Pet class given in Listing 6.1 of Chapter 6 on pages 347 - 349. The new class has the additional attributes of breed (type String) and boosterShot (type boolean), which is true if the pet has had its booster shot, and false if not. Be sure your classes have a reasonable complement of constructors and accessor methods.

You will need all three Java programs for execution: Pet.java, Dog.java, DogDemo.java. .

1. Add two instance variables: String breed and boolean boosterShot; (10)

2. Your derived class name is Dog, therefore your file name is Dog.java.

3. You need to define three constructors: (30)

· Without any parameters, codes given below:

public Dog()

{

super();

breed = "None";

boosterShot = false; // Default: presume no shot

· With five parameters name, age, weight, breed, and boosterShot;

· With four parameters name, age, weight, and breed.

4. Give a new definition of writeOutput() (30)

· This is an overridden method.

· The original output from the base class (don’t forget the super keyword).

· Output breed

· Output the dog has (or has not) had a booster shot.

5. Write three mutator methods: (30)

· To reset name, age, weight, breed, and boosterShot status. The instance variables in the base class can be accessed through base class’s set method. Again don’t forget the super keyword here.

· To reset the breed only.

· To reset boosterShot value.

6. Write two accessor methods: (20)

· To get breed info.

· To get info on boosterShot status.

7. You need to document both programs follow my previous suggestions. (10)

· Your code should be written in a way that is easy to read.

· Add comments on what software/IDE you used in developing your program.

· Add compilation instructions. E.g., javac Dog.java. and javac DogDemo.java

· Add executing instructions. E.g., java DogDemo

· Programmer’s name.

· Preconditions and postconditions.

  1. Write a test (demo or driver) program (file name: DogDemo.java) that reads in five pets of type Dog from the keyboard and at the end of the input the program prints out the name and breed of all dogs that are over two years old and have not had their booster shots. Note that your writeOutput() methods in the Pet class and Dog class determine the output format.

· You will use an array to hold all dogs info (check your StudentRecord class).

· Declare the array size to be 5.

· Use a looping method to enter info for 5 dogs.

· Be sure to check your index during your input loop so you don’t get an array index out of bound exception during run time.

· After each loop, echo all info to the screen as shown here:

Enter first dog’s name:

Freddie

Enter dog’s age in years:

5

Enter dog’s weight in pounds:

10.5

Enter breed:

Dachshund

Has the dog had a booster shot within 2 years?

Enter y (or Y) for yes and anything else for no.

N

You have entered the following dog info:

Name: Freddie

Age: 5 years

Weight: 10.5 pounds

Bread: Dachshund

Has NOT had a booster shot.

Enter second dog’s name:

………and so forth……

· At the end of the program, print all the dogs’ information to the screen in ascending order by their ages.

· Sample screen output listed below.

Name Age Weight Breed Boostershot

. Freddie 2 10.5 Dachshund false

yy 8 20.0 B2 true

zz 10 15.0 B4 true

aa 12 10.0 B5 true

dd 16 30.0 B2 true

· A sorting method that sorts an array of type Dog for your reference:

public static void insertionSort(int numberDogs, Dog a[] )

{

int in, out;

Dog temp = null;

for(out=1; out // out is dividing line

{

temp = a[out]; // remove marked person

in = out; //index of the end of sorted region

while(in>0 && a[in-1].getAge() > temp.getAge() ) { // until smaller one found

a[in] = a[in-1]; // shift item to the right

--in; // go left one position

}

a[in] = temp; // insert marked item

} // end for

} // end insertionSort()

Note: the numberDogs is the number of element of the Dog array have actually filled with data. The Dog array a[] can be a size of 5 if you initially created 5 elements with the following Java statement:

Dog a[] = new Dog[5];

The length of the a[] array is 5, and all 5 elements at this point are all null. If you try to sort this array, you will get a null pointer exception! You have to use the keyword ‘new’ to instantiate each element of the Dog array. For example the 1st element of the a[] array:

a[i] = new Dog(…);







/**
Class for basic pet data: name, age, and weight.
*/
public class Pet
{
private String name;
private int age; //in years
private double weight;//in pounds

public Pet(String initialName, int initialAge,
double initialWeight)
{
name = initialName;
if ((initialAge < 0) || (initialWeight < 0))
{
System.out.println("Error: Negative age or weight.");
System.exit(0);
}
else
{
age = initialAge;
weight = initialWeight;
}
}

public void setPet(String newName, int newAge, double newWeight)
{
name = newName;
if ((newAge < 0) || (newWeight < 0))
{
System.out.println("Error: Negative age or weight.");
System.exit(0);
}
else
{
age = newAge;
weight = newWeight;
}
}

public Pet(String initialName)
{
name = initialName;
age = 0;
weight = 0;
}

public void setName(String newName)
{
name = newName; //age and weight are unchanged.
}

public Pet(int initialAge)
{
name = "No name yet.";
weight = 0;
if (initialAge < 0)
{
System.out.println("Error: Negative age.");
System.exit(0);
}
else
age = initialAge;
}

public void setAge(int newAge)
{
if (newAge < 0)
{
System.out.println("Error: Negative age.");
System.exit(0);
}
else
age = newAge;
//name and weight are unchanged.
}

public Pet(double initialWeight)
{
name = "No name yet";
age = 0;
if (initialWeight < 0)
{
System.out.println("Error: Negative weight.");
System.exit(0);
}
else
weight = initialWeight;
}

public void setWeight(double newWeight)
{
if (newWeight < 0)
{
System.out.println("Error: Negative weight.");
System.exit(0);
}
else
weight = newWeight; //name and age are unchanged.
}

public Pet( )
{
name = "No name yet.";
age = 0;
weight = 0;
}

public String getName( )
{
return name;
}

public int getAge( )
{
return age;
}

public double getWeight( )
{
return weight;
}

public void writeOutput( )
{
System.out.println("Name: " + name);
System.out.println("Age: " + age + " years");
System.out.println("Weight: " + weight + " pounds");
}
}

Monday, May 4, 2009

Algorithm-1

01234 567


Sample Exam 2

EE 322C - University of Texas at Austin - Spring ,2009

Name ____________________________________

Test taking instructions. No calculators, laptops or other assisting devices are allowed. Write your
answers on these sheets. If you need scratch paper then use the backside of the last page. Wherever
code is required, write JAVA statements in the blank areas provided, or by modifying the given code
in place. You are not required to follow the coding style guidelines when writing code on the exam, but
be as neat as possible. If you are unsure of the meaning of a specific test question, then write down
your assumptions and proceed to answer the question on that basis. If you see a typo or syntax error,
fix it, circle it, and if you are right you will get a bonus point for each one fixed. In your programming
solutions on this test you may use any of the classes/methods that you know from the library, or
collections.

Questions about the exam questions will not be answered during the test.

For the binary tree related questions on this exam you may assume that this generic class has been
defined for your use and is included. When the term Btnode is used on the exam it is referring to
this generic class.

class Btnode


{ /* this generic class models a node of a binary tree */


/* here are the private data members of the binary tree node */


private T element;


private Btnode left;


private Btnode right;


/* the constructor given an Object,left child,and right child. */


Btnode(T theElement, Btnode lt, Btnode rt )


{ element = theElement;


left = lt;


right = rt;


}


/* here are the public get/set methods for the data members */


public T getElement( ){ return element;}


public Btnode getLeft( ) {return left;}


public Btnode getRight( ){return right;}


public void setElement( T x ){element = x;}


public void setLeft( Btnode t ) {left = t;}


public void setRight( Btnode t ){right = t;}


}



Page 2

Question 0 -Terminology. [19 pts.] Answer each of the following questions; choose
the best answer from the numbered list below.

A. ___ a sorting technique using a series of queues as intermediate structures
B. _____The level of the lowest leaf of a tree is the same as the tree’s what?
C.
____A binary operation which takes two given sets and yields a set made up of all the items in the first
set that are not in the second set
D. ____A collection of key-value pairs that associate a key with a value.
E. ____A hierarchical structure that place elements in nodes along branches that originate from a root.
F.
____A tree structure in which each node can have at most two children, and in which a unique path
exists from the root to every other node.
G.
____A type of tree in which the key value of each node is less than every key value in its right subtree,
and greater than every key value in its left subtree.
H. ____ A type of binary tree in which the height of each node’s subtrees differs by no more than one.
I.
____A binary tree in which all of the leaves are on the same level and every nonleaf node has exactly
two children
J.
____A binary tree that is either full or full through the next-to-last level, with the leaves on the last level
as far to the left as possible
K.
____A complete binary tree in which each node has a value stored in it that is greater than or equal to
the value in each of its children.
L. ____Nodes in a binary tree that have only NULL children
M. ____A node in a binary tree that does not have a parent
N. ____A data structure that consists of a set of nodes and a set of edges that relate the nodes to each other
O. ____A graph in which each edge is directed from one vertex to another (or the same) vertex
P. ____A graph in which every vertex is directly connected to every other vertex
Q. ____A graph in which each edge carries a value
R.
____A sequential structure that is divided into table elements. The address of an identifier X in the
structure is gotten by computing some arithmetic function
S. ____This occurs when 2 different identifiers are hashed into the same location
T. ____ A method for finding the shortest path from one vertex to another in a weighted digraph
1) 2-3-4 tree 14) device miniaturization27) Prim’s algorithm2) array 15) forking28) queue3) AVL tree 16) functional29) Radix4) binary tree 17) full30) root
5) binary search tree 18) graph31) set
6) black box testing 19) hash table32) set difference
7) breadth first search 20) heap33) set intersection
8) collision 21) infix34) stack
9) complete22) leaf35) synchronization
10) depth23) map 36) ttree
11) depth first search24) matrix 37) weighted graph12) Dijkstra’s algorithm25) overflow 38) White box
13) digraph 26) partially filled array


Page 3
Question 1 -Multiple Choice. [2 pts. each -18 pts total] For each of the following
subparts, circle the best or all correct answers as indicated.

A. The linear probe method for hash tables suffers from the phenomenon known as
i. fatal collisions
ii. sparse distribution
iii. clustering
iv. broken chains
v. none of the above
B. Which of the following sorting algorithms have a worst case performance that is better than O(n*n)?
i) selection
ii) bubble
iii) insertion
iv) shell
v) merge
vi) heapsort
vii)quicksort


C. Which tree below corresponds to the vector v created by the code below?
int arr[ 8 ] = {3, 15, 12, 4, 67, 6, 55, 9};
Vector v = new Vector (8);
for (int i=0; i< 8; i++) { v.addElement(arr[i]); }


341215667955124153667955(i)(ii)
(iii)
(iv)
341512667955367151264955

Page 4

D. Which of the following are true of sets?
i. A set with no elements in it is called an empty set
ii. Each element (ie, value) in a set is distinct
iii. The universal set is that which contains all the values of the base type
iv. The cardinality of a set denotes the number of elements in a set
v. New sets can be created by the union, intersection and difference operations
vi. The elements of a set are not ordered
E. Which of the following are true of heaps ?
i. It is a binary tree
ii. In terms of its shape, it must be complete
iii. It can be either a maximal or a minimal heap
iv. The value of the root has no relationship to the value of any other nodes
v. Is useful for implementing a stack
vi. Is the most efficient representation for a priority queue
F. Hashing is an ______ search algorithm.
(i) O(log2n) (ii) O(n2) (iii) O(n) (iv) O(1)
G. What is the value of the postfix expression 6 3 4 5 + * +
i) 10
ii) 0
iii) 25
iv) 33
v) none of the above


H. Given three arrays with L, M and N elements respectively,
estimate the running time for the
following algorithm in terms of the number of times that the pairwise comparison step is executed:
repeat the following for i from 1 to L for array1
repeat the following for j from 1 to M for array2
repeat the following for k from 1 to N for array3


pairwise compare array1[i], array2 [j] and array3 [k] and based on the result do one the following
case 1: if array1[i] and array2 [j] are equal then { do something 1}
case 2: if array1[i] and array3 [k] are equal then { do something 2}
case 3: if array3[k] and array2 [j] are equal then { do something 3}

end repeat
end repeat
end repeat


i. O ( log 2 (L+M+N) )
ii. O ( N 3 )
iii. O ( L * M * N )
iv. None of the above

Page 5

I. If the characters ‘A’, ‘D’, ‘C’, ‘B’ are put into a queue (in that order), and then retrieved one by one,
what will be the order in which they are removed?
i) ABCD
ii) DCBA
iii) BCDA
iv) ADCB


Question 2. Evaluation. (2 points each = 6 pts. total) For each of the following code segments,
write in the value of the variable x after the Java statements are executed. You may assume that the
proper import statements have already appeared.

A.
______________ Vector alist = new Vector ( );
alist.add (40);
alist.add (10);
alist.add (20);
alist.add (8);
int x = alist.get(0 ) * alist.get( 3) ;
B.
______________ Stack intStack = new Stack ( );
intStack.push (6);
intStack.push (5);
intStack.push (11 + intStack.peek ( ));
int y = intStack.peek ( ) ;
intStack.pop ( ) ;
int x = y + intStack.peek ( ) ;
C.
______________ int array [ ] = {0,1,2,3,4,5,6,7,8,9};
Queue s = new LinkedList ( );
for (int i = 0; i < 10; i++) s.add (array [ i ]);
s.remove ( );
int x = s.peek ( ) + array [7];
// hint: from the ADT for queue: add is enqueue, remove is dequeue, peek is front


Page 6

3. Tree questions (20 pts)
A.(7 pts) For each subpart (a) – (g), use the following tree.

691215721231453201118
(a) What is the parent of node 5? ___________________
(b) What is the depth of this tree? ____________________
(c) List the nodes in subtree 12. ___________________________
(d) List all of the non leaf nodes. ______________________________
(e) Give the order that the nodes are visited in a preorder traversal of the tree.
(f) Give the order that the nodes are visited in an inorder traversal of the tree.
(g) List all of the nodes at level 2 in the tree. _______________________________
B. (2 pts) Draw the tree created by the following statements. Btnode is defined on page 1.
Btnode root, a, b, c, d;
d = new Btnode (6, NULL, NULL);
c = new Btnode (9, d, NULL);
b = new Btnode (4, NULL, c);
a = new Btnode (12, NULL, NULL);
root = new Btnode (10, a, b);


C. (3 pts) Trace the method count() below and describe what it does
public static int count (Btnode t)


{ int ctLeft, ctRight, ct;


if (t == NULL)


ct = 0;


else


{ ctLeft = count(t.getLeft());


ctRight= count(t.getRight());


boolean flag = (t.getLeft()!= NULL && t.getRight()!= NULL);


ct = ctLeft + ctRight + (int)flag;


}


return ct;


}



Page 7

D. (3 pts) Use the following tree traversal function.
Assuming m is initially 0, what is the resultant value of m when
calling this method as f ( Btnode root, m) where root is the base of the tree in Question 3A?
public static void f(Btnode t, int n)
{ if (t != NULL)


{
n++;
f(t.getLeft(), n);
f(t.getRight(), n);


}
return;


}


E. (5 pts) Consider the following binary search tree.
Use the original tree below when answering each subpart (a)
through (e).
506875654515907035208025301852395100150
(a)
If the value 46 is inserted into this tree, which node becomes its parent? __________________
(b) If the value 64 is inserted into this tree, which node becomes its parent? ___________________
(c)
If we delete node 65, which node should be its replacement node? ___________________
(d) If we delete node 90, which node should be its replacement node? __________________
(e)
If we delete the root node 50, which node should be selected as its replacement node so that the fewest number
of changes are made to the tree? ______________________

Page 8

4. Heaps and Graphs (19 pts)
A. (3 pts) A heap can be represented by a vector. Start with the following heap and list the elements after each operation.
Execute the operations sequentially, using the result of the previous operation. The initial vector values for the heap
are {50, 35, 15, 12, 3, 5}.
5012153553
(a) Insert 23: The vector values are now {____________________________}.
(b) Erase an element from the heap:The vector values are now {__________________}.
B. (3 pts) Start with following tree and "heapify" it to create a maximum heap. Draw the resulting tree.
259813292218553533
C. (3 pts) Start with following tree and create a minimum heap. Draw the resulting tree.
75205540304590151035
D. (3 pts) Show the minimum cost path from node B to node E in the following digraph G.

Page 9

ADCBE12532117

Page 10

E..(3 pts) Draw the adjacency list representation for the following digraph G.

ADCBE12532117
F (4 pts) Draw the minimal spanning tree for the following graph G.

B
A
H
E
G
F
D
C
50 25
46
25
23
55
32
98
35
67

Page 11

5. Hash Tables (6 pts) The following hash table is used to store integer values. Assume that we
use the following hashing function to store values in the table.
h(x) = x % tableSize (tableSize is equal to the size of the hash table below -which is 20)

Show the resultant hash table after inserting the values: 52, 12, 11, 2, 7, 10, 21, 121, 23, 33, 71, 90 in
that order. Use the linear probing technique for collision resolution. That is, if the initial hash location
yields a collision then probe forward until an empty slot can be found. The table is used in a circular
manner for that purpose.

Index Value
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19


Page 12

6. Maps (6 points)
Complete the program below whose purpose is to count and record the number of occurrences of each
character found in a given text file (“in.txt”). You are to use the hash map m to store the number of
occurrences of each character. You can use the default hashcode method for Character. After all
characters in the file are processed, output a table to the screen that contains 2 columns with each
character in column 1 and its total number of occurrences in column 2. Note: all legal characters are to
be counted.

import java.io.*;
public class CountingChars
{ public static void main(String[ ] args) throws IOException

{
Map m = new HashMap ( );
FileReader infile = new FileReader("in.txt");
BufferedReader in = new BufferedReader(infile);


// process all the characters in the file, one at a time
char c = (char) in.read( ); // read the first char from the file
while ( )
{


c = (char) in.read(); // read the next char in the file
}
// output the table of (char, count) pairs

}



Page 13

}

7. Design [6 points] Consider the dictionary of 5-lettered words that you used in Assignment 5, and
suppose that you were given the list of words but they were not in order. To put them into alphabetical
order, describe the sorting method that you would use to put them into order in the fastest way possible.
You may assume that there is plenty of space available for your chosen method. Describe your
method’s worst case Big O performance and approximately how much space is required.

Algorithm

Questions about the exam questions will not be answered during the test.
For the binary tree related questions on this exam you may assume that this generic class has been
defined for your use and is included. When the term Btnode is used on the exam it is referring to
this generic class.
class Btnode
{ /* this generic class models a node of a binary tree */
/* here are the private data members of the binary tree node */
private T element;
private Btnode left;
private Btnode right;
/* the constructor given an Object,left child,and right child. */
Btnode(T theElement, Btnode lt, Btnode rt )
{ element = theElement;
left = lt;
right = rt;
}
/* here are the public get/set methods for the data members */
public T getElement( ){ return element;}
public Btnode getLeft( ) {return left;}
public Btnode getRight( ){return right;}
public void setElement( T x ){element = x;}
public void setLeft( Btnode t ) {left = t;}
public void setRight( Btnode t ){right = t;}
}



Question 1 - Multiple Choice. [2 pts. each - 18 pts total] For each of the following
subparts, circle the best or all correct answers as indicated.
A. The linear probe method for hash tables suffers from the phenomenon known as
i. fatal collisions
ii. sparse distribution
iii. clustering
iv. broken chains
v. none of the above
B. Which of the following sorting algorithms have a worst case performance that is better than O(n*n)?
i) selection
ii) bubble
iii) insertion
iv) shell
v) merge
vi) heapsort
vii) quicksort
C. Which tree below corresponds to the vector v created by the code below?
int arr[ 8 ] = {3, 15, 12, 4, 67, 6, 55, 9};
Vector v = new Vector (8);
for (int i=0; i< 8; i++) { v.addElement(arr[i]); }





D. Which of the following are true of sets?
i. A set with no elements in it is called an empty set
ii. Each element (ie, value) in a set is distinct
iii. The universal set is that which contains all the values of the base type
iv. The cardinality of a set denotes the number of elements in a set
v. New sets can be created by the union, intersection and difference operations
vi. The elements of a set are not ordered
E. Which of the following are true of heaps ?
i. It is a binary tree
ii. In terms of its shape, it must be complete
iii. It can be either a maximal or a minimal heap
iv. The value of the root has no relationship to the value of any other nodes
v. Is useful for implementing a stack
vi. Is the most efficient representation for a priority queue
F. Hashing is an ______ search algorithm.
(i) O(log2n) (ii) O(n2) (iii) O(n) (iv) O(1)
G. What is the value of the postfix expression 6 3 4 5 + * +
i) 10
ii) 0
iii) 25
iv) 33
v) none of the above
H. Given three arrays with L, M and N elements respectively, estimate the running time for the
following algorithm in terms of the number of times that the pairwise comparison step is executed:
repeat the following for i from 1 to L for array1
repeat the following for j from 1 to M for array2
repeat the following for k from 1 to N for array3
pairwise compare array1[i], array2 [j] and array3 [k] and based on the result do one the following
case 1: if array1[i] and array2 [j] are equal then { do something 1}
case 2: if array1[i] and array3 [k] are equal then { do something 2}
case 3: if array3[k] and array2 [j] are equal then { do something 3}
end repeat
end repeat
end repeat
i. O ( log 2 (L+M+N) )
ii. O ( N 3 )
iii. O ( L * M * N )
iv. None of the above


I. If the characters ‘A’, ‘D’, ‘C’, ‘B’ are put into a queue (in that order), and then retrieved one by one,
what will be the order in which they are removed?
i) ABCD
ii) DCBA
iii) BCDA
iv) ADCB
Question 2. Evaluation. (2 points each = 6 pts. total) For each of the following code segments,
write in the value of the variable x after the Java statements are executed. You may assume that the
proper import statements have already appeared.
A. ______________ Vector alist = new Vector ( );
alist.add (40);
alist.add (10);
alist.add (20);
alist.add (8);
int x = alist.get(0 ) * alist.get( 3) ;
B. ______________ Stack intStack = new Stack ( );
intStack.push (6);
intStack.push (5);
intStack.push (11 + intStack.peek ( ));
int y = intStack.peek ( ) ;
intStack.pop ( ) ;
int x = y + intStack.peek ( ) ;
C. ______________ int array [ ] = {0,1,2,3,4,5,6,7,8,9};
Queue s = new LinkedList ( );
for (int i = 0; i < 10; i++) s.add (array [ i ]);
s.remove ( );
int x = s.peek ( ) + array [7];
// hint: from the ADT for queue: add is enqueue, remove is dequeue, peek is front


3. Tree questions (20 pts)
A.(7 pts) For each subpart (a) – (g), use the following tree.



(a) What is the parent of node 5? ___________________
(b) What is the depth of this tree? ____________________
(c) List the nodes in subtree 12. ___________________________
(d) List all of the non leaf nodes. ______________________________
(e) Give the order that the nodes are visited in a preorder traversal of the tree.
____________________________________________________________
(f) Give the order that the nodes are visited in an inorder traversal of the tree.
____________________________________________________________
(g) List all of the nodes at level 2 in the tree. _______________________________
B. (2 pts) Draw the tree created by the following statements. Btnode is defined on page 1.
Btnode root, a, b, c, d;
d = new Btnode (6, NULL, NULL);
c = new Btnode (9, d, NULL);
b = new Btnode (4, NULL, c);
a = new Btnode (12, NULL, NULL);
root = new Btnode (10, a, b);
C. (3 pts) Trace the method count() below and describe what it does
public static int count (Btnode t)
{ int ctLeft, ctRight, ct;
if (t == NULL)
ct = 0;
else
{ ctLeft = count(t.getLeft());
ctRight= count(t.getRight());
boolean flag = (t.getLeft()!= NULL && t.getRight()!= NULL);
ct = ctLeft + ctRight + (int)flag;
}
return ct;
}


D. (3 pts) Use the following tree traversal function. Assuming m is initially 0, what is the resultant value of m when
calling this method as f ( Btnode root, m) where root is the base of the tree in Question 3A?
_____________________________
public static void f(Btnode t, int n)
{ if (t != NULL)
{ n++;
f(t.getLeft(), n);
f(t.getRight(), n);
}
return;
}
E. (5 pts) Consider the following binary search tree. Use the original tree below when answering each subpart (a)
through (e).




(a) If the value 46 is inserted into this tree, which node becomes its parent? __________________
(b) If the value 64 is inserted into this tree, which node becomes its parent? ___________________
(c) If we delete node 65, which node should be its replacement node? ___________________
(d) If we delete node 90, which node should be its replacement node? __________________
(e) If we delete the root node 50, which node should be selected as its replacement node so that the fewest number
of changes are made to the tree? ______________________


4. Heaps and Graphs (19 pts)
A. (3 pts) A heap can be represented by a vector. Start with the following heap and list the elements after each operation.
Execute the operations sequentially, using the result of the previous operation. The initial vector values for the heap
are {50, 35, 15, 12, 3, 5}.


Monday, April 27, 2009

GUI

School
? Catchment area of school defines the area of houses influenced by the presence of the school.
? Catchment area for schools is 3km.
? The degree to which a school is considered good or bad is its influence level.
? Influence level is randomly assigned to each school in neighbourhood.
? Influence level: -10 being the worst (negatively influenced), 10 being the best (positively influenced).
? Houses within the 3km proximity radius will show an increase in price of 15%
? However “bad” schools will have no negative effect on house price.

Industrial Estates
? Catchment area of industrial estates defines the area of houses influence by its presence.
? Catchment area for industrial estates is 0.5km
? Industrial estate agents will group together to from an “industrial estate.”
? Industrial estates will have an influence level of -6.

Topography
? Topography defined as scenic areas, countryside, lakes, parks.
? Catchment area of topography defines the area of houses influence by its presence.
? Catchment area for topography 0.5km.
? Influence level for topography range from +5 to +10


Pubs
? Catchment area for pubs ranges from 0.5km to 4km
? Houses within 0.5km of the pub will negatively influence house prices by 8%
? Houses within 0.5km of pubs will carry the negative influence level of
? Houses outside 0.5km of the pub will positively influence house prices by 3%
? Houses outside 0.5km of pubs will carry the positive influence level of
? Influence level for topography range from +5 to +10

Town Centre
? Catchment area for town centre is 1.5km
? Houses prices within this catchment area will be positively influenced by 20%


Interest rates
? When interest rates increase, demand for housing decreases, therefore decrease in price.
? Interest rate ranges from 0 to 15.
? Demand for housing will be measured as a percentage change of the interest rate.
? E.g. if interest rate increases from 4.0 to 4.6 (change being +0.6) then demand decreases by 15% as does house price.

Policing Level
? If level of policing is 0-30% reduce all agents influence level by 5.
? If level of policing is 30-60% reduce all agents influence level by 3.
? If level of policing is 60-100% reduce all agents influence level by 1.




Inputs
Before the simulation is run the user will be able to set up the neighbourhood.

Interest rates
? Interest rates will range from 0 to 15.
? User will have the option to set default value for simulation (5)

Population
? Users will also be able to set the population density for the neighbourhood.
? Population density will range from 0 to 100%
? And will directly effect demand e.g. when population is at 100%, demand is at its highest (therefore price will be equally as high).
? User will have the option to set default value for simulation (75%)
?
Level of policing

General Inputs
? Users will be able to set default values for everything to allow the system run a controlled simulation.
? Users can set the catchment area and influence level for each amenity
? All houses start off with a default price of £100,000


Outputs
The outputs will be shown on a GUI that will help analyse the simulation as a whole.
Each agent will have its own colour, for example houses will be in blue, topography in green and so on.
To represent the difference in house price within the actual simulation, differeing house prices will be represented by different shades of blue. For example houses prices between 0 and 50,000 will show as a light blue, 50,000 to 100,000 a darker shade, 100,000 to 150,000 an even darker shade, until it reaches its maximum category 300,000+.


? Display all input values including interest rate, population
? The number of houses in the simulation
? The number of houses in each price category
? The average house price will be calculated
? The highest and lowest house price will be displayed
? Display the number of each amenity-school pubs topography etc



import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D.Double;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Graphics;
import java.awt.Color;
public class HouseMarketGUI extends JFrame implements ActionListener{

int population ;
int interestRate ;
int policingLevel ;



static HouseMarketGUI gui;
//Page1 GUI Variables
private JLabel p1labelt;
private JLabel p1labeltSub;
private JFrame p1frame;
private JLabel p1popLable;
private JLabel p1intLable;
private JLabel p1poliLable;
private JTextField p1popValue;
private JTextField p1intValue;
private JTextField p1poliValue;

private JButton p1button;
//end


public HouseMarketGUI(){



// size = new Dimension(0, 0);
// stats = new FieldStats();
// JPanel cp = new JPanel(new GridLayout(1, 1));
// JPanel cp1 = new JPanel();
//Page1 Create Object
p1frame= new JFrame(" Housing Market Simulation ");
p1frame.getContentPane().setLayout(null);

p1labelt = new JLabel("Housing Market Simulation");
p1labelt.setFont(new Font("Serif", Font.BOLD, 20));
p1labelt.setBounds(150,0,350,70);

p1labeltSub = new JLabel("Setup Environment");
p1labeltSub.setFont(new Font("Serif", Font.BOLD, 18));
p1labeltSub.setBounds(50,40,350,70);

p1popLable = new JLabel("Population(0-100)%");
p1popValue = new JTextField(35);
p1popValue.setText("75");
p1intLable = new JLabel("Interest Rate(0-15)");
p1intValue = new JTextField(35);
p1intValue.setText("5");

p1poliLable = new JLabel("Policing Level(0-100)%");
p1poliValue = new JTextField(35);
p1poliValue.setText("50");

p1button = new JButton("NEXT");
//end


//Page1 Position
p1popLable.setBounds(50,100,150,70);
p1intLable.setBounds(50,150,150,70);

p1popValue.setBounds(220,120,50,30);
p1intValue.setBounds(220,170,50,30);

p1poliLable.setBounds(50,200,150,70);
p1poliValue.setBounds(220,220,50,30);

p1button.setBounds(370,330,80,27);
//end

//page1 add contentPanel
p1frame.getContentPane().add(p1labelt);
p1frame.getContentPane().add(p1labeltSub);

p1frame.getContentPane().add(p1popLable);
p1frame.getContentPane().add(p1popValue);
p1frame.getContentPane().add(p1intLable);
p1frame.getContentPane().add(p1intValue);

p1frame.getContentPane().add(p1poliLable);
p1frame.getContentPane().add(p1poliValue);

p1frame.getContentPane().add(p1button);
//end



//page1 actionListener
p1button.addActionListener(this);
p1frame.setSize(550,550);
p1frame.setVisible(true);
//end




}

public void actionPerformed(ActionEvent event){

if(event.getSource() == p1button){
p1frame.setVisible(false);
p2frame.setVisible(true);
p3frame.setVisible(false);

p2namevalue.setText("0.5");
p2numberValue.setText("0.5");
p2salaryValue.setText("1.5");
p2pubValue.setText("0.5");
p2schoolValue.setText("3.0");

p2namevalue.setEditable(false);
p2numberValue.setEditable(false);
p2salaryValue.setEditable(false);
p2pubValue.setEditable(false);
p2schoolValue.setEditable(false);

population = Integer.parseInt(p1popValue.getText());
interestRate = Integer.parseInt(p1intValue.getText());
policingLevel = Integer.parseInt(p1poliValue.getText());






}



}



public static void main(String arg[]){


gui = new HouseMarketGUI();

}

}