diff --git a/Dan.java b/Dan.java new file mode 100644 index 0000000..d5010b2 --- /dev/null +++ b/Dan.java @@ -0,0 +1,31 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package textvježba; + + + +/** + * + * @author Tomislav + */ +public class Dan { + private double pocetakRada; + private double krajRada; + private double brojSatiDana; + + public Dan(String danUMjesecu, double pocetakRada, double krajRada) { + + this.pocetakRada = pocetakRada; + this.krajRada = krajRada; + this.brojSatiDana = krajRada - pocetakRada; + + } + + public String toString(){ + return "" + pocetakRada + "-" + krajRada + " " + + brojSatiDana + "h"; + } +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..faf1cbf --- /dev/null +++ b/Main.java @@ -0,0 +1,34 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package textvježba; + +import java.io.File; +import java.io.IOException; +import java.util.Calendar; +import java.util.GregorianCalendar; + +/** + * + * @author Tomislav + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException{ + + UserInterface ui = new UserInterface(); + Mjesec mjesec = new Mjesec(); + System.out.println(mjesec.dajBrojDana()); + ui.run(); + + + } + + + +} diff --git a/Mjesec.java b/Mjesec.java new file mode 100644 index 0000000..026f186 --- /dev/null +++ b/Mjesec.java @@ -0,0 +1,123 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package textvježba; + +import java.io.File; +import java.io.FileWriter; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; + + +/** + * + * @author Tomislav + */ +public class Mjesec { + + private String mjesec; + private int brojDanaUMjesecu; + private double ukupanBrojSati; + private double zaradeno; + private String path; + Calendar calendar; + Date date = new Date(); + + + public Mjesec() { + calendar = new GregorianCalendar(); + brojDanaUMjesecu = calendar.getActualMaximum(calendar.getTime().getMonth()); + path = "F:" + File.separator + "Sati" + File.separator + dajMjesecUGodini() + ".txt"; + } + + public String dajMjesecUGodini() { + switch (calendar.getTime().getMonth()) { + case 0: + return "Siječanj"; + case 1: + return "Veljača"; + case 2: + return "Ožujak"; + case 3: + return "travanj"; + case 4: + return "Svibanj"; + case 5: + return "Lipanj"; + case 6: + return "Srpanj"; + case 7: + return "Kolovoz"; + case 8: + return "Rujan"; + case 9: + return "Listopad"; + case 10: + return "Studeni"; + } + return "Prosinac"; + } + + void napraviNovuListu(){ + + File file = new File(path); + file.getParentFile().mkdirs(); + try { + file.createNewFile(); + FileWriter writer = new FileWriter(path); + for (String str : novaListaSati()) { + writer.write(str + "."); + writer.write("\r\n"); + } + writer.close(); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + + public String dajBrojDana(){ + + SimpleDateFormat dateFormat = new SimpleDateFormat("dd"); + return "" + dateFormat.format(date); + } + //ispiši redne dane za cijeli mjesec + public List novaListaSati(){ + + List lista = new ArrayList(); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd"); + calendar.setTime(date); + calendar.set(calendar.DAY_OF_MONTH, 1); + int myMonth = calendar.get(calendar.MONTH); + + while (myMonth == calendar.get(calendar.MONTH)) { + lista.add(dateFormat.format(calendar.getTime())); + calendar.add(calendar.DAY_OF_MONTH, 1); + } + return lista; + } + + void printDaysTEST(){ + + SimpleDateFormat dateFormat = new SimpleDateFormat("dd"); + calendar.setTime(date); + calendar.set(calendar.DAY_OF_MONTH, 1); + int myMonth = calendar.get(calendar.MONTH); + + while(myMonth == calendar.get(calendar.MONTH)){ + System.out.println(dateFormat.format(calendar.getTime())); + calendar.add(calendar.DAY_OF_MONTH, 1); + } + } + + public String getPath() { + return path; + } + + +} diff --git a/UserInterface.java b/UserInterface.java new file mode 100644 index 0000000..7b79bf6 --- /dev/null +++ b/UserInterface.java @@ -0,0 +1,85 @@ +package textvježba; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * + * @author Tomislav + */ +public class UserInterface { + + Scanner input = new Scanner(System.in); + private Mjesec mjesec = new Mjesec(); + private Dan dan; + List sati = new ArrayList<>(); + + public UserInterface() { + } + + void run() throws IOException { + System.out.println("Odaberi opciju:"); + System.out.println(" 1. Unesi podatke za današnji datum"); + System.out.println(" 2. Unesi podatke za neki drugi datum"); + System.out.println(" 3. Isprintaj cijeli mjesec"); + int odabir = input.nextInt(); + switch(odabir){ + case 1: unesiSate(); + case 4: mjesec.napraviNovuListu(); + } + } + + void unesiSate() { + double pocetakRada; + double krajRada; + System.out.print("Unesi pocetak rada: "); + pocetakRada = input.nextDouble(); + System.out.print("Unesi kraj rada: "); + krajRada = input.nextDouble(); + dan = new Dan(mjesec.dajBrojDana(), pocetakRada, krajRada); + sati.set(mjesec.date.getDay(), "dfs"); + try { + ucitajSate(); + + } catch (Exception e) { + } + + + try { + ispisiUText(); + for(String str: sati){ + System.out.println(str); + } + + } catch (Exception e) { + } + + } + + void ucitajSate() throws FileNotFoundException { + Scanner scanner = new Scanner(new File(mjesec.getPath())); + while (scanner.hasNextLine()) { + sati.add(scanner.nextLine()); + } + } + + void ispisiUText() throws IOException { + FileWriter writer = new FileWriter(mjesec.getPath()); + for (String str : sati) { + writer.write(str); + writer.write("\r\n"); + } + writer.close(); + } + //Napravi fajl sa rednim brojevima za dane za cijeli mjesec + void pripremiMjesec(){ + sati = mjesec.novaListaSati(); + mjesec.napraviNovuListu(); + } + +}