Ask Java Expert


Home >> Java

Questions:

1. The class Boid represents a single movable object that can be drawn and run as a thread. The boid can move around the bounds of a panel with specified velocities in each of its x and y directions. Each Boid needs to know the position and velocities of the nearby (neighbouring) boids around it. However the class is not thread safe. Make the necessary changes to make this class thread safe and avoid any concurrency problems.

2. Using the following UML class diagram create a data structure calledBoidFlock that holds Boid objects in a list. The default constructor just creates an empty flock and initializes the boidList using an appropriate data structure, where the 2nd constructor creates a flock with the specified number of boids to start with. The addBoidToFlock method should add a new Boid to the boidList using random positions (0 - panel width and height) and velocities ( Boid.MAXSPEED), it also needs to pass itself as a reference to the newly created Boid, then should start the object up as a thread. The removeBoidFromFlock should remove an arbitrary Boid object from the list, also stopping its thread execution, destroyAllBoids should stop all boid threads running and clear the list, getNumberOfBoids returns the current number of boids in the list. The getNeighbours is used to return a new list of all the neighbouring boids that the boidToTest object has (excluding itself). A boid is a neighbour if its x and y value is within the DETECT RADIUS of the boidToTest parameter. Make sure this class uses generics where appropriate and that it is thread safe.

BoidFlock

+DETECTRADIUS : int

-boidList : List

+BoidFlock()

+BoidFlock(numBoidsToStart:int)

+addBoidToFlock() : void

+removeBoidFromFlock() : void

+drawAllBoids(g:Graphics): void

+getNumberOfBoids() : int

+destroyAllBoids() : void

+getNeighbours(boidToTest:Boid) : List

A boid with co-ordinates (x0, y0) is a neighbour to another boid (x1, y1) if: (x0 -x1)2 + (y0 -y1)2

3. Prepare a simple GUI called BoidGui to test the BoidFlock and Boid class which should display an entire flock of boids that move around within a panel bouncing off the walls. The GUI should repeatedly update its display by drawing the boids at fixed time intervals.. Add buttons for adding and removing boids or clearing the screen. Add sliders for manipulating radius detection and separation, cohesion and alignment weights of the boids.

4. Suppose an interface called RandomObtainable has been written for collections from which a random element should be obtainable. It has a method getRandom which should return an element randomly selected from the collection, and a method removeRandom that should try to remove a random element from the collection and insertRandom which inserts the element into the collection at a random location between zero and the size of the collection (inclusive). The getRandom should throw a NoSuchElementException if the collection is empty.

RandomObtainable

 

+getRandom() : E

+removeRandom() : boolean

+insertRandom(E element) : boolean

Extend the ArrayList class so that it implements this interface, and test it with a driver main method. At the top of your class in the header comments state what the asymptotic complexity is for each of the methods and why? If instead your class extended LinkedList, what are the asymptotic complexities?

Attachment:- java.zip

Java, Programming

  • Category:- Java
  • Reference No.:- M91724470
  • Price:- $70

Guranteed 36 Hours Delivery, In Price:- $70

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As