Advertisement
ValerioBellic

Untitled

Nov 13th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package progetpersona;
  2. import java.io.*;
  3.  
  4.  
  5. public class persona
  6. {
  7.    
  8.     private String nome;
  9.     private String cognome;
  10.  
  11.     private int anno;
  12.     public void acq()
  13.     {
  14.         InputStreamReader input = new InputStreamReader(System.in);  // impostazione dello standard input
  15.         BufferedReader tastiera = new BufferedReader(input);
  16.        
  17.         System.out.println("inserisci il nome della persona:");
  18.         try
  19.         {
  20.             nome = tastiera.readLine();
  21.         }
  22.         catch(Exception e)
  23.         {
  24.                    
  25.         }
  26.            
  27.         System.out.println("inserisci il cognome della persona:");
  28.         try
  29.             {
  30.             cognome = tastiera.readLine();
  31.             }
  32.         catch(Exception e)
  33.             {  
  34.             }
  35.        
  36.         System.out.println("Inserisci il suo anno di nascita:");
  37.         try
  38.             {
  39.             String annoLetto = tastiera.readLine();
  40.             anno=   Integer.valueOf(annoLetto).intValue();
  41.             }
  42.          catch(Exception e)
  43.             {
  44.             System.out.println("\nErrore! Inserire un valore valido");
  45.             }
  46.        
  47.         }      
  48.    
  49.    
  50.     public int calviseta()
  51.     {
  52.     int eta;
  53.     eta = 2016 - anno;
  54.     System.out.println( nome  + " " + cognome  +  " ha " + eta + " anni");
  55.     return eta;
  56.     }
  57.  
  58.  
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement