Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1. package it.uniba.itps.lab_inf.AA10.appelli.N00.M622841;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args)
  7.     {
  8.         Scanner in = new Scanner(System.in);
  9.         final int LIMITE_SX_GIORNO = 0;
  10.         final int LIMITE_DX_GIORNO = 32;
  11.         final int LIMITE_SX_MESE =0;
  12.         final int LIMITE_DX_MESE =13;
  13.         String MONTH;
  14.         String YEAR;
  15.         String DAY;
  16.         boolean sentinella = true;
  17.         boolean data = false;
  18.        
  19.        
  20.         do
  21.         {
  22.             //PUNTO 1:
  23.             // ACQUISISCI DALLO STANDARD INPUT UNA STRINGA DAY:
  24.             System.out.println("Inserisci il giorno: ");
  25.             DAY = in.next();
  26.  
  27.             // PUNTO 2:
  28.             // Se DAY = “STOP” termina.
  29.  
  30.             if (DAY.compareToIgnoreCase("STOP") == 0)
  31.             {
  32.                 System.out.println("IL PROGRAMMA VERRA' TERMINATO...");
  33.                 sentinella = true;
  34.             }
  35.             // PUNTO 3:
  36.             // Acquisisce dallo standard input due stringhe MONTH e YEAR:
  37.             else
  38.             {
  39.                 System.out.println("Inserisci il mese: ");
  40.                 MONTH = in.next();
  41.                 System.out.println("Inserisci l'anno: ");
  42.                 YEAR = in.next();
  43.  
  44.                 //PUNTO 4:
  45.                 // Converte in numero le tre stringhe lette:
  46.                 int GIORNO = Integer.parseInt(DAY);
  47.                 int MESE = Integer.parseInt(MONTH);
  48.                 int ANNO = Integer.parseInt(YEAR);
  49.  
  50.                 //PUNTO 5:
  51.                 // Se la terna di numeri non rappresenta una data valida allora emette nello
  52.                 //standard output la stringa “ERRORE” e ricomincia l'acquisizione (passo 1.)
  53.  
  54.                 if(GIORNO <= LIMITE_SX_GIORNO || GIORNO >= LIMITE_DX_GIORNO)
  55.                 {
  56.                     System.out.println("ERRORE GIORNO!!!");
  57.                     data = false;
  58.  
  59.                 }
  60.                 else if( MESE <= LIMITE_SX_MESE || MESE >= LIMITE_DX_MESE)
  61.                 {
  62.                     System.out.println("ERRORE MESE !!!");
  63.                     data = false;
  64.  
  65.                 }
  66.                 else if( ANNO <= 0)
  67.                 {
  68.                     System.out.println("ERRORE ANNO!!!");
  69.                     data = false;
  70.                 }
  71.                 else
  72.                 {
  73.                     data = true;
  74.                 }
  75.                
  76.                 int output = CalendarUtils.weekOfDay(GIORNO, MESE, ANNO);
  77.                
  78.                 if(output == -1)
  79.                 {
  80.                     System.out.println("NON GREGORIANO!!!");
  81.                 }
  82.                 else
  83.                 {
  84.                     switch(output)
  85.                     {
  86.                     case 1: System.out.println("LUNEDI");break;
  87.                     case 2: System.out.println("MARTEDI");break;
  88.                     case 3: System.out.println("MERCOLEDI");break;
  89.                     case 4: System.out.println("GIOVEDI");break;
  90.                     case 5: System.out.println("VENERDI");break;
  91.                     case 6: System.out.println("SABATO");break;
  92.                     case 7: System.out.println("DOMENICA");break;
  93.                     default: System.out.println("BOH");
  94.                     }
  95.                     data = false;
  96.                 }
  97.             }
  98.         }
  99.         while(!sentinella || !data); // false
  100.        
  101.  
  102.  
  103.  
  104.  
  105.     }
  106.  
  107.  
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement