Beste mensen,
Ben bezig geweest met een project voor school waarbij ik het bewegen van een biljartbal
over het speelveld beschrijf. Ik heb een hele class geschreven voor de biljartbal.
Maar ik krijg het niet voor elkaar dat het programma de method gebruikt op de manier die ik wil.
Dat is dus bij elke verplaatsing van 0.1 x de nieuwe y waarde en de nieuwe snelheid berekenen.
Ben nog niet heel ervaren met programmeren dus denk dat ik ergens een grote fout heb gemaakt.
Graag hulp bij het vinden van deze fout.
de error (in de regel: Biljartbal rood = new Biljartbal(0.38,0.12).shoot(15.0, 33.6);) :
incompatible types
required: alfa05.Biljartbal
found: void
-----------------------
bij voorbaat dank
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package alfa05;
/**
*
* @author Manders
*/
public class Alfa05 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
Biljartbal rood = new Biljartbal(0.38,0.12).shoot(15.0, 33.6);
}
class Biljartbal {
double speed = 0.0; //ms^-1
double mass = 0.22; //kg
double radius = 0.036; //m
double Elasticity = 0.99; // on a scale from 0 to 1
double xCoordinate; // length of the playing field
double yCoordinate; // width of the playing field
double direction;
double b; // from: y = ax + b
double s; // distance traveled (m)
double F = 0.2; // force of friction between Ball and surface (N)
//constructor
public Biljartbal(double x, double y) {
x = xCoordinate;
y = yCoordinate;
}
// method
// for a shot
void shoot(double increment, double angle){
direction += angle;
speed += increment;
do {
// calculating the new Coordinates of the ball
// depending on the increasement of the x-Coordinate
do {
b = (yCoordinate - Math.tan(direction) * xCoordinate);
xCoordinate += 0.01;
yCoordinate = (Math.tan(direction) * xCoordinate + b);
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
// calculating the distance traveled by the ball
// .sqrt = square root
// .pow(a,b) = a raised to the power of b
s = Math.sqrt(Math.pow(Math.abs((yCoordinate
- ((xCoordinate - 0.1)
* Math.tan(direction)+ b))), 2.0) +
Math.pow(0.1, 2.0));
// calculating the new speed:
// speed = Math.sqrt(v² - 2*F*s/mass)
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
// new direction when ball hits north or south bumper:
if ( (yCoordinate + radius) >= 1.4225 ||
(yCoordinate - radius) <= 0.0) {
direction = (360.0 - direction);
}
// new direction when ball hits east bumper:
if ( (xCoordinate + radius) >= 2.845 &&
(direction < 90.0) ) {
direction = (180.0 - direction);
}
if ( (xCoordinate + radius) >= 2.845 &&
(direction > 270.0) ) {
direction = (540.0 - direction);
}
} while (direction < 90.0 || direction > 270.0);
do {
b = (yCoordinate - Math.tan(direction) * xCoordinate);
xCoordinate -= 0.01;
yCoordinate = (Math.tan(direction) * xCoordinate + b);
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
// calculating the distance traveled by the ball
// .sqrt = square root
// .pow(a,b) = a raised to the power of b
s = Math.sqrt(Math.pow(Math.abs((yCoordinate -
((xCoordinate + 0.1)
* Math.tan(direction)+ b))), 2.0)
+ Math.pow(0.1, 2.0));
// calculating the new speed:
// speed = Math.sqrt(v² - 2*F*s/mass)
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
//new direction when ball hits north or south bumper
if ( (yCoordinate + radius) >= 1.4225 ||
(yCoordinate - radius) <= 0.0) {
direction = (360.0 - direction);
}
//new direction when ball hits west bumper
if ( (xCoordinate - radius) <= 0.0 &&
(direction > 180.0) ) {
direction = (540.0 - direction);
}
if ( (xCoordinate - radius) <= 0.0 &&
(direction < 180.0) ) {
direction = (180.0 - direction);
}
} while (direction > 90.0 && direction < 270.0 &&
direction != 180.0);
do {
yCoordinate += 0.1;
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
s = 0.1;
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
if ((yCoordinate + radius) >= 1.4225) {
direction = 270.0;
}
} while (direction == 90.0);
do {
yCoordinate -= 0.1;
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
s = 0.1;
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
if ((yCoordinate - radius) <= 0.0) {
direction = 90.0;
}
} while (direction == 270.0);
do {
xCoordinate -= 0.1;
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
s = 0.1;
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
if ((xCoordinate - radius) <= 0.0) {
direction = 0.0;
}
} while (direction == 180.0);
do {
xCoordinate += 0.1;
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
s = 0.1;
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
if ((xCoordinate - radius) <= 0.0) {
direction = 180.0;
}
} while (direction == 0.0);
} while (speed > 0.0);
}
}
class Speelveld {
double length = 2.845; //m
double width = 1.4225; //m
double bumperHeight = 0.036; //m
double bumperElasticity = 0.7; //scale of 0 to 1
//constructor
public Speelveld () {
};
}
Ben bezig geweest met een project voor school waarbij ik het bewegen van een biljartbal
over het speelveld beschrijf. Ik heb een hele class geschreven voor de biljartbal.
Maar ik krijg het niet voor elkaar dat het programma de method gebruikt op de manier die ik wil.
Dat is dus bij elke verplaatsing van 0.1 x de nieuwe y waarde en de nieuwe snelheid berekenen.
Ben nog niet heel ervaren met programmeren dus denk dat ik ergens een grote fout heb gemaakt.
Graag hulp bij het vinden van deze fout.
de error (in de regel: Biljartbal rood = new Biljartbal(0.38,0.12).shoot(15.0, 33.6);) :
incompatible types
required: alfa05.Biljartbal
found: void
-----------------------
bij voorbaat dank
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package alfa05;
/**
*
* @author Manders
*/
public class Alfa05 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
Biljartbal rood = new Biljartbal(0.38,0.12).shoot(15.0, 33.6);
}
class Biljartbal {
double speed = 0.0; //ms^-1
double mass = 0.22; //kg
double radius = 0.036; //m
double Elasticity = 0.99; // on a scale from 0 to 1
double xCoordinate; // length of the playing field
double yCoordinate; // width of the playing field
double direction;
double b; // from: y = ax + b
double s; // distance traveled (m)
double F = 0.2; // force of friction between Ball and surface (N)
//constructor
public Biljartbal(double x, double y) {
x = xCoordinate;
y = yCoordinate;
}
// method
// for a shot
void shoot(double increment, double angle){
direction += angle;
speed += increment;
do {
// calculating the new Coordinates of the ball
// depending on the increasement of the x-Coordinate
do {
b = (yCoordinate - Math.tan(direction) * xCoordinate);
xCoordinate += 0.01;
yCoordinate = (Math.tan(direction) * xCoordinate + b);
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
// calculating the distance traveled by the ball
// .sqrt = square root
// .pow(a,b) = a raised to the power of b
s = Math.sqrt(Math.pow(Math.abs((yCoordinate
- ((xCoordinate - 0.1)
* Math.tan(direction)+ b))), 2.0) +
Math.pow(0.1, 2.0));
// calculating the new speed:
// speed = Math.sqrt(v² - 2*F*s/mass)
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
// new direction when ball hits north or south bumper:
if ( (yCoordinate + radius) >= 1.4225 ||
(yCoordinate - radius) <= 0.0) {
direction = (360.0 - direction);
}
// new direction when ball hits east bumper:
if ( (xCoordinate + radius) >= 2.845 &&
(direction < 90.0) ) {
direction = (180.0 - direction);
}
if ( (xCoordinate + radius) >= 2.845 &&
(direction > 270.0) ) {
direction = (540.0 - direction);
}
} while (direction < 90.0 || direction > 270.0);
do {
b = (yCoordinate - Math.tan(direction) * xCoordinate);
xCoordinate -= 0.01;
yCoordinate = (Math.tan(direction) * xCoordinate + b);
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
// calculating the distance traveled by the ball
// .sqrt = square root
// .pow(a,b) = a raised to the power of b
s = Math.sqrt(Math.pow(Math.abs((yCoordinate -
((xCoordinate + 0.1)
* Math.tan(direction)+ b))), 2.0)
+ Math.pow(0.1, 2.0));
// calculating the new speed:
// speed = Math.sqrt(v² - 2*F*s/mass)
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
//new direction when ball hits north or south bumper
if ( (yCoordinate + radius) >= 1.4225 ||
(yCoordinate - radius) <= 0.0) {
direction = (360.0 - direction);
}
//new direction when ball hits west bumper
if ( (xCoordinate - radius) <= 0.0 &&
(direction > 180.0) ) {
direction = (540.0 - direction);
}
if ( (xCoordinate - radius) <= 0.0 &&
(direction < 180.0) ) {
direction = (180.0 - direction);
}
} while (direction > 90.0 && direction < 270.0 &&
direction != 180.0);
do {
yCoordinate += 0.1;
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
s = 0.1;
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
if ((yCoordinate + radius) >= 1.4225) {
direction = 270.0;
}
} while (direction == 90.0);
do {
yCoordinate -= 0.1;
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
s = 0.1;
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
if ((yCoordinate - radius) <= 0.0) {
direction = 90.0;
}
} while (direction == 270.0);
do {
xCoordinate -= 0.1;
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
s = 0.1;
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
if ((xCoordinate - radius) <= 0.0) {
direction = 0.0;
}
} while (direction == 180.0);
do {
xCoordinate += 0.1;
System.out.println("x: " + xCoordinate +
" y: " + yCoordinate);
s = 0.1;
speed = Math.sqrt(Math.pow(speed, 2.0) - (2.0*F*s/mass));
System.out.println("speed: " + speed);
if ((xCoordinate - radius) <= 0.0) {
direction = 180.0;
}
} while (direction == 0.0);
} while (speed > 0.0);
}
}
class Speelveld {
double length = 2.845; //m
double width = 1.4225; //m
double bumperHeight = 0.036; //m
double bumperElasticity = 0.7; //scale of 0 to 1
//constructor
public Speelveld () {
};
}