Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
Reloj
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yovan Martinez
Reloj
Commits
8412c34f
Commit
8412c34f
authored
Apr 25, 2022
by
Yovan Martinez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finalizado reloj
parents
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
139 additions
and
0 deletions
+139
-0
Reloj.java
+139
-0
No files found.
Reloj.java
0 → 100644
View file @
8412c34f
import
java.math.BigDecimal
;
import
java.time.LocalTime
;
import
java.util.Scanner
;
public
class
Reloj
{
private
int
horas
;
private
int
minutos
;
private
int
segundos
;
public
Reloj
(){
horas
=
12
;
minutos
=
00
;
segundos
=
00
;
}
public
Reloj
(
int
hours
,
int
minutes
,
int
seconds
){
horas
=
hours
;
minutos
=
minutes
;
segundos
=
seconds
;
}
public
Reloj
(
int
seconds
){
horas
=
seconds
/
3600
;
minutos
=
(
seconds
%
3600
)/
60
;
segundos
=
(
seconds
%
60
);
}
public
int
setReloj
(
int
seconds
){
setHoras
((
int
)(
seconds
/
3600
));
setMinutos
((
int
)(
seconds
%
3600
)/
60
);
setSegundos
((
int
)(
seconds
%
60
));
return
seconds
;
}
public
int
getHoras
(){
return
horas
;
}
public
int
getMinutos
(){
return
minutos
;
}
public
int
getSegundos
(){
return
segundos
;
}
public
void
setHoras
(
int
hours
){
if
(
hours
>=
0
&&
hours
<=
23
){
horas
=
hours
;
}
else
{
System
.
out
.
println
(
"Valor en horas invalido"
);
}
}
public
void
setMinutos
(
int
value
){
if
(
value
>=
0
&&
value
<=
59
){
minutos
=
value
;
}
else
{
System
.
out
.
println
(
"Valor en minutos invalido"
);
}
}
public
void
setSegundos
(
int
value
){
if
(
value
>=
0
&&
value
<=
59
){
segundos
=
value
;
}
else
{
System
.
out
.
println
(
"Valor en segundos invalido"
);
}
}
public
int
tick
(){
if
(
segundos
>=
0
&&
segundos
<
59
){
segundos
++;
return
segundos
;
}
else
{
segundos
=
0
;
return
segundos
;
}
}
//Privado ya que solo ayuda a transformar en segundos para evitar conflictos
private
int
toSegundos
(
Reloj
time
){
int
seconds
=
0
;
seconds
=
(
time
.
getHoras
()*(
3600
))
+
(
time
.
getMinutos
()*
60
)
+
time
.
getSegundos
();
return
seconds
;
}
public
void
addReloj
(
Reloj
time
){
int
newTime
=
0
;
newTime
=
(
getHoras
()*
3600
)+(
getMinutos
()*
60
)
+
getSegundos
()
+
(
time
.
getHoras
()*(
3600
))
+
(
time
.
getMinutos
()*
60
)
+
time
.
getSegundos
();
while
(
newTime
>
86400
){
newTime
=
newTime
-
86400
;
}
horas
=
newTime
/
3600
;
minutos
=
(
newTime
%
3600
)/
60
;
segundos
=
(
newTime
%
60
);
}
public
String
toString
(){
String
reloj
=
""
;
reloj
=
"["
+
String
.
valueOf
(
getHoras
())+
":"
+
String
.
valueOf
(
getMinutos
())+
":"
+
String
.
valueOf
(
getSegundos
())+
"]"
;
return
reloj
;
}
public
void
restaReloj
(
Reloj
time
){
int
resta
=
0
;
resta
=
toSegundos
(
time
);
resta
=
(
getHoras
()*
3600
)+(
getMinutos
()*
60
)
+
getSegundos
()
-
((
time
.
getHoras
()*(
3600
))
+
(
time
.
getMinutos
()*
60
)
+
time
.
getSegundos
());
if
(
resta
<
0
){
resta
=
resta
*
-
1
;
}
horas
=
resta
/
3600
;
minutos
=
(
resta
%
3600
)/
60
;
segundos
=
(
resta
%
60
);
}
public
static
void
main
(
String
[]
args
)
{
Reloj
relojUsuario
=
new
Reloj
();
Reloj
relojMaquina
=
new
Reloj
();
Scanner
in
=
new
Scanner
(
System
.
in
);
int
lector
=
0
;
System
.
out
.
print
(
"Por favor ingrese los segundos = "
);
lector
=
Integer
.
parseInt
(
System
.
console
().
readLine
());
relojUsuario
.
setReloj
(
lector
);
System
.
out
.
println
(
lector
+
" Segundos son ="
+
relojUsuario
.
toString
());
relojUsuario
.
tick
();
for
(
int
i
=
0
;
i
<
9
;
i
++)
{
System
.
out
.
println
(
relojUsuario
.
toString
());
relojUsuario
.
tick
();
}
System
.
out
.
println
(
relojUsuario
.
toString
());
relojUsuario
.
addReloj
(
relojMaquina
);
System
.
out
.
println
(
"La suma es = "
+
relojUsuario
.
toString
());
relojUsuario
.
restaReloj
(
relojMaquina
);
System
.
out
.
println
(
"La resta es = "
+
relojUsuario
.
toString
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment