La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

Suponiendo que además en la clase U hay: import java.util.*; class U{ static Scanner teclado = new Scanner(System.in); static public int readInt(String.

Presentaciones similares


Presentación del tema: "Suponiendo que además en la clase U hay: import java.util.*; class U{ static Scanner teclado = new Scanner(System.in); static public int readInt(String."— Transcripción de la presentación:

1

2 Suponiendo que además en la clase U hay: import java.util.*; class U{ static Scanner teclado = new Scanner(System.in); static public int readInt(String x) { println(x); return readInt(); } static public double readDouble(String x) { println(x); return teclado.nextDouble(); } static public void print(String x){ System.out.print(x); } static public void println(String x){ System.out.println(x); } static public String readLine(String x) { println(x); return teclado.nextLine(); }

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20 Implementar la clase Tiempo de modo que se pueda programar el siguiente diálogo Primer tiempo (HHMMSS) ? 013040 Segundo tiempo (HHMMSS) ? 104530 Mayor = 10:45:30 Menor = 01:30:40 Suma = 12:16:10 Resta = 09:14:50 class T { public static void main(String[] args) { Tiempo t1 = new Tiempo(C.readInt(“Primer instante(HHMMSS)?“)); Tiempo t2 = new Tiempo(C.readInt(“Segundo instante(HHMMSS)?”); Tiempo t3 = t1.suma(t2); System.out.print(“Suma=”+t3.toString()); if (t1.compareTo(t2) > 0){ mayor = t1; menor = t2; } else { mayor = t2; menor = t1; } U.println(“Mayor=“+mayor.toString()); U.println(“Menor=”+menor.tostring()); U.print(“Suma = “+(t1.suma(t2)).toString()+” Resta=”+(t1.resta(t2)).toString()); }

21 Esqueleto de la clase Tiempo: class Tiempo { int segundos; //conviene guardar el total de segundos no mas Tiempo (String x) { //construcctor que recibe un string de parámetro } public int compareTo(Tiempo x) { // retorna un entero 0 según si x es mayor igual o menor } public Tiempo suma(Tiempo x) { //retorna un objeto tiempo nuevo con la suma } public Tiempo resta(Tiempo x) { //retorna un objeto tiempo nuevo con la resta } public String toString() { //retorna un string “HH:MM:SS” }


Descargar ppt "Suponiendo que además en la clase U hay: import java.util.*; class U{ static Scanner teclado = new Scanner(System.in); static public int readInt(String."

Presentaciones similares


Anuncios Google