Advertisement
Pihtija

OBP2 V5

Nov 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. package paket1;
  2.  
  3. import java.io.Serializable;
  4.  
  5. /**
  6. * Created by korisnik on 20.11.2018..
  7. */
  8. public class Osoba implements Serializable{
  9. private String ime;
  10. private int godiste;
  11. transient private double plata;
  12.  
  13. public Osoba(String ime, int godiste){
  14. this.ime=ime;
  15. this.godiste=godiste;
  16. }
  17.  
  18. @Override
  19. public String toString() {
  20. return "Osoba{" +
  21. "me='" + ime + '\'' +
  22. ", godiste=" + godiste +
  23. ", plata=" + plata +
  24. '}';
  25. }
  26.  
  27. public double getPlata() {
  28. return plata;
  29. }
  30.  
  31. public void setPlata(double plata) {
  32. this.plata = plata;
  33. }
  34.  
  35.  
  36. }
  37.  
  38.  
  39. ----------------------------------------
  40. package glavni;
  41.  
  42. import paket1.Osoba;
  43.  
  44. import java.io.*;
  45.  
  46. /**
  47. * Created by korisnik on 20.11.2018..
  48. */
  49. public class Program {
  50. public static void main(String[] args) {
  51. Osoba o1=new Osoba("Pera", 1900);
  52. o1.setPlata(50000);
  53. System.out.println(o1);
  54.  
  55. try {
  56. FileOutputStream fos=new FileOutputStream("dat.bin");
  57. ObjectOutputStream oos=new ObjectOutputStream(fos);
  58. oos.writeObject(o1);
  59. fos.close();
  60. oos.close();
  61. System.out.println("objekat uspesno sacuvan" );
  62. } catch (FileNotFoundException e) {
  63. e.printStackTrace();
  64. } catch (IOException e) {
  65. e.printStackTrace();
  66. }
  67.  
  68. try {
  69. FileInputStream fis= new FileInputStream("dat.bin");
  70. ObjectInputStream ois = new ObjectInputStream(fis);
  71. Osoba op=(Osoba) ois.readObject();
  72. fis.close();
  73. ois.close();
  74. System.out.println(op);
  75.  
  76. } catch (FileNotFoundException e) {
  77. e.printStackTrace();
  78. } catch (IOException e) {
  79. e.printStackTrace();
  80. } catch (ClassNotFoundException e) {
  81. e.printStackTrace();
  82. }
  83.  
  84. }
  85. }
  86. ----------------------------------
  87. package samostalni;
  88.  
  89. import java.io.Serializable;
  90.  
  91. /**
  92. * Created by korisnik on 20.11.2018..
  93. */
  94. public class Settings implements Serializable{
  95. private String korisnickoime;
  96. private String licenca;
  97. private int vreme;
  98.  
  99. public Settings(String korisnickoime, String licenca, int vreme) {
  100. this.korisnickoime = korisnickoime;
  101. this.licenca = licenca;
  102. this.vreme = vreme;
  103. }
  104.  
  105. public String getKorisnickoime() {
  106. return korisnickoime;
  107. }
  108.  
  109. public String getLicenca() {
  110. return licenca;
  111. }
  112.  
  113. public int getVreme() {
  114. return vreme;
  115. }
  116.  
  117. public void setKorisnickoime(String korisnickoime) {
  118. this.korisnickoime = korisnickoime;
  119. }
  120.  
  121. public void setLicenca(String licenca) {
  122. this.licenca = licenca;
  123. }
  124.  
  125. public void setVreme(int vreme) {
  126. this.vreme = vreme;
  127. }
  128.  
  129. @Override
  130. public String toString() {
  131. return "Settings{" +
  132. "korisnickoime='" + korisnickoime + '\'' +
  133. ", licenca='" + licenca + '\'' +
  134. ", vreme=" + vreme +
  135. '}';
  136. }
  137. }
  138. -----------------------------------------
  139. package glavni;
  140.  
  141. import com.sun.xml.internal.ws.api.config.management.policy.ManagementAssertion;
  142. import samostalni.Settings;
  143.  
  144. import java.io.*;
  145. import java.util.Scanner;
  146.  
  147. /**
  148. * Created by korisnik on 20.11.2018..
  149. */
  150. public class GlavniSamostalni {
  151. public static void main(String[] args) {
  152.  
  153. String[] licence = new String [5];
  154. licence[0]="1111-2222-3333-4444";
  155. licence[1]="1111-skn8-3333-4444";
  156. licence[2]="1111-2222-snaf-4444";
  157. licence[3]="Ps21-2JS2-3333-4444";
  158. licence[4]="1111-2222-3333-6542";
  159.  
  160. try {
  161. FileOutputStream fos = new FileOutputStream("license.bin");
  162. ObjectOutputStream oos = new ObjectOutputStream(fos);
  163. Settings ob = new Settings("evaluate", "0000-0000-0000-0000", 1);
  164. oos.writeObject(ob);
  165. fos.close();
  166. oos.close();
  167. System.out.println("Uspesno kreiran fajl");
  168. } catch (FileNotFoundException e) {
  169. e.printStackTrace();
  170. } catch (IOException e) {
  171. e.printStackTrace();
  172. }
  173. Scanner sc = new Scanner(System.in);
  174.  
  175. System.out.println("Imate li licencu??");
  176. System.out.println("Y/N");
  177. String in = sc.nextLine();
  178.  
  179. if (in.contains("y")) {
  180. System.out.println("Unesite licencu u obliku xxxx-xxxx-xxxx-xxxx");
  181. String lc = sc.nextLine();
  182. for (int i=0; i<licence.length;i++){
  183. if (licence[i].equals(lc)){
  184. System.out.println("Unesite zeljeno korisnicko ime: ");
  185. String ki=sc.nextLine();
  186. Settings novi = new Settings(ki, lc, 15);
  187. }
  188.  
  189. }
  190. }
  191.  
  192. else if (in.contains("n"))
  193. System.out.println("Nema");
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. }
  201. }
  202. -----------------------------------------
  203. package samostalni;
  204.  
  205. /**
  206. * Created by korisnik on 20.11.2018..
  207. */
  208. public class Nit {
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement