Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package paket1;
- import java.io.Serializable;
- /**
- * Created by korisnik on 20.11.2018..
- */
- public class Osoba implements Serializable{
- private String ime;
- private int godiste;
- transient private double plata;
- public Osoba(String ime, int godiste){
- this.ime=ime;
- this.godiste=godiste;
- }
- @Override
- public String toString() {
- return "Osoba{" +
- "me='" + ime + '\'' +
- ", godiste=" + godiste +
- ", plata=" + plata +
- '}';
- }
- public double getPlata() {
- return plata;
- }
- public void setPlata(double plata) {
- this.plata = plata;
- }
- }
- ----------------------------------------
- package glavni;
- import paket1.Osoba;
- import java.io.*;
- /**
- * Created by korisnik on 20.11.2018..
- */
- public class Program {
- public static void main(String[] args) {
- Osoba o1=new Osoba("Pera", 1900);
- o1.setPlata(50000);
- System.out.println(o1);
- try {
- FileOutputStream fos=new FileOutputStream("dat.bin");
- ObjectOutputStream oos=new ObjectOutputStream(fos);
- oos.writeObject(o1);
- fos.close();
- oos.close();
- System.out.println("objekat uspesno sacuvan" );
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- FileInputStream fis= new FileInputStream("dat.bin");
- ObjectInputStream ois = new ObjectInputStream(fis);
- Osoba op=(Osoba) ois.readObject();
- fis.close();
- ois.close();
- System.out.println(op);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
- ----------------------------------
- package samostalni;
- import java.io.Serializable;
- /**
- * Created by korisnik on 20.11.2018..
- */
- 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 String getKorisnickoime() {
- return korisnickoime;
- }
- public String getLicenca() {
- return licenca;
- }
- public int getVreme() {
- return vreme;
- }
- public void setKorisnickoime(String korisnickoime) {
- this.korisnickoime = korisnickoime;
- }
- public void setLicenca(String licenca) {
- this.licenca = licenca;
- }
- public void setVreme(int vreme) {
- this.vreme = vreme;
- }
- @Override
- public String toString() {
- return "Settings{" +
- "korisnickoime='" + korisnickoime + '\'' +
- ", licenca='" + licenca + '\'' +
- ", vreme=" + vreme +
- '}';
- }
- }
- -----------------------------------------
- package glavni;
- import com.sun.xml.internal.ws.api.config.management.policy.ManagementAssertion;
- import samostalni.Settings;
- import java.io.*;
- import java.util.Scanner;
- /**
- * Created by korisnik on 20.11.2018..
- */
- public class GlavniSamostalni {
- public static void main(String[] args) {
- String[] licence = new String [5];
- licence[0]="1111-2222-3333-4444";
- licence[1]="1111-skn8-3333-4444";
- licence[2]="1111-2222-snaf-4444";
- licence[3]="Ps21-2JS2-3333-4444";
- licence[4]="1111-2222-3333-6542";
- try {
- FileOutputStream fos = new FileOutputStream("license.bin");
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- Settings ob = new Settings("evaluate", "0000-0000-0000-0000", 1);
- oos.writeObject(ob);
- fos.close();
- oos.close();
- System.out.println("Uspesno kreiran fajl");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- Scanner sc = new Scanner(System.in);
- System.out.println("Imate li licencu??");
- System.out.println("Y/N");
- String in = sc.nextLine();
- if (in.contains("y")) {
- System.out.println("Unesite licencu u obliku xxxx-xxxx-xxxx-xxxx");
- String lc = sc.nextLine();
- for (int i=0; i<licence.length;i++){
- if (licence[i].equals(lc)){
- System.out.println("Unesite zeljeno korisnicko ime: ");
- String ki=sc.nextLine();
- Settings novi = new Settings(ki, lc, 15);
- }
- }
- }
- else if (in.contains("n"))
- System.out.println("Nema");
- }
- }
- -----------------------------------------
- package samostalni;
- /**
- * Created by korisnik on 20.11.2018..
- */
- public class Nit {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement