Skip to content
Snippets Groups Projects
Commit 05f8e7e7 authored by DALI AYOUB's avatar DALI AYOUB :speech_balloon:
Browse files

tp java

parents 37628dfd 2aaa8da9
Branches
No related merge requests found
public class SexDec {
private double dec;
public SexDec(double heureDec) {
this.dec = heureDec;
}
public double getDec() {
return dec;
}
public SexDec(int heure, int mn, int sec) {
this.dec = heure + (mn + sec / 60.0) / 60.0;
}
public int getH() {
int heure = (int) dec;
return heure;
}
public int getM() {
int heure = getH();
int mn = (int) ((dec - heure) * 60);
return mn;
}
public int getS() {
int heure = getH();
int mn = getM();
int sec = (int) ((dec - heure - mn / 60.0) * 3600);
return sec;
}
}
\ No newline at end of file
import java.text.DecimalFormat;
public class TestSexDec{
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("0.00");
SexDec h1 = new SexDec(4.51);
System.out.println("h1 - decimal = " + df.format(h1.getDec()) + " Sexa = " + h1.getH() + ":" + h1.getM() + ":" + h1.getS());
SexDec h2 = new SexDec(2, 32, 15);
System.out.println("h2 - decimal = " + df.format(h2.getDec()) + " Sexa = " + h2.getH() + ":" + h2.getM() + ":" + h2.getS());
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment