Part A: Using the UML below create a class that represents a fish swimming in a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Part A: Using the UML below create a class that represents a fish swimming in a tank. A Fish runs in a separate thread while it is still alive and has an x,y position. A fish moves within its world from (0,0) to (world_width, world_height) pixel coordinates, increasing its position by suitable dx,dy movement values. It will also periodically generate small randomized noise factors which are added or subtracted to its dx, dy movement values after several movements (but still keeping dx and dy below an upper threshold). A fish is also randomly given a size during instantiation within some min and max value. A fish is instantiated with a reference to a FishShoal collection. Fish x, y double dx, dy double size: double isAlive boolean + world width, world height : int colour Color [] shoal FishShoal + Fish (shoal: FishShoal) + run (): void + getX(): double + getY(): double + getSize(): double +kill (): void move(): void + eat (target: Fish): void +draw (g Graphics) : void Part B: Using the UML diagram below, create a class called FishShoal which represents a shoal of fish by encapsulating a List of Fish objects. It has methods to remove and add fish to the shoal and size to obtain the number of fish in the shoal. It has a method drawShoal which draws all fish in the shoal by calling the draw method of each Fish. The method canEat is used to check if the parameter fish can eat any other fish in the shoal. The two basic rules for the parameter fish to eat another fish in the fish shoal is as follows: The parameter fish must be 40% bigger in size than a target fish The parameter Fish position must be within range of the target fish position, the range is determined by taking an average of the size of the two fish. If the parameter fish can eat a fish in the shoal the canEat method will return reference to that fish otherwise it will return null if the parameter fish cannot eat. FishShoal -fishList List<Fish> +FishShoal() + add (fish + remove (fish + drawshoal (g: + canEat (fish: Fish) Fish Fish): void Fish) : void Graphics) : void As a fish moves around the world it should check to see if it can eat another fish by passing itself to the FishShoal method canEat, and obtaining a reference to a target fish available to eat (or null if it cannot eat a fish). The eat method is used to feed this fish with the target parameter fish, in which case it kills the target fish (stopping its thread from running) and increases its size (up to a maximum). If a fish dies it should remove itself from the shoal. A three coloured fish can be drawn as follows: speed= √√dx² + dy² (x-velX + vely, y-velx-vely), (x-2x velx,y - 2 x vely) velX = (x,y) size xdx 2 xspeeed vely = (x-velX -vely, y + velX - vely) size xay 2 xspeeed Fish Bowl V K K K 7 YOU PAY 71 71 K K Part A: Using the UML below create a class that represents a fish swimming in a tank. A Fish runs in a separate thread while it is still alive and has an x,y position. A fish moves within its world from (0,0) to (world_width, world_height) pixel coordinates, increasing its position by suitable dx,dy movement values. It will also periodically generate small randomized noise factors which are added or subtracted to its dx, dy movement values after several movements (but still keeping dx and dy below an upper threshold). A fish is also randomly given a size during instantiation within some min and max value. A fish is instantiated with a reference to a FishShoal collection. Fish x, y double dx, dy double size: double isAlive boolean + world width, world height : int colour Color [] shoal FishShoal + Fish (shoal: FishShoal) + run (): void + getX(): double + getY(): double + getSize(): double +kill (): void move(): void + eat (target: Fish): void +draw (g Graphics) : void Part B: Using the UML diagram below, create a class called FishShoal which represents a shoal of fish by encapsulating a List of Fish objects. It has methods to remove and add fish to the shoal and size to obtain the number of fish in the shoal. It has a method drawShoal which draws all fish in the shoal by calling the draw method of each Fish. The method canEat is used to check if the parameter fish can eat any other fish in the shoal. The two basic rules for the parameter fish to eat another fish in the fish shoal is as follows: The parameter fish must be 40% bigger in size than a target fish The parameter Fish position must be within range of the target fish position, the range is determined by taking an average of the size of the two fish. If the parameter fish can eat a fish in the shoal the canEat method will return reference to that fish otherwise it will return null if the parameter fish cannot eat. FishShoal -fishList List<Fish> +FishShoal() + add (fish + remove (fish + drawshoal (g: + canEat (fish: Fish) Fish Fish): void Fish) : void Graphics) : void As a fish moves around the world it should check to see if it can eat another fish by passing itself to the FishShoal method canEat, and obtaining a reference to a target fish available to eat (or null if it cannot eat a fish). The eat method is used to feed this fish with the target parameter fish, in which case it kills the target fish (stopping its thread from running) and increases its size (up to a maximum). If a fish dies it should remove itself from the shoal. A three coloured fish can be drawn as follows: speed= √√dx² + dy² (x-velX + vely, y-velx-vely), (x-2x velx,y - 2 x vely) velX = (x,y) size xdx 2 xspeeed vely = (x-velX -vely, y + velX - vely) size xay 2 xspeeed Fish Bowl V K K K 7 YOU PAY 71 71 K K
Expert Answer:
Answer rating: 100% (QA)
Here is the Java code for the Fish class and FishShoal class as per the given UML diagrams Fish Clas... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
i need a java code please do it in 1 hr I'll give you 5likes please test your code before submitting iti want output screen shot also rotate the image if you fine any difficulty Consider a non-empty...
-
Convert the following JAVA code into Python please provide screenshots of the output as well as the pythoncode. Exercise 2: Applying higher order functions The following Java code implements...
-
Q. Want the multiplication code for this using java please Multiplying a Matrix by Another Matrix 78 1 2 3 [ 4 3 8 ] [ 20 ] = [58 64] X 9 10 456 11 12 (1, 2, 3) (1, 2, 3) (4, 5, 6) (4, 5, 6) (7, 9,...
-
We-B-Busy, Inc. uses job costing and a predetermined overheadrate based onmachine hours (MH). The firm estimated that it would use $240,000of MOH and7,500 MH this year. Data for February:Job 1010 2...
-
In what ways did IBMs corporate-level strategy help protect and defend its business-level strategy? From its beginnings as a company that developed instruments to measure time, IBM grew to become the...
-
Use the Half-angle Formulas to find the exact value of expression. tan 9/8
-
On August 31, Pro Tennis Equipment had a $150,000 debit balance in Accounts Receivable. During September, Pro Tennis Equipment had the following transactions: Sales of $500,000, all on credit. ...
-
Amy Torbert operates Hollins Riding Academy. The academy's primary sources of revenue are riding fees and lesson fees, which are paid on a cash basis. Amy also boards horses for owners, who are...
-
(a) Define semistrongform market efficiency. (b) Using the evidence discussed in class, explain whether the evidence on the return behavior of 'size based portfolios' and 'booktomarket based...
-
Big Guy Inc. purchased 80% of the outstanding voting shares of Humble Corp. for $360,000 on July 1, 2017. On that date, Humble Corp. had common shares and retained earnings worth $180,000 and...
-
Suppose it is known that in a certain population, 5 percent of the population is colorblind. If a random sample of 10 people is drawn from this population, the mean of the variable is: Select one: O...
-
I scored a 35 out of 40 which puts me closer to the Theory y attitudes. Did you expect your score to be high or low? Any surprises? Are your stronger or milder points an asset? What is the theory X...
-
Minden Company is a wholesale distributor of premium European chocolates. The company s balance sheet as of April 3 0 is given below: MINDEN COMPANY Balance Sheet April 3 0 Assets Cash $ 1 5 , 1 0 0...
-
Denzel Corporation is planning to issue bonds with a face value of $620,000 and a coupon rate of 7.5 percent. The bonds mature in 8 years and pay interest semiannually every June 30 and December 31....
-
Schroeder Baking Corporation uses process costing in its large-scale baking operations. In the Mixing Department in July, the cost of beginning work in process inventory was $4,240, the cost of...
-
During the month of March, Olinger Company's employees earned wages of $72,100. Withholdings related to these wages were $5,516 for Social Security (FICA), $8,449 for federal income tax, $3,492 for...
-
(1) What is the code to add an additional array that lists the managers of the individual tasks? (2) What is the code to add an additional array that lists whether a project was successfully...
-
For the following exercises, find the inverse of the function and graph both the function and its inverse. f(x) = 4 x 2 , x 0
-
Greg died on July 1, 2012, and left Lea, his wife, a $50,000 life insurance policy which she elects to receive at $5,000 per year plus interest for 10 years. In the current year, Lea receives $6,200....
-
Jerry made the following contributions during 2012: His synagogue (by check).....................................................$680 The Democratic Party (by check)...
-
Larry and Lisa Williams, both 33 years old, have been married for 9 years. They live at 638 Arctic Way, Fairbanks, AK 99701. Lisa's Social Security number is 445- 81-1423 and Larry's is 798-09-8526....
-
The following table presents prices, in thousands of dollars, of single-family homes for some of the largest metropolitan areas in the United States for the third quarter of 2015 and the third...
-
Following are the closing prices of Google stock for each trading day in May and June of a recent year. a. Find the mean and median price in May. b. Find the mean and median price in June. c. Does...
-
Following are the weights, in pounds, for offensive and defensive linemen on the New York Giants National Football League team at the beginning of a recent year. a. Find the mean and median weight...
Study smarter with the SolutionInn App