Hello all, I was asked by a friend of mine to help him out with a program he needs completed, unlucky for him I have not much experience with it myself.
Wondering how the complete code would look like, or perhaps an easier way to write the whole code for this program.
The idea is that the user inputs x number of months/days/hours/minutes/seconds... and a final array will display all this information in the proper format.
Meaning:
max sec display would be 59 seconds.
Max min display would be 59 minutes.
Max hour display would be 23 hours.
Max day display would be 29 (always assuming every month has 30 days).
Max month display would be 11. If it all happens to exceed the 11 months, then the corresponding number of years would be shown in the array as well.
So here is the code:
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class arreglohras { private String fecha; private int anio; private int mes; private int dia; private int hora; private int min; private int seg; public String getFecha() { return fecha; } public void setFecha(String fecha) { this.fecha = fecha; } public int getAnio() { return anio; } public void setAnio(int anio) { this.anio = anio; } public int getMes() { return mes; } public void setMes(int mes) { this.mes = mes; } public int getDia() { return dia; } public void setDia(int dia) { this.dia = dia; } public int getHora() { return hora; } public void setHora(int hora) { this.hora = hora; } public int getMin() { return min; } public void setMin(int min) { this.min = min; } public int getSeg() { return seg; } public void setSeg(int seg) { this.seg = seg; } public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] arg) throws Exception { arreglo cal1 = new arreglo(); arreglo cal2 = new arreglo(); arreglo cal3 = new arreglo(); System.out.println("Introduce seg:min:horas:dias:meses"); cal1.setFecha(in.readLine()); System.out.println("Introduce seg:min:horas:dias:meses"); cal2.setFecha(in.readLine()); StringTokenizer token; token = new StringTokenizer(cal1.getFecha(), ":"); String uno = token.nextToken(); int numero = Integer.parseInt(uno); cal1.setSeg(numero); cal1.setMin(Integer.parseInt(token.nextToken())); cal1.setHora(Integer.parseInt(token.nextToken())); cal1.setDia(Integer.parseInt(token.nextToken())); cal1.setMes(Integer.parseInt(token.nextToken())); token = new StringTokenizer(cal2.getFecha(), ":"); cal2.setSeg(Integer.parseInt(token.nextToken())); cal2.setMin(Integer.parseInt(token.nextToken())); cal2.setHora(Integer.parseInt(token.nextToken())); cal2.setDia(Integer.parseInt(token.nextToken())); cal2.setMes(Integer.parseInt(token.nextToken())); cal3.setSeg(cal1.getSeg() + cal2.getSeg()); cal3.setMin(cal1.getMin() + cal2.getMin() + cal3.getSeg() / 60); cal3.setHora(cal1.getHora() + cal2.getHora() + cal3.getMin() / 60); cal3.setDia(cal1.getDia() + cal2.getDia() + cal3.getHora() / 24); cal3.setMes(cal1.getMes() + cal2.getMes() + cal3.getDia() / 30); cal3.setAnio(cal3.getMes() / 12); cal3.setSeg(cal3.getSeg() % 60); cal3.setMin(cal3.getMin() % 60); cal3.setHora(cal3.getHora() % 24); cal3.setDia(cal3.getDia() % 30); cal3.setMes(cal3.getMes() % 12); System.out.println("La fecha es:"); System.out.println(cal3.getAnio() + " Aņos "); System.out.println(cal3.getMes() + " Meses "); System.out.println(cal3.getDia() + " Dias "); System.out.println(cal3.getHora() + " Horas "); System.out.println(cal3.getMin() + " Minutos "); System.out.println(cal3.getSeg() + " Segundos "); } }
Here is the error message when compiling:
----jGRASP exec: javac -g arreglohras.java arreglohras.java:61: error: cannot find symbol arreglo cal1 = new arreglo(); ^ symbol: class arreglo location: class arreglohras arreglohras.java:61: error: cannot find symbol arreglo cal1 = new arreglo(); ^ symbol: class arreglo location: class arreglohras arreglohras.java:62: error: cannot find symbol arreglo cal2 = new arreglo(); ^ symbol: class arreglo location: class arreglohras arreglohras.java:62: error: cannot find symbol arreglo cal2 = new arreglo(); ^ symbol: class arreglo location: class arreglohras arreglohras.java:63: error: cannot find symbol arreglo cal3 = new arreglo(); ^ symbol: class arreglo location: class arreglohras arreglohras.java:63: error: cannot find symbol arreglo cal3 = new arreglo(); ^ symbol: class arreglo location: class arreglohras 6 errors ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.