Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java code for below instruction: For this programming assignment, you'll create a JavaFX application that displays and controls Vehicle objects created by Vehicle

Write a java code for below instruction:

For this programming assignment, you'll create a JavaFX application that displays and controls Vehicle objects created by Vehicle class(given program Vehicle.java). The diagram below shows what your GUI should look like. Your GUI should allow the user to create up to five vheicles. As each vehicle is created, it is represented as a colored circle in the central drawing pane and as a label in the left area of the GUI (with the same background color as the circle). In the figure below, the user has just used the Create Vehicle button to create the first vehicle at location (100, -120) with velocity 50 and direction 90. The first vehicle color is red, so the vehicle is represented by a red circle in the central drawing pane and via the red label on the left.

Vehicle Display rection 90 Y Coordinate -120 Velocity 50 x Coordinate 100 Acceleration ime Direction Change Vehicle Number Create Vehicle Delete Vehicle Accelerate Change Direction Move Vehicle Quit

Details of the GUI's operation: Your application must obey the following rules:

? Your class for the GUI must be called VehicleGUI and it must be part of the vehicle package that contains the Vehicle class.

? There can be only five vehicles created by your GUI. If the user tries to create a sixth vehicle; your GUI will simple ignore the request.

? Each of the vehicles created must have a unique color chosen from the following: RED, GREEN, BLUE, PURPLE, PINK.

? The central drawing pane should be 300 by 300 and surrounded by a black border

? When the Create Vehicle button is press, your GUI should attempt to create a vehicle. In order to succesfully create a vehicle, the following must hold: 1) there must be less than five vehicles, the four text fields at the top of the GUI (X Coordinate, Y Coordinate, Velocity, and Direction) plus the Vehicle Number field must be filled with numeric values and the Y Coordinate value must be zero or less. If any of these conditions do not hold, simply ignore the request. When creating the vehicle, negate the Y Coordinate value, which will produce a Y Coordinate value suitable for JavaFX. After the vehicle is created, draw the circle with one of the remaining colors and create the label for the vehicle.

? When the Delete Vehicle button is pressed, your GUI should attempt to delete the vehicle identified by the number in the Vehicle Number text field. If the Vehicle Number text field is empty or does not hold a number, simply ignore the request. Remove the circle and label for this vehicle and return its color to the available colors.

? When the Accelerate button is pressed, your GUI should attempt to change the velocity of the vehicle identified by the Vehicle Number field, using the values in the Accelerate and Time text fields. If any of these three text fields do not contain numeric values, simply ignore the request. Note that this will not have an effect on the GUI.

? When the Change Direction button is pressed, your GUI should attempt to change the direction of the vehicle identified by the Vehicle Number field, using the value in the Direction text field. If either of these text fields do not contain numeric values, simply ignore the request. Note that this will not have an effect on the GUI.

? When the Move Vehicle is pressed, your GUI should attempt to move the vehicle identified by the Vehicle Number field, using the value in the Time field as the amount of time the vehicle travels. If either of the text fields do not contain numeric values, simply ignore the request. If either of the new X, Y values is outside the drawing area (the values are negative or greater than 300, ignore the request. If the request is successful, change the vehicle's coordinates and also the representing circle's coordinates.

? When the Quit button is pressed, terminate the application. You can use System.exit() to do this.

x Coordinate 100 Vehicle Vehicle Display Y Coordinate -120 Create Vehicle Delete Vehicle Accelerate Velocity 50 Direction 90 Change Direction Move Vehicle Acceleration Time Direction Change Vehicle Number Quit

Step by Step Solution

3.43 Rating (150 Votes )

There are 3 Steps involved in it

Step: 1

VehicleGUIjava package vehicle import javafxapplicationApplication import javafxsceneGroup import javafxsceneScene import javafxscenecontrolButton import javafxscenecontrolLabel import javafxscenecont... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Document Format ( 2 attachments)

PDF file Icon
609a680a291d4_30586.pdf

180 KBs PDF File

Word file Icon
609a680a291d4_30586.docx

120 KBs Word File

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

More Books

Students also viewed these Programming questions