Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class app {
- public static Settings glavni;
- public static void main(String[] args) {
- File f = new File("licence.bin");
- ArrayList<String> lista_licenci = new ArrayList<>();
- lista_licenci.add("AAAA-AAAA-AAAA-AAAA");
- lista_licenci.add("BBBB-BBBB-BBBB-BBBB");
- lista_licenci.add("CCCC-CCCC-CCCC-CCCC");
- if(!f.exists()){
- try {
- Settings def = new Settings();
- f.createNewFile();
- def.upisi("licence.bin");
- System.out.println("Datoteka kreirana!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else {
- System.out.println("Datoteka vec postoji");
- Settings cit;
- cit = Settings.procitaj("licence.bin");
- System.out.println(cit);
- }
- System.out.println("DA LI IMATE LICENCU ZA PROGRAM?? (DA/NE)");
- Scanner input = new Scanner(System.in);
- input.useDelimiter("\\n");
- String unos = input.next();
- if(unos.equals("DA")){
- String unos_licence = null;
- while (!lista_licenci.contains(unos_licence)){
- System.out.println("UNESITE SVOJU LICENCU (FORMAT: XXXX-XXXX-XXXX-XXXX");
- unos_licence = input.next();
- }
- if(lista_licenci.contains(unos_licence)){
- System.out.println("UNESITE ZELJENO KORISNICKO IME: ");
- unos = input.next();
- Settings novi = new Settings(unos,unos_licence,15);
- novi.upisi("licence.bin");
- glavni = novi;
- }
- }else {
- System.exit(0);
- }
- Nit nit = new Nit();
- nit.start();
- }
- }
- ////////
- /**
- * Created by guest-Mt2hFp on 21.11.17..
- */
- public class Nit extends Thread {
- public void run(){
- while (app.glavni.getVreme()>0){
- System.out.println(app.glavni.getKorisnickoime());
- try {
- this.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- app.glavni.smanjiVreme();
- app.glavni.upisi("licence.bin");
- }
- }
- }
- ///////////
- import java.io.*;
- /**
- * Created by markort2815 on 21.11.17..
- */
- public class Settings implements Serializable {
- private String korisnickoime;
- private String licenca;
- private int vreme;
- public Settings(String korisnickoime, String licenca, int vreme) {
- this.korisnickoime = korisnickoime;
- this.licenca = licenca;
- this.vreme = vreme;
- }
- public Settings() {
- this.korisnickoime = "evaluate";
- this.licenca = "0000-0000-0000-0000";
- this.vreme = 1;
- }
- public static Settings procitaj(String path){
- try {
- FileInputStream fileInputStream = new FileInputStream(path);
- ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
- Settings load = (Settings)objectInputStream.readObject();
- fileInputStream.close();
- objectInputStream.close();
- return load;
- }catch (IOException e){
- e.printStackTrace();
- return null;
- }catch (ClassNotFoundException e){
- e.printStackTrace();
- return null;
- }
- }
- public void upisi(String path){
- try {
- FileOutputStream fileOutputStream = new FileOutputStream(path);
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
- objectOutputStream.writeObject(this);
- objectOutputStream.close();
- fileOutputStream.close();
- }catch (IOException e){
- e.printStackTrace();
- }
- }
- @Override
- public String toString() {
- return "Settings{" +
- "korisnickoime='" + korisnickoime + '\'' +
- ", licenca='" + licenca + '\'' +
- ", vreme=" + vreme +
- '}';
- }
- public String getLicenca() {
- return licenca;
- }
- public String getKorisnickoime() {
- return korisnickoime;
- }
- public int getVreme() {
- return vreme;
- }
- public void smanjiVreme(){
- vreme=vreme-1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment