Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package centroSportivo;
- public class Abbonamento { // Genera oggetti immutabili
- public final static String[] mesi = { "gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio",
- "agosto", "settembre", "ottobre", "novembre", "dicembre" };
- public final static int MESI = 12, SETTIMANE = 4;
- private int codiceServizio;
- private boolean[][] mesiSettimane;
- public Abbonamento(int codiceServizio, boolean[][] mesiSettimane) {
- this.codiceServizio = codiceServizio;
- mesiSettimane = new boolean[MESI][SETTIMANE];
- for (int i = 0; i < MESI; i++)
- for (int j = 0; j < SETTIMANE; j++)
- this.mesiSettimane[i][j] = mesiSettimane[i][j];
- }// Costruttore
- public int getCodiceServizio() {
- return codiceServizio;
- }// getCodiceServizio
- public boolean[][] getMesiSettimane() {
- boolean[][] ret = new boolean[MESI][SETTIMANE];
- for (int i = 0; i < 12; i++)
- for (int j = 0; j < 4; j++)
- ret[i][j] = mesiSettimane[i][j];
- return ret;
- }// getMesiSettimane
- public static int getIndiceMese(String mese) {
- int indiceMese = -1;
- for(int i=0; i<mesi.length; i++) {
- if(mesi[i].equals(mese)) {
- indiceMese = i;
- break;
- }// if
- }// for
- return indiceMese;
- }// getIndiceMese
- public int getSettimaneCoperte(String mese) {
- int conta = 0;
- int indiceMese = getIndiceMese(mese);
- for (int i = 0; i < mesiSettimane[indiceMese].length; i++)
- if (mesiSettimane[indiceMese][i])
- conta++;
- return conta;
- }// getSettimaneCoperte
- }// Abbonamento
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement