Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //plik klasowy baza
- package ztp1;
- public class Baza {
- //private char[] tab = new char[100];
- private char[] tab = {'a','b','c','d','e','f','g','h'};
- static Baza baza = new Baza();
- /* ... */
- private Baza() {}
- public static Baza getBaza() {
- return baza;
- }
- public static IPolaczenie getPolaczenie() {
- return Polaczenie.getInstance();
- }
- private static class Polaczenie implements IPolaczenie {
- private Baza baza;
- private static int which = 0;
- private static Polaczenie[] polaczenia = {
- new Polaczenie(), new Polaczenie(), new Polaczenie()
- };
- /* ... */
- public static IPolaczenie getInstance() {
- // System.out.println("korzystasz z "+ which + "-tego polaczenia.");
- // return polaczenia[which];
- which = (++which) % polaczenia.length;
- System.out.println("bedziesz korzystac z "+ which + "-tego polaczenia.");
- return polaczenia[which];
- }
- //private Polaczenie() {}
- @Override
- public char get(int indeks) {
- return baza.tab[indeks];
- }
- @Override
- public void set(int indeks, char c) {
- baza.tab[indeks] = c;
- }
- @Override
- public int length() {
- return baza.tab.length;
- }
- }
- }
- // plik interfejs
- package ztp1;
- public interface IPolaczenie {
- char get(int indeks);
- void set(int indeks, char c);
- int length();
- }
- // plik glowny
- package ztp1;
- public class ZTP1 {
- public static void main(String[] args) {
- IPolaczenie first, second, third;
- first = Baza.getPolaczenie();
- second = Baza.getPolaczenie();
- third = Baza.getPolaczenie();
- int i = 0;
- while(i<5){
- System.out.println(first.get(i)+
- " " + second.get((i+3)%5) +
- " " + third.get((i+5)%5)
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement