CS145 PROGRAMMING ASSIGNMENT #1 OVERVIEW - This is a review exercise, so the primary goal of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
CS145 PROGRAMMING ASSIGNMENT #1 OVERVIEW - This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space. In this activity you will create an imaginary cube of locations that goes from -5≤ x ≤ 5, -5≤ y≤5, and -5≤ Z ≤ 5 with the coordinate (0,0,0) being "home". On this grid you will keep track of various bird objects as they move around the grid. Make sure that all birds stay within that box at all times including when they are created. Using Java, create the following classes and primary program that uses the classes that you developed. INSTRUCTIONS Create the following classes. BIRD CLASS Create a Bird class. Each bird has a name, an x,y, and z integer coordinate. The Bird class should have at minimum the following methods below but you may want to add more if necessary: • • A default constructor that starts the bird at 1,1,1 with a name of "Unknown Bird". A constructor that allows the user to start with a given name. 。 In this case, the constructor should give the bird a random x,y,z that are inside the box. A parameter constructor that allows the programmer to input all 4 pieces of information. (x,y,z,name) о Check the parameters for valid input based on the constraints. If any of the input coordinates is invalid, that particular coordinate should be set to -1. getx() getY() getz() • • getName() toString() ° This should print out the name and coordinates of the animal. touching (Bird other) о This method should determine if the bird is on the same spot as a second bird (x). It should return a boolean value of true if they are touching and false if they are not on the same location. move() о When this method is run, the animal will move in a random direction. The animal can move in one of six directions. ° ° о о The animal could move left, or right, or up, or down, or in/out. If the animal moves in one of these directions, it should move random x number of units, where x is between 1 and 2 (inclusive). Each direction should have an equal chance of happening, so make sure everything is balanced. Note that there are no parameters. The animal should self move. Check for the range constraints. After the bird has moved, double check that it is still inside the box. " If it isn't, undo the move and pick a different direction to move. Check both x, y, and z coordinates at all times including construction. " • After the bird has moved, double check that it is still inside the box. MAIN CLASS Inside your main class do the following • Create an array that can hold 7 birds. ° Fill the array with 4 birds with names and locations of your choice. 。 Fill the array with 2 named birds but with random locations. o Finish filling the array with one default bird. • Create a touching counter that starts at zero and a round counter. • Print out the starting locations and names of all the animals. • Then do the following loop. o Print out the round number. ° Move all the birds randomly. o Check all the birds to see if any of them are on the same spot. о " Make sure to check for touching animals AFTER moving all the animals. If any of the birds are touching it should print out the word "TOUCHING" to the screen and show the names of the two animals that are touching. • Note if A is touching B, do NOT also print that B is touching A. Each touch should only be printed once. o Print out the current locations and names of all birds. ° Print a line "[############## round of the movement. ############]" between each • Repeat the loop above until there are at least 6 touches. • Print out the total number of fights. O This will probably be 6 but might be larger IF there were multiple touches on the last round. Print out the total number of rounds that it took to get to 6 touches. SAMPLE OUTPUT *** Beginning of program Eagle is at 1, 2, 3 Hawk is at 3, 3, 3 Finch is at 1, 1, 1 Sparrow is at 5, 5, 5 *** Humming Bird is at 1, 3, 0 Dove is at 4, 1, -4 Unknown Bird is at 0, 0, 0 [####### Round 1 Eagle is at 3, 2, 3 Hawk is at 3, 1, 3 Finch is at 1, 1, 0 Sparrow is at 5, 3, 5 Humming Bird is at -4, 3, 2 Dove is at 4, 1, -1 Unknown Bird is at 0, 1, 0 [### Round 2 Eagle is at 2, 2, 3 Hawk is at 2, 1, 3 Finch is at 1, 0, 0 Sparrow is at 3, 3, 5 Humming Bird is at -3, 3, 2 Dove is at 4, 1, 5 Unknown Bird is at 2, 1, 0 ####] ] [######## Round 3 TOUCH Eagle vs Hawk Eagle is at 2, 0, 3 Hawk is at 2, 0, 3 Finch is at 0, 0, 0 Sparrow is at 3, 3, -2 Humming Bird is at 2, 3, 2 Dove is at 4, 1, 4 Unknown Bird is at 2, 1, 2 [######### Round 964 TOUCH - ########] ######] Sparrow vs Humming Bird Eagle is at -1, -5, 4 Hawk is at 1, 4, -3 Finch is at -1, -1, -1 Sparrow is at 4, 5, -2 Humming Bird is at 4, 5, -2 Unknown Bird is at 1, 3, 4 Dove is at 1, -4, 3 [############ ########] There was a total of 964 rounds to get to 6 touches. CS145 PROGRAMMING ASSIGNMENT #1 OVERVIEW - This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space. In this activity you will create an imaginary cube of locations that goes from -5≤ x ≤ 5, -5≤ y≤5, and -5≤ Z ≤ 5 with the coordinate (0,0,0) being "home". On this grid you will keep track of various bird objects as they move around the grid. Make sure that all birds stay within that box at all times including when they are created. Using Java, create the following classes and primary program that uses the classes that you developed. INSTRUCTIONS Create the following classes. BIRD CLASS Create a Bird class. Each bird has a name, an x,y, and z integer coordinate. The Bird class should have at minimum the following methods below but you may want to add more if necessary: • • A default constructor that starts the bird at 1,1,1 with a name of "Unknown Bird". A constructor that allows the user to start with a given name. 。 In this case, the constructor should give the bird a random x,y,z that are inside the box. A parameter constructor that allows the programmer to input all 4 pieces of information. (x,y,z,name) о Check the parameters for valid input based on the constraints. If any of the input coordinates is invalid, that particular coordinate should be set to -1. getx() getY() getz() • • getName() toString() ° This should print out the name and coordinates of the animal. touching (Bird other) о This method should determine if the bird is on the same spot as a second bird (x). It should return a boolean value of true if they are touching and false if they are not on the same location. CS145 PROGRAMMING ASSIGNMENT #1 OVERVIEW - This is a review exercise, so the primary goal of the exercise is to get your mind working and in the correct space. In this activity you will create an imaginary cube of locations that goes from -5≤ x ≤ 5, -5≤ y≤5, and -5≤ Z ≤ 5 with the coordinate (0,0,0) being "home". On this grid you will keep track of various bird objects as they move around the grid. Make sure that all birds stay within that box at all times including when they are created. Using Java, create the following classes and primary program that uses the classes that you developed. INSTRUCTIONS Create the following classes. BIRD CLASS Create a Bird class. Each bird has a name, an x,y, and z integer coordinate. The Bird class should have at minimum the following methods below but you may want to add more if necessary: • • A default constructor that starts the bird at 1,1,1 with a name of "Unknown Bird". A constructor that allows the user to start with a given name. 。 In this case, the constructor should give the bird a random x,y,z that are inside the box. A parameter constructor that allows the programmer to input all 4 pieces of information. (x,y,z,name) о Check the parameters for valid input based on the constraints. If any of the input coordinates is invalid, that particular coordinate should be set to -1. getx() getY() getz() • • getName() toString() ° This should print out the name and coordinates of the animal. touching (Bird other) о This method should determine if the bird is on the same spot as a second bird (x). It should return a boolean value of true if they are touching and false if they are not on the same location. move() о When this method is run, the animal will move in a random direction. The animal can move in one of six directions. ° ° о о The animal could move left, or right, or up, or down, or in/out. If the animal moves in one of these directions, it should move random x number of units, where x is between 1 and 2 (inclusive). Each direction should have an equal chance of happening, so make sure everything is balanced. Note that there are no parameters. The animal should self move. Check for the range constraints. After the bird has moved, double check that it is still inside the box. " If it isn't, undo the move and pick a different direction to move. Check both x, y, and z coordinates at all times including construction. " • After the bird has moved, double check that it is still inside the box. MAIN CLASS Inside your main class do the following • Create an array that can hold 7 birds. ° Fill the array with 4 birds with names and locations of your choice. 。 Fill the array with 2 named birds but with random locations. o Finish filling the array with one default bird. • Create a touching counter that starts at zero and a round counter. • Print out the starting locations and names of all the animals. • Then do the following loop. o Print out the round number. ° Move all the birds randomly. o Check all the birds to see if any of them are on the same spot. о " Make sure to check for touching animals AFTER moving all the animals. If any of the birds are touching it should print out the word "TOUCHING" to the screen and show the names of the two animals that are touching. • Note if A is touching B, do NOT also print that B is touching A. Each touch should only be printed once. o Print out the current locations and names of all birds. ° Print a line "[############## round of the movement. ############]" between each move() о When this method is run, the animal will move in a random direction. The animal can move in one of six directions. ° ° о о The animal could move left, or right, or up, or down, or in/out. If the animal moves in one of these directions, it should move random x number of units, where x is between 1 and 2 (inclusive). Each direction should have an equal chance of happening, so make sure everything is balanced. Note that there are no parameters. The animal should self move. Check for the range constraints. After the bird has moved, double check that it is still inside the box. " If it isn't, undo the move and pick a different direction to move. Check both x, y, and z coordinates at all times including construction. " • After the bird has moved, double check that it is still inside the box. MAIN CLASS Inside your main class do the following • Create an array that can hold 7 birds. ° Fill the array with 4 birds with names and locations of your choice. 。 Fill the array with 2 named birds but with random locations. o Finish filling the array with one default bird. • Create a touching counter that starts at zero and a round counter. • Print out the starting locations and names of all the animals. • Then do the following loop. o Print out the round number. ° Move all the birds randomly. o Check all the birds to see if any of them are on the same spot. о " Make sure to check for touching animals AFTER moving all the animals. If any of the birds are touching it should print out the word "TOUCHING" to the screen and show the names of the two animals that are touching. • Note if A is touching B, do NOT also print that B is touching A. Each touch should only be printed once. o Print out the current locations and names of all birds. ° Print a line "[############## round of the movement. ############]" between each • Repeat the loop above until there are at least 6 touches. • Print out the total number of fights. O This will probably be 6 but might be larger IF there were multiple touches on the last round. Print out the total number of rounds that it took to get to 6 touches. • Repeat the loop above until there are at least 6 touches. • Print out the total number of fights. O This will probably be 6 but might be larger IF there were multiple touches on the last round. Print out the total number of rounds that it took to get to 6 touches. SAMPLE OUTPUT *** Beginning of program Eagle is at 1, 2, 3 Hawk is at 3, 3, 3 Finch is at 1, 1, 1 Sparrow is at 5, 5, 5 *** Humming Bird is at 1, 3, 0 Dove is at 4, 1, -4 Unknown Bird is at 0, 0, 0 [####### Round 1 Eagle is at 3, 2, 3 Hawk is at 3, 1, 3 Finch is at 1, 1, 0 Sparrow is at 5, 3, 5 Humming Bird is at -4, 3, 2 Dove is at 4, 1, -1 Unknown Bird is at 0, 1, 0 [### Round 2 Eagle is at 2, 2, 3 Hawk is at 2, 1, 3 Finch is at 1, 0, 0 Sparrow is at 3, 3, 5 Humming Bird is at -3, 3, 2 Dove is at 4, 1, 5 Unknown Bird is at 2, 1, 0 ####] ] SAMPLE OUTPUT *** Beginning of program Eagle is at 1, 2, 3 Hawk is at 3, 3, 3 Finch is at 1, 1, 1 Sparrow is at 5, 5, 5 *** Humming Bird is at 1, 3, 0 Dove is at 4, 1, -4 Unknown Bird is at 0, 0, 0 [####### Round 1 Eagle is at 3, 2, 3 Hawk is at 3, 1, 3 Finch is at 1, 1, 0 Sparrow is at 5, 3, 5 Humming Bird is at -4, 3, 2 Dove is at 4, 1, -1 Unknown Bird is at 0, 1, 0 [### Round 2 Eagle is at 2, 2, 3 Hawk is at 2, 1, 3 Finch is at 1, 0, 0 Sparrow is at 3, 3, 5 Humming Bird is at -3, 3, 2 Dove is at 4, 1, 5 Unknown Bird is at 2, 1, 0 ####] ] [######## Round 3 TOUCH Eagle vs Hawk Eagle is at 2, 0, 3 Hawk is at 2, 0, 3 Finch is at 0, 0, 0 Sparrow is at 3, 3, -2 Humming Bird is at 2, 3, 2 Dove is at 4, 1, 4 Unknown Bird is at 2, 1, 2 [######### Round 964 TOUCH - ########] ######] Sparrow vs Humming Bird Eagle is at -1, -5, 4 Hawk is at 1, 4, -3 Finch is at -1, -1, -1 Sparrow is at 4, 5, -2 Humming Bird is at 4, 5, -2 Unknown Bird is at 1, 3, 4 Dove is at 1, -4, 3 [############ ########] There was a total of 964 rounds to get to 6 touches. [######## Round 3 TOUCH Eagle vs Hawk Eagle is at 2, 0, 3 Hawk is at 2, 0, 3 Finch is at 0, 0, 0 Sparrow is at 3, 3, -2 Humming Bird is at 2, 3, 2 Dove is at 4, 1, 4 Unknown Bird is at 2, 1, 2 [######### Round 964 TOUCH - ########] ######] Sparrow vs Humming Bird Eagle is at -1, -5, 4 Hawk is at 1, 4, -3 Finch is at -1, -1, -1 Sparrow is at 4, 5, -2 Humming Bird is at 4, 5, -2 Unknown Bird is at 1, 3, 4 Dove is at 1, -4, 3 [############ ########] There was a total of 964 rounds to get to 6 touches.
Expert Answer:
Answer rating: 100% (QA)
Limited Direct Connection The circuit design course management system and bird simulation data are not directly related in terms of functionality They ... View the full answer
Related Book For
Financial management theory and practice
ISBN: 978-0324422696
12th Edition
Authors: Eugene F. Brigham and Michael C. Ehrhardt
Posted Date:
Students also viewed these programming questions
-
Consider the method below, which is intended to return true if there is at least one duplicate in the vector, and false if there are no duplicates. bool hasdupicate ( ( vectornums ) ) { { for ( ( int...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
At fiscal year-end December 31, 2015, Shop-World had the following assets and liabilities on its balance sheet (in millions): Current liabilities ............ $9,459 Long-term debt .................
-
The Morton Company recently reported net profits after taxes of $15.8 million. It has 2.5 million shares of common stock outstanding and pays preferred dividends of $1 million a year. The company's...
-
Gail and Harry own the GH Partnership, which has conducted business for 10 years. The bases for their partnership interests are $100,000 for Gail and $150,000 for Harry. GH Partnership has the...
-
The time constant for the discharge of this capacitor is. A. 5 s B. 4 s C. 2 s D. 1 s ww 202 20 ww HH 1 F
-
Corinne Dunbar, M.D., maintains the accounting records of Dunbar Clinic on a cash basis. During 2012, Dr. Dunbar collected $142,600 from her patients and paid $60,470 in expenses. At January 1, 2012,...
-
For the month a company had total cost of goods available for sale of $900,000, and cost of goods sold of $700,00. If inventories increased by $100,000 over the period, what was their beginning...
-
The Apex Television Company has to decide on the number of 65 and 55 sets to be produced at one of its factories. Market research indicates that at most 280 of the 65 sets and 70 of the 55 sets can...
-
Leto Inc. purchased merchandise on account from Metis Inc. for $25,000, credit terms being 2/10, n/30. If Leto pays the invoice within the discount period, what amount will Metis receive as payment?...
-
8. Use both algorithms to find spanning trees for the graph in Figure 0.4. (3 5 (6) 8 (10 (11) (12) (13) (14) Figure 0.4
-
7) (i) If k is a positive integer, A is an eigenvalue of a matrix A, and v is a corresponding eigenvector, then A is an eigenvalue of A* and v is a corresponding eigenvector. (ii) use 6(i) to find...
-
How do you think the practices of Operations Management can be applied to Colleges and Universities. Remember, if the practices are implemented successfully, quality will increase and cost will...
-
TASK: Our Challenge: Cooperation: I will choose to invest in and work with others to achieve success for both my team and myself. Write one way you have recently applied or adjusted your strengths to...
-
What will be printed by the code below? (notice that there is no new-lines-enter- or whitespaces) #include using namespace std; class A ( public: A() (cout < < "+1";} -A() (cout < < "-1";} }; class...
-
If there is deficiency in the alpha granules of a blood platelets, what is the most logical conciseness for it ? Purpura Thrombocytopenia Thrombocythemia
-
A circular concrete shaft liner with Youngs modulus of 3.4 million psi, Poissons ratio of 0.25, unconfined compressive strength 3,500 psi and tensile strength 350 psi is loaded to the verge of...
-
Tunney Industries can issue perpetual preferred stock at a price of $50 a share. The issue is expected to pay a constant annual dividend of $3.80 a share. The flotation cost on the issue is estimated...
-
A. Sadik Industries must install $1 million of new machinery in its Texas plant. It can obtain a bank loan for 100 percent of the required amount. Alternatively, a Texas investment banking firm that...
-
Explain how net operating working capital is recovered at the end of a projects life, and why it is included in a capital budgeting analysis.
-
Figure 7.18 shows a liquid-level system in which two tanks have cross-sectional areas \(A_{1}\) and \(A_{2}\), respectively. The volume flow rate into tank 1 is \(q_{\mathrm{i}}\). A pump is...
-
For the three-room house shown in Figure 7.35, all rooms are perfect squares and have the same dimensions. An air conditioner produces an equal amount of heat flow \(q_{\mathrm{ho}}\) out of each...
-
Consider the single-tank liquid-level system shown in Figure 7.19, where the volume flow rate into the tank through a pipe is \(q_{\mathrm{i}}\). The liquid leaves the tank through an orifice of area...
Study smarter with the SolutionInn App