Question
How can I redo this so that it doesn't have static in front of double, int, and Scanner under defining variables? import java.util.*; public
How can I redo this so that it doesn't have "static" in front of double, int, and Scanner under defining variables?
import java.util.*;
public class chpt6 {
//Declaring global variables
static double speed, time;
static int height;
static Scanner input = new Scanner(System.in);
//This method computes for the height of the ball
public static double calcBallHeight(int height, double speed, double time) {
double ballHeight;
ballHeight = -(16*time*time) + (speed*time) + height;
return ballHeight;
}
public static void main(String[] args) {
//Prompts user to input
System.out.print("Enter the height of the building in feet as an integer: ");
height = input.nextInt();
System.out.print("Enter the initial speed of the ball in ft/sec as a double: ");
speed = input.nextDouble();
System.out.print("Enter the flight time of the ball as a double: ");
time = input.nextDouble();
//Calls the method to compute for the height of ball
double ballHeight = calcBallHeight(height,speed,time);
//Prints out the result
System.out.printf("The ball will be %.2f feet above the ground after %.2f seconds of flight time.", ballHeight, time);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
You can simply remove the static keyword from the variable declarations under Defining variables Her...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