Advertisement
Guest User

ClientN Finito!

a guest
Jan 19th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.*;
  4.  
  5.  
  6. public class clientN {
  7.     public static void main ( String[] args)
  8.     {  
  9.         try {
  10.             InetAddress addr = InetAddress.getByName("localhost");
  11.             Socket s = new Socket(addr,5000);            
  12.             PrintStream writer = new PrintStream(s.getOutputStream(),true);
  13.             InputStreamReader reader = new InputStreamReader(s.getInputStream());
  14.             BufferedReader read = new BufferedReader(reader);
  15.             int temp;
  16.             do
  17.             {
  18.                 System.out.println("Aggiungi scelta : ");
  19.                 Scanner input = new Scanner(System.in);
  20.                 String inputValue = new String(input.nextLine());
  21.                 temp = Integer.parseInt(inputValue);
  22.                 writer.println(inputValue);
  23.                 switch(temp)
  24.                 {
  25.                     case 1 :
  26.                         //inserimento negozio
  27.                         System.out.println("Aggiugi negozio :");
  28.                         String shopName = input.nextLine();
  29.                         writer.println(shopName);
  30.                         System.out.println(read.readLine());
  31.                         break;
  32.                    
  33.                     case 2 :
  34.                         //eliminazione negozio
  35.                         System.out.println("Negozio da eliminare :");
  36.                         String shopNameToDelete = input.nextLine();
  37.                         writer.println(shopNameToDelete);
  38.                         System.out.println(read.readLine());
  39.                         break;
  40.  
  41.                     case 3:
  42.                         //inserimento prodotto
  43.                         System.out.println("Nome del negozio prodotto: ");
  44.                         String addShopName = new String(input.nextLine());
  45.                         System.out.println("Nome del prodotto: ");
  46.                         String productName = new String(input.nextLine());
  47.                         writer.println(addShopName);
  48.                         writer.println(productName);
  49.                         System.out.println(read.readLine());
  50.                         break;
  51.                        
  52.                     case 4:
  53.                         //eliminazione prodotto
  54.                         System.out.println("Nome del negozio da cui eliminare: ");
  55.                         String shopToDelete = new String(input.nextLine());
  56.                         System.out.println("Nome del prodotto da eliminare: ");
  57.                         String productNameToDelete = new String(input.nextLine());
  58.                         writer.println(shopToDelete);
  59.                         writer.println(productNameToDelete);
  60.                         System.out.println(read.readLine());
  61.                         break;
  62.                    
  63.                 }
  64.             }while(temp != 0);            
  65.             writer.close();
  66.             s.close();
  67.             System.out.println("Arrivederci!");
  68.         } catch (Exception e) {
  69.             System.out.println(e);
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement