Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

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 ...

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 ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Assignment - java program using array of objectsobjectives

Assignment - 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 Menu ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

  • 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