Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def kinetic_energy(mass, velocity): formula =(mass)*(velocity**2) / 2 return formula mass = float(input(Input mass (kg): )) velocity = float(input(Input a velocity (meters per second): )) answer
def kinetic_energy(mass, velocity): formula =(mass)*(velocity**2) / 2 return formula mass = float(input("Input mass (kg): ")) velocity = float(input("Input a velocity (meters per second): ")) answer = kinetic_energy(mass, velocity) print("Kinetic Energy = ", format(answer, ".2f')) Rewrite this Python program as a Java class called KineticEnergy. KineticEnergy should have two instance variables, mass and velocity (both double types); a 2-argument constructor; and a single instance method, public double kineticEnergy () (but note that this method has no arguments, unlike the Python function by the same name). Include a main method inside your class that uses scanner to get inputs the same way that the Python class does. Use these inputs to then create a KineticEnergy object, and print the same formatted output as the Python program above. Note: (velocity 2 ) is "velocity squared." You can achieve this expression in Java with
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