Advertisement
Guest User

Main.java

a guest
Mar 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.        
  6.         Scanner s= new Scanner("");
  7.         int dimensione;
  8.        
  9.         Rubrica r;
  10.         if(s.hasNextInt()) {
  11.             System.out.println("Inserisci dimensione rubrica:");
  12.          dimensione=s.nextInt();
  13.         } else {
  14.              dimensione=1;
  15.         }
  16.         s.close();
  17.        
  18.         r=new Rubrica(dimensione);
  19.          
  20.         String comando="";  //da tastiera ricevo il comando dello switch
  21.         Scanner f=new Scanner("");
  22.         if(f.hasNextLine()) {
  23.         comando=f.nextLine().toLowerCase();
  24.         }
  25.         f.close();
  26.        
  27.         System.out.println("Scrivi:\n 'aggiungi' per aggiungere un contatto;\n 'cancella' per cancellare un contatto; \n 'modifica' per modificare un contatto; \n 'cerca' per cercare un contatto; \n 'stampa' per stampare la rubrica. \n 'fine' per finire \n ");
  28.        
  29.         while(comando!="fine") {
  30.            
  31.             Scanner z= new Scanner("");
  32.            
  33.             if(z.hasNextLine()) {
  34.                 switch (comando) {
  35.            
  36.                 case "aggiungi": {
  37.                     System.out.println("Inserisci in ordine: nome, cognome, telefono ed email!\n");
  38.                     r.aggiungiPersona(z.nextLine(), z.nextLine(), z.nextLine(), z.nextLine());
  39.                     z.close();
  40.        
  41.                 } break;
  42.                
  43.                 case "cancella": {
  44.                     System.out.println("Inserisci in ordine: nome e cognome!\n");
  45.                     r.cancellaPersona(z.nextLine(), z.nextLine());
  46.                     z.close();
  47.                 } break;
  48.                
  49.                 case "modifica": {
  50.                     System.out.println("Inserisci in ordine: nome, cognome, telefono ed email!\n");
  51.                      r.modificaPersona(z.nextLine(), z.nextLine(), z.nextLine(), z.nextLine());
  52.                         z.close();
  53.                 } break;
  54.                
  55.                 case "cerca": {
  56.                     System.out.println("Inserisci in ordine: nome e cognome!\n");
  57.                      r.cercaPersona(z.nextLine(), z.nextLine());
  58.                         z.close();
  59.                 } break;
  60.        
  61.                 case "stampa": {
  62.                      r.stampaRubrica();
  63.                 } break;
  64.        
  65.                 case "fine": {
  66.                      comando="fine";
  67.                 } break;
  68.                
  69.                 default: System.out.println("Errore! Hai inserito un comando non valido!");
  70.                
  71.                     }
  72.                 }
  73.             }
  74.         }
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement