PEP 8 : Maximum line Length :
Roy Smith
roy at panix.com
Sat May 17 09:46:43 EDT 2014
In article <mailman.10085.1400333338.18130.python-list at python.org>,
Tim Chase <python.list at tim.thechases.com> wrote:
> On 2014-05-17 12:52, Albert van der Horst wrote:
> > Now translate E=mc^2 into Java.
>
> I suspect it would be something like
>
> public class Einstein {
> private double mass=0, energy=0;
> public class Relativity implements IEquation {
> Relativity(double mass) {
> set_mass(mass);
> }
> public double getEnergy() {return energy;}
> public double setEnergy(double newEnergy) {
> energy = newEnergy;
> mass = newEnergy / (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT);
> }
> public double get_mass() {return mass;}
> public double setMass(double newMass) {
> mass = newMass;
> energy = newMass * (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT);
> }
> }
>
> public static void main(String[] args) {
> Relativity relativity = new Relativity(
> Integer.parseInt(args[1])
> );
> System.out.println(relativity.getEnergy())
> }
> }
>
>
> (untested, as it has been a long time since I've touched any Java code)
>
> -tkc
Not good enough. Einstein should really be a singleton, so you need
something like an AbstractScientistFactory, which implements Singleton.
And you really should be importing
SPEED_OF_LIGHT_IN_VACUUM_METERS_PER_SECOND from
org.universe.physics.constants. And you need to declare that
Einstein.getEnergy() raises NumericValueOutOfBoundsError if mass is
negative (and FlatEarthError if the code is run in certain states south
of the Mason-Dixie line).
More information about the Python-list
mailing list