Practica de Tiempo POO
Enviado por Lukiaa • 24 de Septiembre de 2015 • Práctica o problema • 528 Palabras (3 Páginas) • 126 Visitas
package mypkg;
import java.util.Scanner;
public class TryTiempo {
public static void main(String[] args) {
Scanner dato=new Scanner(System.in);
int hrs,min,sg;
Tiempo tp1=new Tiempo();
Tiempo hr=new Tiempo(0);
Tiempo mts=new Tiempo(0);
Tiempo seg=new Tiempo(0);
System.out.println("Introduzca la hora");
hrs=dato.nextInt();
System.out.println("Introduzca los minutos");
min=dato.nextInt();
System.out.println("Introduzca los segundos:");
sg=dato.nextInt();
hr.setH(hrs);
mts.setM(min);
seg.setS(sg);
System.out.println("0:0:0");
System.out.println(hr.getH()+":00:00");
System.out.println(hr.getH()+":"+mts.getM()+":00");
System.out.println(hr.getH()+":"+mts.getM()+":"+seg.getS());
}
}
package mypkg;
public class Tiempo {
private int m;
private int h;
private int s;
public Tiempo(){
this.m=0;
this.h=0;
this.s=0;
}
Tiempo(int h) {
this.m=0;
this.h=h;
this.s=0;
}
Tiempo(int h, int m, int s) {
this.h=h;
this.m=m;
this.s=s;
}
public int getM() {
return m;
}
public void setM(int m) {
if(m<60)
this.m=m;
else
this.m=0;
}
public int getH() {
return h;
}
public void setH(int h) {
if(h<=24)
this.h=h;
else
this.h=0;
}
public int getS() {
return s;
}
public void setS(int s) {
if(s<60)
...