Jump to content

programa para verificar se uma tarefa fica ao mesmo tempo de outro


Little_star
 Share

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.