Reputation:
So, I'm trying to figure out how to set up my new object parameters as well as my object constructor parameters correctly. When I leave the new object line the way it is I get the error message "constructor KingFallingItem in class KingFallingItem cannot be applied to given types; required: double, double found: no arguments reason: actual and formal argument lists differ in length"
I'm not quite sure what I should put within the () on the new object creation line. I tried double initialPosition and initialVelocity, as well as getInitPosition and getInitVelocity. I feel like I'm forgetting some important information here. Any help would be appreciated. I'm not done coding all the parts of my program yet so the for loop makes no sense, I wanted to get this first part all working correctly first.
first file:
public class KingFallingItem {
//data fields
private final double INITIAL_POSITION;
private final double INITIAL_VELOCITY;
private int currentTime;
private double currentPosition;
private double currentVelocity;
public static final int TERMINAL_VELOCITY = -500;
// box contstructor
public KingFallingItem(double initialPosition, double initialVelocity) {
INITIAL_POSITION = initialPosition;
INITIAL_VELOCITY = initialVelocity;
currentTime = 0;
currentPosition = INITIAL_POSITION;
currentVelocity = INITIAL_VELOCITY;
}
}
second file:
import java.util.Scanner;
public class KingTrajectoryProjector {
public static int HEIGHT_THRESHOLD = 600;
public static void main(String[] args) {
System.out.println("This program will calculate the position and"
+ "velocity of a alling object until it reaches "
+ HEIGHT_THRESHOLD + " feet above ground");
getInitPosition();
getInitVelocity();
System.out.println();
System.out.println();
KingFallingItem fallingItem = new KingFallingItem();
int count;
for (count = 5; count >= 1; count--) {
System.out.println("Countdown:");
System.out.println(" " + count);
}
}
public static double getInitPosition() {
Scanner keyboard = new Scanner(System.in);
double initialPosition;
do {
System.out.print("Enter an initial position"
+ " (must be over 600.0 feet): ");
initialPosition = keyboard.nextDouble();
} while (initialPosition < HEIGHT_THRESHOLD);
return initialPosition;
}
public static double getInitVelocity() {
Scanner keyboard = new Scanner(System.in);
double initialVelocity;
do {
System.out.print("Enter an initial velocity "
+ "(-500.0 ft/sec or more: ");
initialVelocity = keyboard.nextDouble();
} while (initialVelocity < -500.0);
return initialVelocity;
}
}
Upvotes: 0
Views: 66
Reputation: 191738
I don't see why this wouldn't work
double position = getInitPosition();
double velocity = getInitVelocity();
System.out.println();
System.out.println();
KingFallingItem fallingItem = new KingFallingItem(position, velocity);
Upvotes: 1