Answered step by step
Verified Expert Solution
Link Copied!

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 1--Variables:
Create a new class AverageAcceleration with a main method.
in the main method, Create a scanner
Scanner input = new Scanner(System.in);
Ask the user to enter a starting velocity, an ending velocity, and time . All 3 are doubles. store them in 3 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 =(v1- v0)/t
Print out the 3 variables
Print the acceleration formatted this way(See Example output below):
The average acceleration is 10.088888888888889 meters / second.
Run the program
Part 2--Conditionals:
Use one condition with one if-else statement to display an error if any of the entered data for starting velocity, ending velocity, and/or time is less than 0; 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 3--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 4--Arrays/ArrayList:
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 values(See Example output below):
The average acceleration is 17.142857142857142 meters / second.
The average acceleration is 10.088888888888889 meters / second.
Run the program
Part 5--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 if/else 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 (user-entered data in red)
Enter starting velocity in meters / second: 5.5
Enter ending velocity in meters / second: 50.9
Enter the time in seconds: 4.5
Would you like to enter another calculation? enter Y for yes N
The average acceleration is 10.088888888888889 meters / second.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

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

Survey of Accounting

Authors: Thomas Edmonds, Christopher, Philip Olds, Frances McNair, Bor

4th edition

77862376, 978-0077862374

Students also viewed these Databases questions