daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Jan 21st, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MAIN
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Shop p = new Shop();
  5.         Product prod = new Product();
  6.         prod.name = "Кефир";
  7.         prod.srok = 10;
  8.         prod.price = 100;
  9.  
  10.         Product prod2 = new Product();
  11.         prod2.name = "Кефир2";
  12.         prod2.srok = 10;
  13.         prod2.price = 200;
  14.  
  15.         Product prod3 = new Product();
  16.         prod3.name = "Кефир3";
  17.         prod3.srok = 10;
  18.         prod3.price = 300;
  19.  
  20.         p.setProduct(prod,prod2,prod3);
  21.  
  22.         System.out.println(p.getSum());
  23.     }
  24. }
  25.  
  26.  
  27. ==============PRODUCT
  28. import java.util.ArrayList;
  29.  
  30. public class Product {
  31.  
  32.     public String name;
  33.     public double srok;
  34.     public double price;
  35.  
  36. }
  37.  
  38. ================SHOP
  39. import java.util.ArrayList;
  40.  
  41. public class Shop {
  42.     ArrayList list = new ArrayList();
  43.  
  44.     public void setProduct(Product prod, Product prod2, Product prod3) {
  45.         list.add(prod);
  46.         list.add(prod2);
  47.         list.add(prod3);
  48.     }
  49.  
  50.     public double getSum() {
  51.         double sum = 0;
  52.         for (int i = 0; i < list.size(); i++) {
  53.             Product p = (Product) list.get(i);
  54.             sum = sum + p.price;
  55.  
  56.         }
  57.         return sum;
  58.     }
  59.  
  60. }
RAW Paste Data
Top