Advertisement
Talar97

Adrian kolokwium 4

Jan 11th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package com.Talar;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Random rand = new Random();
  9.         double ceny[] = new double[20];
  10.  
  11.         //Uzupełnienie tablicy randomowymi liczbami
  12.         System.out.print("Przed promocją: ");
  13.         for(int i = 0; i < ceny.length; i++){
  14.             ceny[i] = rand.nextInt(100);
  15.             System.out.print(ceny[i] + ", ");
  16.         }
  17.  
  18.         //Wywołanie funkcji
  19.         double Bilans_promocji = swiatecznaPromocja(ceny);
  20.         System.out.print("Bilans promocji: " + Bilans_promocji);
  21.     }
  22.  
  23.     static double swiatecznaPromocja(double [] ceny){
  24.         double srednia = 0;
  25.         double suma = 0;
  26.         double suma_podw = 0;
  27.         double suma_obni = 0;
  28.  
  29.         //Wyliczanie średniej:
  30.         for(int i = 0; i < ceny.length; i++){
  31.             suma += ceny[i];
  32.         }
  33.         srednia = suma/ceny.length;
  34.  
  35.         //Obniżka cen
  36.         for(int i = 0; i < ceny.length; i++){
  37.             if(ceny[i]>srednia){
  38.                 suma_obni = ceny[i] - (ceny[i]*0.90);
  39.                 ceny[i] = ceny[i] * 0.90;
  40.             }
  41.             else if(ceny[i]<srednia){
  42.                 suma_podw = (ceny[i]*1.15) - ceny[i];
  43.                 ceny[i] = ceny[i] * 1.15;
  44.             }
  45.         }
  46.  
  47.         //Wyswietlanie cen po promocji
  48.         System.out.print("\nPo promocji: ");
  49.         for(int i = 0; i < ceny.length; i++){
  50.             System.out.print(ceny[i] + ", ");
  51.         }
  52.         System.out.println("\nSuma obnizek: " + suma_obni + ", suma podwyżek: " +suma_podw);
  53.  
  54.         return suma_podw - suma_obni;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement