Little_star Posted December 19, 2009 at 06:50 PM Report Share #301455 Posted December 19, 2009 at 06:50 PM boas. tenho uma programa que preciso de ver se dadas 2 tarefas, elas ficam sobrepostas uma à outra. o meu problema é que quando vou o código é executado em vez de ir ate 59m e dps mudar de hora vai só ate 30m e muda a hora e no minuto seguinte vai ate 29m e muda a hora. public class tarefa{ public static void main(String[] args){ tarefa t1 = new tarefa(new Tempo(13, 30),new Tempo(14, 30)); tarefa t2 = new tarefa(new Tempo(14, 00),new Tempo(15, 30)); tarefa t3 = new tarefa(new Tempo(15, 00),new Tempo(16, 30)); boolean intersect1 = t1.intersecta(t2); System.out.println(intersect1); boolean intersect2 = t1.intersecta(t3); System.out.println(intersect2); } private Tempo i=null; private Tempo f=null; public tarefa (Tempo inicio,Tempo fim){ i=inicio; f=fim; } public String toString(){ StringBuilder sb = new StringBuilder(); sb.append("a tarefa comeca as"); sb.append(i); sb.append("e acaba as"); sb.append(f); return sb.toString(); } public boolean intersecta (tarefa t){ int ih=i.getHora(); int im=i.getMinuto(); int fh=f.getHora(); int fm=f.getMinuto(); int iht=t.i.getHora(); int imt=t.i.getMinuto(); int fht=t.f.getHora(); int fmt=t.f.getMinuto(); int h=ih; int m=im; while(h!=fh && m!=fm){ if(h==iht && m == imt) return true; m++; if(m>59){ h++; m=0; if( h>=24) h=0; } } h=iht; m=imt; while(h!=fht && m!=fmt){ if(h==ih && m == im) return true; m++; if(m>59){ h++; m=0; if( h>=24) h=0; } } se me pudessem explicar o que esta mal neste código eu agradecia é que não entendo por que vai so ate aos 30m. obrigado. Link to comment Share on other sites More sharing options...
bruno1234 Posted December 19, 2009 at 07:01 PM Report Share #301457 Posted December 19, 2009 at 07:01 PM Isso o melhor é fazeres debug passo a passo até encontrares onde está o erro. Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now