class robot:
def __init__(self, length = 20.0):
self.x = 0.0
self.y = 0.0
self.orientation = 0.0
self.length = length
self.steering_noise = 0.0
self.distance_noise = 0.0
self.steering_drift = 0.0
def set(self, new_x, new_y, new_orientation):
self.x = float(new_x)
self.y = float(new_y)
self.orientation = float(new_orientation) % (2.0 * pi)
def set_noise(self, new_s_noise, new_d_noise):
self.steering_noise = float(new_s_noise)
self.distance_noise = float(new_d_noise)
def set_steering_drift(self, drift):
self.steering_drift = drift
def move(self, steering, distance,
tolerance = 0.001, max_steering_angle = pi / 4.0):
if steering > max_steering_angle:
steering = max_steering_angle
if steering < max_
steering_angle:
steering = max_
steering_angle
if distance < 0.0:
distance = 0.0
# make a new copy
res = robot()
res.length = self.length
res.steering_noise = self.steering_noise
res.distance_noise = self.distance_noise
res.steering_drift = self.steering_drift

I try to convert it in Java. This is my java code but not sure it is right approch or not

public class Robot1 {
    double length = 20.0;
    double x = 0.0;
    double y = 0.0;
    double orientation = 0.0;
    Robot1.length = length;//Not working
    double steering_noise = 0.0;
    double distance_noise = 0.0;
    double steering_drift = 0.0;

    void set(float new_x, float new_y, float new_orientation) {
        x = new_x;
        y = new_y;
        orientation = new_orientation;
    }

    void set_noise(double s_noise, double d_noise) {
        steering_noise = s_noise;
        distance_noise = d_noise;
    }

    void set_steering_drift(double drift) {
        steering_drift = drift;
    }
    void move(double steering,double distance,double tolerance,double max_steering_angle){
    tolerance=0.01;
    max_steering_angle=3.14/4.0;
    if(steering>max_steering_angle){
        steering=max_steering_angle;
    }
    if(steering<-max_steering_angle){
        steering=-max_steering_angle;
    }
    if(distance<0.0){
        distance=0.0;
    }
    }
    public static void main(String [] args){
        Robot1 res;//Not working
        res.length=20.0;//Not working
    }
}

Please help me to convert it ...

Please take care to post in the appropriate forum.

I speak Java but not Python, so I don't understand all the original code, but looking at the Java in its own right...
it looks like you should remove line 6 and write your main as

    public static void main(String [] args){
        Robot1 res = new Robot1(); // need to explicity create an instance of Robot1
        res.length=20.0;   // this should now be OK because
                                                     // res refers to a valid instance of Robot1
        // now you can call res.set..., res.move... etc
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.