P24Wyjatki.java
Interfejs 1 (MiesiacDzien.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
//MiesiacDzien.java - Interfejs 1 package p24wyjatki; import java.util.*; public interface MiesiacDzien { int[][] nr_znaku = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, {0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0}, {0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, {0, 4, 4, 4, 4, 4, 4, 4,4 , 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0}, {0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}, {0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0}, {0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}, {0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9}, {0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10, 0}, {0,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 10,10,10,10,10,11,11,11,11,11,11,11,11,11}, {0,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, 11,11,11,11,12,12,12,12,12,12,12,12,12, 0}, {0,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12, 1, 1, 1, 1, 1, 1, 1, 1, 1} }; } |
---|
Interfejs 2 (TablicaZodiak.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// TablicaZodiak.java - Interfejs 2 package p24wyjatki; import java.util.*; public interface TablicaZodiak { String[] ZODIAK = { "Zle dane", "Koziorozec", "Wodnik", "Ryby", "Baran", "Byk", "Bliznieta", "Rak", "Lew", "Panna", "Waga", "Skorpion", "Strzelec" }; } |
---|
Program (P24Wyjatki.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// P24Wyjatki.java package p24wyjatki; import java.util.*; public class P24Wyjatki implements MiesiacDzien,TablicaZodiak { public static void main(String[] args) { int k1 = MiesiacDzien.nr_znaku[1][1]; System.out.println(TablicaZodiak.ZODIAK[k1]); int k2 = MiesiacDzien.nr_znaku[2][40]; System.out.println(TablicaZodiak.ZODIAK[k2]); } } |
---|
P25Wyjatki.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
// P25Wyjatki.java package p25wyjatki; import java.util.*; public class P25Wyjatki implements MiesiacDzien,TablicaZodiak { public static void main(String[] args) { int k1 = MiesiacDzien.nr_znaku[1][1]; System.out.println(TablicaZodiak.ZODIAK[k1]); try { int k2 = MiesiacDzien.nr_znaku[2][33]; System.out.println(TablicaZodiak.ZODIAK[k2]); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Zle dane- przechwycony wyjatek"); } int k3 = MiesiacDzien.nr_znaku[2][10]; System.out.println(TablicaZodiak.ZODIAK[k3]); int k4 = MiesiacDzien.nr_znaku[2][33]; System.out.println(TablicaZodiak.ZODIAK[k4]); // reszta nie zostanie wykonana - wyjatek = przerwanie int k5 = MiesiacDzien.nr_znaku[6][6]; System.out.println(TablicaZodiak.ZODIAK[k5]); } } |
---|
P26Wyjatki.java