GoConqr has a new look! Let us know what you think.

Notes

Untitled

ANGUE LIZETH LUQUE MAMANI English 2 pages

Content of the notes (2)

Page 1

Page 2

main.java

public class Main { public static void main(String[] args){ TIEMPO TIEMPO1 = new TIEMPO(); TIEMPO1.setTiempo (13,50,5); System.out.println("hora en el sistema de 24 horas"); System.out.println("Hora: "+TIEMPO1.formato24h()); System.out.println(); System.out.println("hora en el sistema de 12 horas"); System.out.println(TIEMPO1.formato12h()); } }

tiempo.java

public class TIEMPO { private int hora; private int minuto; private int segundo; public void setTiempo (int hora, int minuto, int segundo) { if (hora<0 || hora>=24 || minuto<0 || minuto>=60 || segundo<0 || segundo>=60) throw new IllegalArgumentException(); this.hora=hora; this.minuto=minuto; this.segundo=segundo; } //metodo que muestra la hora en el sistema de 24h public String formato24h(){ return String.format("%02d:%02d:%02d", hora,minuto,segundo); } //metodo que muestra la hora en el sistema de 12h public String formato12h(){ return String.format("%d:%02d:%02d %s",((hora==0 || hora==12)?12 : hora%12),minuto,segundo,(hora<12 ? "AM" : "PM" )); } }

Information

Description
Note on Untitled, created by ANGUE LIZETH LUQUE MAMANI on 01/04/2024.
Views
0
Rating

More on Clases y objetos

Feedback

What is it about?

What do you think of the new look?

How do you like it?