Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Description Average acceleration is defined as the change of velocity divided by the time taken to make the change. Part 1 - - Variables: Create
Description
Average acceleration is defined as the change of velocity divided by the time taken to make the change.
Part Variables:
Create a new class AverageAcceleration with a main method.
in the main method, Create a scanner
Scanner input new ScannerSystemin;
Ask the user to enter a starting velocity, an ending velocity, and time All are doubles. store them in variables
Enter starting velocity in meters second;
Enter ending velocity in meters second:
Enter the time in seconds:
create a double acceleration variable for the calculation
acceleration v vt
Print out the variables
Print the acceleration formatted this waySee Example output below:
The average acceleration is meters second.
Run the program
Part Conditionals:
Use one condition with one ifelse statement to display an error if any of the entered data for starting velocity, ending velocity, andor time is less than ; else compute and display the average acceleration.
if the data is invalid print the following message:
Invalid data. Please check data entered.
move the acceleration calculation to the else.
Run the program...verify that the if prints the expected invalid statement.
Part Loops:
Let's create a loop around the current code that will allow us to ask and run acceleration calculations until the user quits
which loop should we use?
Ask the user after the first loop if they want to enter another password
Would you like to enter another calculation? enter Y for yes
Run the program
Part ArraysArrayList:
Collect the calculated accelerations in an ArrayList
after the loop that ask for User input and does the calculation, create another loop to iterate thru the acceleration ArrayList
move the print out into the new loop and update it to use the ArrayList to print the valuesSee Example output below:
The average acceleration is meters second.
The average acceleration is meters second.
Run the program
Part Methods:
Our code is starting to get a little messy
create a method calculateAcceleration
parameters: double startVelocity, double endVelocity, double time
return: Double. Note: if the User input is Invalid data, then return null.
move the ifelse code into the method. The adding to the ArrayList should stay in the main method.
In the main method, update the code to use the calculateAcceleration method. Note: if the method returns null, then do not add it to the ArrayList
Run the program
Example output:
Sample Run userentered data in red
Enter starting velocity in meters second:
Enter ending velocity in meters second:
Enter the time in seconds:
Would you like to enter another calculation? enter Y for yes N
The average acceleration is meters second.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started