Last active
December 12, 2015 06:48
-
-
Save HiroNakamura/4731442 to your computer and use it in GitHub Desktop.
Ejemplos en Ceylon (recopilación), algunos ejemplos ya no funcionan en la nueva versión
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Ejemplos de código en Ceylon (2014)" | |
//47 clases | |
void run(){ | |
Ventana ventana; | |
try{ | |
ventana=Ventana(300,400); | |
ventana.ver(); | |
}catch(Exception ex){ | |
print("Error: ``ex.message`` "); | |
} | |
} | |
shared class Ventana(ancho,alto){ | |
shared Integer ancho; | |
shared Integer alto; | |
if(ancho==0 || alto==0){ | |
throw Exception(); | |
} | |
shared void ver(){print("ancho: ``ancho`` y alto: ``alto`` ");} | |
} | |
//45 classes | |
void run(){ | |
variable Empleado emp; | |
try{ | |
emp=Empleado("Fernando","Carraro","Aguirre"); | |
emp.ver(); | |
print("-----------------------"); | |
emp=Empleado("Mario","Horcasitas","Alvarez"); | |
emp.ver(); | |
print("-----------------------"); | |
emp._nombre="Ignacio"; | |
emp._apellidoPaterno="Torres"; | |
emp._apellidoMaterno="Alcantara"; | |
print("nombre: ``emp._nombre`` "); | |
print("apellido paterno: ``emp._apellidoPaterno`` "); | |
print("apellido materno: ``emp._apellidoMaterno`` "); | |
}catch(Exception ex){ | |
print(ex.message); | |
} | |
} | |
shared class Empleado(variable String nombre,variable String apellidoPaterno,variable String apellidoMaterno){ | |
shared variable String _nombre=""; | |
shared variable String _apellidoPaterno=""; | |
shared variable String _apellidoMaterno=""; | |
shared void ver(){ | |
print("nombre: ``nombre`` "); | |
print("apellido paterno: ``apellidoPaterno`` "); | |
print("apellido materno: ``apellidoMaterno`` "); | |
} | |
} | |
//44 | |
void run(){ | |
print("Version de Ceylon[ ``language.version`` ]\n"); | |
String menu="\t[Menu]\n1. Ver nombre y version del sistema operativo\n2. Calcular no.de pulsaciones de una persona\n3. Salir\nElije opcion:"; | |
while(true){ | |
print(menu); | |
String opc=process.readLine(); | |
switch(opc) | |
case ("1"){ | |
print("Nombre y version del SO"); | |
infoSistema(); | |
} | |
case ("2"){ | |
print("No. de pulsaciones"); | |
print("Introduce edad:"); | |
String edadStr=process.readLine(); | |
Integer? _edad=parseInteger(edadStr); | |
if(exists _edad){ | |
Integer edad=_edad; | |
print("no. pulsaciones: ``pulsaciones(edad)`` "); | |
} | |
} | |
case ("3"){ | |
print("Salida"); | |
process.exit(0); | |
} | |
else { | |
print("Opcion no valida"); | |
} | |
}//fin for | |
} | |
shared Float pulsaciones(Integer edad){ | |
return (220-edad)/15.0; | |
} | |
shared void infoSistema(){ | |
print("sistema: ``operatingSystem.name`` "); | |
print("version del sistema: ``operatingSystem.version`` "); | |
} | |
//43 | |
void run(){ | |
print("Introduce edad:"); | |
String edadStr=process.readLine(); | |
Integer? _edad=parseInteger(edadStr); | |
if(exists _edad){ | |
Integer edad=_edad; | |
print("no. pulsaciones: ``pulsaciones(edad)`` "); | |
} | |
} | |
shared Float pulsaciones(Integer edad){ | |
return (220-edad)/15.0; | |
} | |
//42 switch | |
void run(){ | |
print("\tMenu\n1. Iniciar\n2. Detener\n3. Reiniciar\nTeclea opcion:"); | |
String opcion=process.readLine(); | |
switch(opcion) | |
case ("1"){ | |
print("Iniciando proceso..."); | |
} | |
case ("2"){ | |
print("Deteniendo proceso..."); | |
} | |
case ("3"){ | |
print("Reiniciando proceso..."); | |
} | |
else{ | |
print("no existe esa opcion"); | |
} | |
} | |
//41 | |
void run(){ | |
print("sistema: ``operatingSystem.name`` "); | |
print("version del sistema: ``operatingSystem.version`` "); | |
} | |
//40 introducir datos | |
void run(){ | |
print("Introduce tu nombre: "); | |
String nombreStr=process.readLine(); | |
print("hola ``nombreStr`` "); | |
} | |
//39 for | |
void run(){ | |
String[] nombres=["fer","alma","hortencia","maria dolores"]; | |
for(n in nombres){ | |
print("hola ``n`` "); | |
} | |
} | |
//38 | |
import java.util { Scanner } | |
import java.lang { System { sin=\Iin } } | |
doc "método principal del programa" | |
shared void run(){ | |
Scanner teclado=Scanner(sin); | |
//introducir nombre y edad | |
print("Tu nombre: "); | |
String nombre=teclado.nextLine(); | |
print("Tu edad: "); | |
Integer edad=teclado.nextInt(); | |
//mostramos los datos | |
print("Hola " nombre " tienes " edad " años de edad"); | |
} | |
//37 | |
void run(){ | |
try { | |
if(nonempty args=process.arguments){ | |
for(arg in args){ | |
print(arg); | |
} | |
} | |
} catch (Exception e) { | |
print(e.message); | |
} | |
} | |
//36 manejo de String | |
shared void run() { | |
for (s in [ "😸😾", "noël", "baffle", "abc" ]) { | |
print("*** ``s``"); | |
print("length ``s.size``"); | |
print("reverse ``s.reversed``"); | |
print("tail ``s.rest``"); | |
print("3 chars ``s[0..(min({2, s.size - 1}))]``"); | |
print("upper ``s.uppercased``"); | |
} | |
} | |
//35 paso de parámetros | |
void run() { | |
try { | |
if(nonempty args=process.arguments){ | |
for(arg in args){ | |
print(arg); | |
} | |
} | |
} catch (Exception e) { | |
print(e.message); | |
} | |
} | |
//34 | |
"entrada desde teclado" | |
void run(){ | |
print("Introduce tu nombre: "); | |
String nombre=process.readLine(); | |
print("Hola ``nombre``"); | |
} | |
//33 | |
void run(){ | |
Ejemplo e=Ejemplo("String","Fernando"); | |
e.informacion(); | |
Ejemplo e2=Ejemplo("String"); | |
e2.informacion(); | |
} | |
shared class Ejemplo(tipo,String? nombre=null){ | |
shared String tipo; | |
shared void informacion(){ | |
if(exists nombre){ | |
print("Hola ``nombre`` la cadena es de tipo ``tipo``"); | |
}else{ | |
print("la cadena es de tipo ``tipo``"); | |
} | |
} | |
} | |
//32 for var in coleccion/vector/lista | |
"Esto es un comentario" | |
void run(){ | |
String[] palabras=["1","2","3"]; | |
print("Palabras:"); | |
for(p in palabras){ | |
if(p == "1"){ | |
print("ha aparecido el numero ``p`` "); | |
}else{ | |
print("Hola: ``p``"); | |
} | |
} | |
Integer[] numeros=[1,2,3,4]; | |
print("Numeros:"); | |
for(n in numeros){ | |
if(n==2){ | |
print("ha aparecido el numero ``n``"); | |
}else{ | |
print("Hola: ``n``"); | |
} | |
} | |
value valores=[1,2,3,4,5]; | |
print({for(v in valores) v}); | |
print({for(v in valores) if(v==3) v}); | |
print({for(v in valores) if(v!=3) v}); | |
ver(numeros); | |
} | |
"funcion" | |
shared void ver(Integer[] vect){ | |
for(v in vect){ | |
print(v); | |
} | |
} | |
//31 ejemplo de clase | |
void run(){ | |
print(Ejemplo("123","Fer").informacion); | |
print(Ejemplo("123").informacion); | |
} | |
shared class Ejemplo(tipo, String? nombre=null){ | |
shared String tipo; | |
shared String informacion{ | |
if(exists nombre){ | |
return nombre; | |
}else{ | |
return "es de tipo: ``tipo`` "; | |
} | |
} | |
} | |
//30 ejemplo de clase | |
void run(){ | |
print(Ejemplo("123","Fer").informacion); | |
print(Ejemplo("123",null).informacion); | |
} | |
shared class Ejemplo(tipo, String? nombre){ | |
shared String tipo; | |
shared String informacion{ | |
if(exists nombre){ | |
return nombre; | |
}else{ | |
return "es de tipo: ``tipo`` "; | |
} | |
} | |
} | |
//29 ejemplo de clase | |
void run(){ | |
String nombre="Fer"; | |
Integer edad=31; | |
Float peso=45.0; | |
Ejemplo fer=Ejemplo(nombre,edad,peso); | |
print("Hola ``fer.getNombre()`` tienes ``fer.getEdad()`` anyos de edad"); | |
print("pesas ``fer.getPeso()`` kg"); | |
} | |
shared class Ejemplo(String nombre, Integer edad,Float peso){ | |
shared String getNombre(){ | |
return nombre; | |
} | |
shared Integer getEdad(){ | |
return edad; | |
} | |
shared Float getPeso(){ | |
return peso; | |
} | |
} | |
//28 Ejemplo de clase | |
void run(){ | |
Ejemplo fer=Ejemplo("Fernando",31,45.0); | |
print("Hola ``fer.getNombre()`` tienes ``fer.getEdad()`` anyos de edad"); | |
print("pesas ``fer.getPeso()`` kg"); | |
} | |
shared class Ejemplo(String nombre, Integer edad,Float peso){ | |
shared String getNombre(){ | |
return nombre; | |
} | |
shared Integer getEdad(){ | |
return edad; | |
} | |
shared Float getPeso(){ | |
return peso; | |
} | |
} | |
// 27 Ejemplo de clase | |
void run(){ | |
Ejemplo fer=Ejemplo(); | |
print("Hola ``fer.nombre`` tienes ``fer.edad`` anyos de edad"); | |
print("pesas ``fer.peso`` kg"); | |
} | |
shared class Ejemplo(){ | |
shared String nombre="Fernando"; | |
shared Integer edad=31; | |
shared Float peso=45.0; | |
} | |
//-------------------------------------------------------------------- | |
// estos para versión pasada de Ceylon | |
doc "Ejemplos sencillos" | |
by "yo" | |
//26 uso de clases y paso de parametros | |
void run(){ | |
variable Integer cont=0; | |
if (nonempty args=process.arguments) { | |
for (arg in args) { | |
Prueba p=Prueba(arg); | |
print(p.getUsuario()); | |
cont=cont+1; | |
} | |
print("no. de parametros: ``cont``"); | |
} | |
else { | |
print("No hay nada que evaluar"); | |
} | |
} | |
shared class Prueba(String usuario){ | |
shared String getUsuario(){ | |
return "Hola ``usuario``"; | |
} | |
} | |
//25 paso de parametros | |
void run(){ | |
if (nonempty args=process.arguments) { | |
for (arg in args) { | |
print("Hola ``arg``"); | |
} | |
} | |
else { | |
print("No hay nada que evaluar"); | |
} | |
} | |
//24 uso de clases | |
void run(){ | |
Prueba p=Prueba("Fernando"); | |
print(p.getUsuario()); | |
} | |
shared class Prueba(String usuario){ | |
shared String getUsuario(){ | |
return "Hola ``usuario``"; | |
} | |
} | |
//23 uso de process | |
void run(){ | |
print("sistema operativo: ``process.os``"); | |
print("version sistema operativo: ``process.osVersion``"); | |
print("maquina virtual: ``process.vm``"); | |
print("version maquina virtual: ``process.vmVersion``"); | |
} | |
//22 otro de clases | |
shared class Persona(String nombre,Integer edad){ | |
shared String toString(){ | |
return "Persona(nombre: "+nombre.string+", edad: "+edad.string+")"; | |
} | |
} | |
void run(){ | |
Persona persona=Persona("Fernando",31); | |
print(" ``persona.toString()``"); | |
} | |
//21 uso de process | |
void run(){ | |
print("sistema operativo: ``process.os``"); | |
print("version sistema operativo: ``process.osVersion``"); | |
print("maquina virtual: ``process.vm``"); | |
print("version maquina virtual: ``process.vmVersion``"); | |
} | |
//20 process.readLine() | |
void run(){ | |
variable Integer cont=0; | |
variable Float suma=0.0; | |
variable Float promedio=0.0; | |
print("no. de materias:"); | |
value numero=parseInteger(process.readLine()); | |
if(exists numero){ | |
Integer maximo=numero; | |
for(n in 1..maximo){ | |
print("calf. no. ``n`` : "); | |
value calf=parseFloat(process.readLine()); | |
if(exists calf){ | |
Float calff=calf; | |
suma=suma+calff; | |
}//fin if | |
}//fin for | |
promedio=suma/maximo; | |
print("promedio: ``promedio`` "); | |
}//fin if | |
} | |
//19 IMC | |
void run(){ | |
print("Tu peso:"); | |
value pesoStr=process.readLine(); | |
value _peso=parseFloat(pesoStr); | |
print("Tu talla:"); | |
value tallaStr=process.readLine(); | |
value _talla=parseFloat(tallaStr); | |
if (exists _peso, exists _talla) { | |
Float peso=_peso; | |
Float talla=_talla; | |
value imc=Imc(peso,talla); | |
print("tu imc es de: ``imc.calculo()``"); | |
} | |
} | |
shared class Imc(Float peso, Float talla){ | |
shared Float calculo(){ | |
return peso/(talla*talla); | |
} | |
} | |
//18 uso de for | |
void run(){ | |
for(n in 0..12){ | |
print("hola no. ``n``"); | |
} | |
} | |
//17 funciona, pulsaciones | |
void run(){ | |
print("Age: "); | |
String ageStr=process.readLine(); | |
Integer? age=parseInteger(ageStr); | |
if(exists age){ | |
print("You have ``age`` years"); | |
Integer edad=age; | |
Ejemplo ejemplo=Ejemplo(edad); | |
print("result: ``ejemplo.pulsaciones()``"); | |
} | |
//assert (exists age) or if (exists age) | |
} | |
shared class Ejemplo(Integer age){ | |
shared Float pulsaciones(){ | |
return (220.0-age)/15.0; | |
} | |
} | |
//16 obtener IMC, funciona | |
void run(){ | |
print("Nombre:"); | |
String nombre=process.readLine(); | |
print("Edad:"); | |
String edadStr=process.readLine(); | |
Integer? _edad=parseInteger(edadStr); | |
print("Peso:"); | |
String pesoStr=process.readLine(); | |
Float? _peso=parseFloat(pesoStr); | |
print("talla:"); | |
String tallaStr=process.readLine(); | |
Float? _talla=parseFloat(tallaStr); | |
if(exists _edad){ | |
Integer edad=_edad; | |
if(exists _peso){ | |
Float peso=_peso; | |
if(exists _talla){ | |
Float talla=_talla; | |
Persona persona=Persona(nombre,edad,peso,talla); | |
persona.ver(); | |
} | |
} | |
} | |
} | |
shared class Persona(String nombre,Integer edad,Float peso,Float talla){ | |
shared Float imc(){ | |
return peso/(talla*talla); | |
} | |
shared void ver(){ | |
print("Hola ``nombre`` tienes ``edad`` anyos , pesas ``peso`` kg y mides ``talla`` mts"); | |
print("Tu IMC es de: ``imc()`` tu clasificacion: ``clasificacion()``"); | |
} | |
shared String clasificacion(){ | |
variable String cad=""; | |
if(imc()<16.00){ | |
cad="Infrapeso: Delgadez Severa"; | |
}else if(imc()<=16.00 || imc()<=16.99){ | |
cad="Infrapeso: Delgadez moderada"; | |
}else if(imc()<=17.00 ||imc()<=18.49){ | |
cad="Infrapeso: Delgadez aceptable"; | |
}else if(imc()<=18.50 || imc()<=24.99){ | |
cad="Peso Normal"; | |
}else if(imc()<=25.00 || imc()<=29.99){ | |
cad="Sobrepeso"; | |
}else if(imc()<=30.00 || imc()<=34.99){ | |
cad="Obeso: Tipo I"; | |
}else if(imc()<=35.00 || imc()<=40.00){ | |
cad="Obeso: Tipo II"; | |
}else if(imc()>=40.00){ | |
cad="Obeso: Tipo III"; | |
}else{ | |
cad="no existe clasificacion"; | |
} | |
return cad; | |
} | |
} | |
//15 obtener IMC | |
void run(){ | |
Persona persona=Persona("Horacio",36,60.0,1.65); | |
persona.ver(); | |
} | |
shared class Persona(String nombre,Integer edad,Float peso,Float talla){ | |
shared Float imc(){ | |
return peso/(talla*talla); | |
} | |
shared void ver(){ | |
print("Hola ``nombre`` tienes ``edad`` , pesas ``peso`` y mides ``talla``"); | |
print("Tu IMC es de: ``imc()`` tu clasificacion: ``clasificacion()``"); | |
} | |
shared String clasificacion(){ | |
variable String cad=""; | |
if(imc()<16.00){ | |
cad="Infrapeso: Delgadez Severa"; | |
}else if(imc()<=16.00 || imc()<=16.99){ | |
cad="Infrapeso: Delgadez moderada"; | |
}else if(imc()<=17.00 ||imc()<=18.49){ | |
cad="Infrapeso: Delgadez aceptable"; | |
}else if(imc()<=18.50 || imc()<=24.99){ | |
cad="Peso Normal"; | |
}else if(imc()<=25.00 || imc()<=29.99){ | |
cad="Sobrepeso"; | |
}else if(imc()<=30.00 || imc()<=34.99){ | |
cad="Obeso: Tipo I"; | |
}else if(imc()<=35.00 || imc()<=40.00){ | |
cad="Obeso: Tipo II"; | |
}else if(imc()>=40.00){ | |
cad="Obeso: Tipo III"; | |
}else{ | |
cad="no existe clasificacion"; | |
} | |
return cad; | |
} | |
} | |
//14 uso de funciones | |
void run(){ | |
String nombre="Fernando"; | |
Integer edad=31; | |
Float peso=45.0; | |
Float talla=1.55; | |
print("Hola ``nombre `` tienes ``edad`` anyos , tu imc es de ``imc(peso,talla)``"); | |
} | |
shared Float imc(Float peso, Float talla){ | |
return peso/(talla*talla); | |
} | |
//13 uso de for | |
void run(){ | |
Integer[] valores=[3,300,2,11,0,43,21]; | |
for(v in valores){ | |
print("hola no. ``v``"); | |
} | |
value cincos = { for (i in valores) if (i%5==0) i }; | |
for (i in cincos) { | |
print(i); | |
} | |
value val= { for (i in 1..10) i }; | |
for(v in val){ | |
print(v); | |
} | |
} | |
//12 paso de parametros | |
doc "ejemplo de paso de parametros" | |
by "Fer" | |
void run(){ | |
if (nonempty args=process.arguments) { | |
for (arg in args) { | |
print(arg); | |
} | |
} | |
} | |
//11 uso de process.readLine() y parseInteger(str) | |
doc "ejemplo" | |
by "yo" | |
void run(){ | |
print("Nombre:"); | |
String nombre=process.readLine(); | |
print("Edad:"); | |
String edadStr=process.readLine(); | |
Integer? edad=parseInteger(edadStr); | |
print("Hola, `` nombre ``"); | |
print("tienes `` edadStr `` de edad"); | |
} | |
//10 paso de argumentos | |
doc "método principal del programa" | |
by "yo" | |
shared void run(){ | |
if (nonempty args=process.arguments) { | |
for (arg in args) { | |
ver(arg); | |
} | |
}else{ | |
print("Mis mas sinceras disculpas si no queda al 100 % satisfecho con el codigo"); | |
} | |
} | |
shared void ver(String nombre){ | |
print("Hola, `` nombre ``"); | |
} | |
//9 uso de Sequence | |
doc "main del programa" | |
by "yo" | |
void run(){ | |
Sequence<String?> valores={"java","ceylon",null,"python","",null}; | |
ver(valores); | |
} | |
void ver(Sequence<String?> cad){ | |
for(c in cad){ | |
if(exists c){ | |
print("longitud: " c.size ""); | |
}else{ | |
print("no existe"); | |
} | |
} | |
} | |
//8 importar librerías Java | |
import java.util { Scanner } | |
import java.lang { System { sin=\Iin } } | |
doc "main del programa" | |
by "yo" | |
void run(){ | |
Scanner s=Scanner(sin); | |
print("tu nombre: "); | |
String? nombre=s.nextLine(); | |
if(exists nombre){ | |
print("longitud: " nombre.size ""); | |
}else{ | |
print("no existe"); | |
} | |
} | |
//7 | |
doc "main del programa" | |
by "yo" | |
void run(){ | |
print("celsius: " celsius(12.0) ""); | |
print("fahrenheit: " fahrenheit(12.0) ""); | |
} | |
Float celsius(Float f){ | |
return (f-32)/1.8; | |
} | |
Float fahrenheit(Float c){ | |
return (1.8*c)+32; | |
} | |
//6 uso de comprehensiones | |
doc "main del programa" | |
by "yo" | |
void run(){ | |
print({for (w in {"hello", "world"}) for (c in w) if (c in "aeiou") c.uppercased}); | |
print({for(a in {"HOLA","MUNDO"})for(i in a) if(i in "AEIOU") i.lowercased}); | |
} | |
//5 uso de clases | |
doc "main del programa" | |
by "yo" | |
void run(){ | |
value persona=Persona("Hiro",31,45.0,1.55); | |
ver(persona); | |
value servicio=Servicio(persona); | |
verPulsaciones(servicio); | |
verImc(servicio); | |
} | |
doc "metodo para ver datos" | |
void ver(Persona p){ | |
print("Hola " p.getNombre() ""); | |
print("tienes " p.getEdad() " de edad"); | |
print("pesas " p.getPeso() " kg"); | |
print("tienes " p.getTalla() " mts. de estatura"); | |
} | |
doc "ver resultado pulsaciones" | |
void verPulsaciones(Servicio serv){ | |
print("no. de pulsaciones: " serv.pulsaciones() ""); | |
} | |
doc "ver imc" | |
void verImc(Servicio serv){ | |
print("imc obtenido es: " serv.imc() ""); | |
print("status: " serv.interpretacion() ""); | |
} | |
shared class Persona(String nombre, Integer edad,Float peso, Float talla){ | |
shared String getNombre(){ | |
return nombre; | |
} | |
shared Integer getEdad(){ | |
return edad; | |
} | |
shared Float getPeso(){ | |
return peso; | |
} | |
shared Float getTalla(){ | |
return talla; | |
} | |
} | |
shared class Servicio(Persona p){ | |
shared Float pulsaciones(){ | |
return (220.0-p.getEdad())/10.0; | |
} | |
shared Float imc(){ | |
return p.getPeso()/(p.getTalla()*p.getTalla()); | |
} | |
shared String interpretacion(){ | |
variable String cad:=""; | |
if(imc()<16.0){ | |
cad:="Infrapeso: Delgadez Severa"; | |
}else if(imc()<=16.0 || imc()<=16.9){ | |
cad:="Infrapeso: Delgadez moderada"; | |
}else if(imc()<=17.0 ||imc()<=18.4){ | |
cad:="Infrapeso: Delgadez aceptable"; | |
}else if(imc()<=18.5 || imc()<=24.9){ | |
cad:="Peso Normal"; | |
}else if(imc()<=25.0 || imc()<=29.9){ | |
cad:="Sobrepeso"; | |
}else if(imc()<=30.0 || imc()<=34.9){ | |
cad:="Obeso: Tipo I"; | |
}else if(imc()<=35.0 || imc()<=40.0){ | |
cad:="Obeso: Tipo III"; | |
}else{ | |
cad:="no existe clasificacion "; | |
} | |
return cad; | |
} | |
} | |
//4 importar librerías | |
import java.util { Date } | |
doc "main" | |
by "yo" | |
void run(){ | |
value serv=Servicio("Servicio comun"); | |
serv.fecha(); | |
print("nombre: " serv.getNombre() ""); | |
print("Clase-->" className(serv) " !"); | |
value p=Prueba(); | |
ver(p); | |
} | |
void ver(Prueba p){ | |
print("" p.getCadena() ""); | |
} | |
shared class Servicio(String nombre){ | |
shared void fecha(){ | |
value fecha=Date(); | |
print("hoy es " fecha.toLocaleString() ""); | |
} | |
shared String getNombre(){ | |
return nombre; | |
} | |
} | |
shared class Prueba(){ | |
shared String getCadena(){ | |
return "una prueba de cadenas"; | |
} | |
} | |
//3 importar librerías | |
import java.lang { System { propiedades=properties } } | |
//import java.io { File } | |
doc "main del programa" | |
void run(){ | |
Servicio serv=Servicio(); | |
serv.getUsuario(); | |
serv.getOS(); | |
serv.getarch(); | |
serv.fecha(); | |
print("Hola " className(serv) " bienvenido"); | |
//serv.listHomeDir(); | |
} | |
shared class Servicio(){ | |
//http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html | |
shared void getUsuario(){ | |
print("Hola " propiedades.getProperty("user.name") " bienvenido"); | |
} | |
shared void getOS(){ | |
print("usas " propiedades.getProperty("os.name") " "); | |
} | |
shared void getarch(){ | |
print("arquitectura " propiedades.getProperty("os.arch") " "); | |
} | |
shared void fecha(){ | |
value fecha=Date(); | |
print("hoy es " fecha.toLocaleString() ""); | |
} | |
/* | |
http://in.relation.to/Bloggers/Gavin | |
shared void listHomeDir() { | |
for (file in File(propiedades.getProperty("user.home")).listFiles()) { | |
//print(file.canonicalPath); | |
print(file.getCanonicalPath()); | |
} | |
}*/ | |
} | |
//2 uso de Scanner de Java | |
import java.util { Scanner } | |
import java.lang { System { sin=\Iin } } | |
doc "main del programa" | |
by "yo" | |
void run(){ | |
Scanner s=Scanner(sin); | |
print("Introduce valor: "); | |
Float valor=s.nextFloat(); | |
print("Introduce interes: "); | |
Float interes=s.nextFloat(); | |
print("Introduce plazo: "); | |
Integer plazo=s.nextInt(); | |
for(p in 0..plazo){ | |
print("valor futuro : " vf(valor,interes,p) " periodo no. " p " "); | |
} | |
} | |
shared Float vf(Float valor,Float interes,Integer plazo){ | |
return valor*((1+interes/100)**plazo); | |
} | |
//1 uso de Scanner de Java | |
import java.util { Scanner } | |
import java.lang { System { sin=\Iin } } | |
doc "main del programa" | |
void run(){ | |
Scanner s=Scanner(sin); | |
print("Introduce valor: "); | |
Float valor=s.nextFloat(); | |
print("Introduce interes: "); | |
Float interes=s.nextFloat(); | |
print("Introduce plazo: "); | |
Integer plazo=s.nextInt(); | |
print("valor futuro : " vf(valor,interes,plazo) " "); | |
} | |
shared Float vf(Float valor,Float interes,Integer plazo){ | |
return valor*((1+interes/100)**plazo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment