2
I had posted earlier but could not edit, I will try to be clearer this time. I am doing (trying)a code for Fonica account. I have class time, connection and contagion. in the account link class I call a time type (class) field to convert time into minutes and display it by calling the time class a constructor.I also have in the link class another field that returns the minute value. What I would like to do is call both the method that returns me the value, when what returns the minutes, into the condadaligacao class. The point is, I’m having trouble calling these roles, and since I’m a beginner, I don’t even know what I’m doing wrong.
Follow my classes below:
public class Ligacao
{
private String nrOrigem, localOrig, nrDest, localDest;
private float valor;
private Tempo inicio, termino;
public Ligacao(String nrOrigem, String localOrig, String nrDest, String localDest, float valor, Tempo inicio, Tempo termino){
this.nrOrigem=nrOrigem;
this.localOrig=localOrig;
this.nrDest=nrDest;
this.localDest=localDest;
this.valor=valor;
this.inicio=inicio;
this.termino=termino;
}
public String getnrOrigem(){
return nrOrigem;
}
public void setnrOrigem(String numOrigem){
this.nrOrigem=numOrigem;
}
public String getlocalOrig(){
return localOrig;
}
public void setlocalOrig(String localOrigem){
this.localOrig=localOrigem;
}
public String getnrDest(){
return nrDest;
}
public void setnrDest(String numDest){
this.nrDest=numDest;
}
public String getlocalDest(){
return localDest;
}
public void setlocalDest(String localDest){
this.localDest=localDest;
}
public float getvalor(){
return valor;
}
public void setvalor(float valor){
this.valor=valor;
}
public Tempo getinicio(){
return inicio;
}
public Tempo gettermino(){
return termino;
}
public int calcularDuracao(){
int inicioSeg,terminoSeg,durSeg,durMin,resto;
inicioSeg=inicio.tempoEmSegundos();
terminoSeg=termino.tempoEmSegundos();
durSeg=terminoSeg-inicioSeg;
durMin=durSeg/60;
resto=durSeg%2;
if(resto>0){
durMin++;
}
return durMin;
}
public boolean verificaNumero(String numero){
return ((nrOrigem.equals(numero))||(nrDest.equals(numero)));
}
}
public class Tempo
{
private int hora, minuto, segundo;
private float tempoTotal;
public Tempo (int hora, int minuto, int segundo){
this.hora=hora;
this.minuto=minuto;
this.segundo=segundo;
}
public int tempoEmSegundos(){
return hora*3600 + minuto *60 + segundo;
}
public int gethora(){
return this.hora;
}
public void sethora(int hora){
this.hora = hora;
}
public int getminuto(){
return this.minuto;
}
public void setminuto(int minuto){
this.minuto=minuto;
}
public int getsegundo(){
return this.segundo;
}
public void setsegundo(int segundo){
this.segundo=segundo;
}
}
public class ContaTel
{
private int mes, ano, contrato;
private Ligacao[] listaligacoes;
private Tempo inicio,termino;
public ContaTel(int mes,int ano, int contrato, int tamanho){
this.mes=mes;
this.ano=ano;
this.contrato=contrato;
this.listaligacoes = new Ligacao[tamanho];
}
public void setmes(int mes){
this.mes= mes;
}
public int getmes(){
return mes;
}
public void setano(int ano){
this.ano = ano;
}
public int getano(){
return ano;
}
public void setcontrato(int contrato){
this.contrato = contrato;
}
public int getcontrato(){
return contrato;
}
public Ligacao[] getlistaligacoes(){
return this.listaligacoes;
}
public void addligacao(Ligacao lig){
int i=0;
for(i=0;i<listaligacoes.length;i++){
if (listaligacoes[i]==null){
listaligacoes[i]=lig;
break;
}
else {
break;
}
}
}
I don’t want the answer, I want to learn, I’ve been at it all day.
With modeling you say code identation? if yes, where can I see more about standardization? And thank you so much for the answer!
– Marcela Braga
@Marcelabraga modeling, is what you did. You created a class
ContaTel
that there could be more than one connection, and that the connection depended on a Time to exist. You created the "rules". However, there are some holes... Like... the Contactel class has no reason to have the Time attribute. This Time is part of the link and not the account. Got it?– Andrei Coelho
@Marcelabraga research about UML and class diagram.
– Andrei Coelho
Okay, anyway, I’m trying and it’s returning me an exception here: java.lang.Nullpointerexception At contactel.valorConta(Contactel.java:52)
– Marcela Braga
@Marcelabraga ai is already another problem! But you can already access the functions. Search about this error in google.
– Andrei Coelho