Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. //plik klasowy baza
  2.  
  3. package ztp1;
  4.  
  5. public class Baza {
  6.     //private char[] tab = new char[100];
  7.     private char[] tab = {'a','b','c','d','e','f','g','h'};
  8.     static Baza baza = new Baza();
  9.     /* ... */
  10.     private Baza() {}
  11.     public static Baza getBaza() {
  12.         return baza;
  13.     }
  14.     public static IPolaczenie getPolaczenie() {
  15.         return Polaczenie.getInstance();
  16.     }
  17.     private static class Polaczenie implements IPolaczenie {
  18.         private Baza baza;
  19.         private static int which = 0;
  20.         private static Polaczenie[] polaczenia = {
  21.             new Polaczenie(), new Polaczenie(), new Polaczenie()
  22.         };
  23.        
  24.         /* ... */
  25.        
  26.         public static IPolaczenie getInstance() {
  27. //            System.out.println("korzystasz z "+ which + "-tego polaczenia.");
  28. //            return polaczenia[which];
  29.             which = (++which) % polaczenia.length;
  30.             System.out.println("bedziesz korzystac z "+ which + "-tego polaczenia.");
  31.             return polaczenia[which];
  32.         }
  33.         //private Polaczenie() {}
  34.        
  35.         @Override
  36.         public char get(int indeks) {
  37.             return baza.tab[indeks];
  38.         }
  39.         @Override
  40.         public void set(int indeks, char c) {
  41.             baza.tab[indeks] = c;
  42.         }
  43.         @Override
  44.         public int length() {
  45.             return baza.tab.length;
  46.         }
  47.     }
  48. }
  49.  
  50.  
  51. // plik interfejs
  52.  
  53. package ztp1;
  54.  
  55. public interface IPolaczenie {
  56.     char get(int indeks);
  57.     void set(int indeks, char c);
  58.     int length();
  59. }
  60.  
  61. // plik glowny
  62.  
  63. package ztp1;
  64.  
  65. public class ZTP1 {
  66.     public static void main(String[] args) {
  67.         IPolaczenie first, second, third;
  68.         first = Baza.getPolaczenie();
  69.         second = Baza.getPolaczenie();
  70.         third = Baza.getPolaczenie();
  71.         int i = 0;
  72.         while(i<5){
  73.             System.out.println(first.get(i)+
  74.                     " " + second.get((i+3)%5) +
  75.                     " " + third.get((i+5)%5)
  76.             );
  77.         }
  78.     }
  79.    
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement