All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Demo.bean.TempConverter.py Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
import java

class TempConverter(java.lang.Object):
	def __init__(self):
		self.setFahrenheit(0.0)

	def setFahrenheit(self, degrees):
		"@sig public void setFahrenheit(double degrees)"
		self.f = degrees
		self.c = (degrees-32.)/1.8

	def getFahrenheit(self):
		"@sig public double getFahrenheit()"
		return self.f

	def setCelsius(self, degrees):
		"@sig public void setCelsius(double degrees)"
		self.c = degrees
		self.f = degrees*1.8+32.

	def getCelsius(self):
		"@sig public double getCelsius()"
		return self.c

	def __repr__(self):
		return '<%.2g degrees fahrenheit == %.2g celsius>' % (self.f, self.c)

if __name__ == '__main__':
	c = TempConverter()
	print c
	c.setCelsius(100)
	print c
	c.setCelsius(0)
	print c
	c.setFahrenheit(212)
	print c




© 2015 - 2024 Weber Informatics LLC | Privacy Policy