PEP 8 : Maximum line Length :

Tim Chase python.list at tim.thechases.com
Sat May 17 09:28:24 EDT 2014


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



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20140517/82ebb3be/attachment.sig>


More information about the Python-list mailing list