Commit ac190044 by Angel Zarate

Clock Reloj

parents
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Clock.iml" filepath="$PROJECT_DIR$/Clock.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import java.util.Scanner;
public class Reloj {
int hora;
int minuto;
int segundo;
public Reloj(){//este inicializa
hora=12;
minuto=0;
segundo=0;
}
public Reloj(int hh,int mm,int ss){//constructor de los 3 parametros y recomendable el nombre del parametro,cambia los valores actuales
hora=hh;
minuto=mm;
segundo=ss;
}
public Reloj(int s){//Convertir segundos a horas
hora = s / 3600;
minuto = (s- (3600 * hora)) / 60;
segundo= s - ((hora * 3600) + (minuto * 60));
}
public void setReloj(int s){
hora = s / 3600;
minuto = (s- (3600 * hora)) / 60;
segundo= s - ((hora * 3600) + (minuto * 60));
toString();
System.out.println("[: " + hora + ":" + minuto+ ":" + segundo+"]");
}
public void tick() {
int[] conversion=conversionSegundos(hora,minuto);
int x = conversion[0] + conversion[1] + 1 + segundo;
setReloj(x);
}
public void addReloj(Reloj tipoReloj){
int[] x = conversionSegundos(tipoReloj.hora,tipoReloj.minuto);
int [] c = conversionSegundos(hora,minuto);
int sumaReloj=x[0]+c[0]+x[1]+c[1] + segundo + tipoReloj.segundo;
setReloj(sumaReloj);
}
public void restaReloj(Reloj tipoReloj){
int[] x = conversionSegundos(tipoReloj.hora,tipoReloj.minuto);
int [] c = conversionSegundos(hora,minuto);
//el objeto tipo reloj HI ES A
if(tipoReloj.hora<hora){//hacemos la resta dell relj
int restaReloj= (x[0]-c[0]-x[1]-c[1] - segundo - tipoReloj.segundo) *(-1);
setReloj(restaReloj);
}else{
int restaReloj= (x[0]-c[0]-x[1]-c[1] - segundo - tipoReloj.segundo);
setReloj(restaReloj);
}
}
public int[] conversionSegundos(int h,int m){
int[] Array=new int[2];
Array[0]=h*3600;
Array[1]=m*60;
return Array;
}
public int getHora() {
return hora;
}
public void setHora(int hora) {
this.hora = hora;
}
public int getMinuto() {
return minuto;
}
public void setMinuto(int minuto) {
this.minuto = minuto;
}
public int getSegundo() {
return segundo;
}
public void setSegundo(int segundo) {
this.segundo = segundo;
}
@Override
public String toString() {
return "Reloj{" +
"hh" + hora +
":mm:" + minuto +
"segundo" + segundo +
'}';
}
public static void main(String[] args) {
System.out.println("ingrese");
Scanner teclado = new Scanner(System.in);
int num = teclado.nextInt();
//contructores
Reloj reloj = new Reloj();
System.out.println(reloj);
Reloj reloj2 = new Reloj(19,22,30);
Reloj reloj3 = new Reloj(num);
//metodos
reloj3.restaReloj(reloj);
for (int i = 0; i < 10; i++) {
reloj2.tick();
}
}
}
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Clock.iml" filepath="$PROJECT_DIR$/Clock.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment