Mrgentledolphin

calcola reparti frutta

Nov 30th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package scuola;
  2. import java.util.*;
  3. public class IVA1 {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner input;
  8.         input=new Scanner (System.in);
  9.        
  10.         int cont=0, nprod;
  11.         float pkg, kgs, frutta, spesa, tot = 0, min=9999999, sf=0;
  12.         String reparto, minn = null;
  13.        
  14.         System.out.println("inserire numero prodotti acquistati:");
  15.         nprod=input.nextInt();
  16.        
  17.         while (nprod>cont){
  18.             cont=cont+1;
  19.             System.out.println("inserire nome reparto");
  20.             reparto=input.next();
  21.            
  22.             System.out.println("prezzo al kilo");
  23.             pkg=input.nextFloat();
  24.             System.out.println("inserire quantità di kg acquistati del prodotto");
  25.             kgs=input.nextFloat();
  26.            
  27.             spesa=pkg*kgs;
  28.            
  29.             if(reparto.equals("frutta")){
  30.                 sf=spesa;
  31.             }
  32.             if (pkg<min){
  33.                 min=pkg;
  34.                 minn=reparto;
  35.             }
  36.             tot=tot+spesa;
  37.            
  38.            
  39.         }
  40.         System.out.println("spesa totale: "+tot);
  41.         System.out.println("reparto più economica: "+minn);
  42.         System.out.println("spesa reparto frutta: "+sf);
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment