package robot;
import javax.swing.*;
public class ROBOT {
public String name;
public double R;
public double theta;
public ROBOT(String is){R=0;theta=0;name=is;}
public ROBOT(String is,double Ri){name=is;R=Ri;theta=0;}
public ROBOT(String is,double Ri,double theta_angle){name=is;R=Ri;theta=theta_angle*Math.PI/180.0;}
public ROBOT(ROBOT r1){name=r1.name;R=r1.R;theta=r1.theta;}
public void Turn_North(){theta=Math.PI/2.0;}
public void Turn_South(){theta=3.0*Math.PI/2.0;}
public void Turn_West(){theta=Math.PI;}
public void Turn_East(){theta=Math.PI;}
public void Turn(double angle){theta+=angle*Math.PI/180.0;}
public void Scroll(){R+=1;}
public void Scroll(double Ri){R+=Ri;}
public void go_back(){R-=1;}
public void go_back(double Ri){R-=Ri;}
public String output(){
String s="------------"+name+"---------------\n";
s+="Cartesian coordinates x = "+R*Math.sin(theta)+" y = "+R*Math.cos(theta)+" \n";
s+="Polar coordinates R = "+R+" Theta angle = "+theta*180/Math.PI+" \n";
return s;
}
public static void main(String[] args) {
ROBOT R2D2=new ROBOT("aRtuDitu");
ROBOT z2=new ROBOT("GOKHAN",1.0,90.0);
ROBOT z3=new ROBOT(R2D2);
String s="";
R2D2.Turn_North();R2D2.Scroll();s+=R2D2.output();
R2D2.Turn_West();R2D2.Scroll(2.0);s+=R2D2.output();
z2.Turn_East();z2.Scroll(3.0);s+=z2.output();
z2.Turn_South();z2.Scroll();s+=z2.output();
s+="Copy Robot z3 : "+z3.output();
JOptionPane.showMessageDialog(null,s, "Robot class test",JOptionPane.PLAIN_MESSAGE);
}
}
Hiç yorum yok:
Yorum Gönder