Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Talar;
- import java.util.Random;
- public class Main {
- public static void main(String[] args) {
- Random rand = new Random();
- double ceny[] = new double[20];
- //Uzupełnienie tablicy randomowymi liczbami
- System.out.print("Przed promocją: ");
- for(int i = 0; i < ceny.length; i++){
- ceny[i] = rand.nextInt(100);
- System.out.print(ceny[i] + ", ");
- }
- //Wywołanie funkcji
- double Bilans_promocji = swiatecznaPromocja(ceny);
- System.out.print("Bilans promocji: " + Bilans_promocji);
- }
- static double swiatecznaPromocja(double [] ceny){
- double srednia = 0;
- double suma = 0;
- double suma_podw = 0;
- double suma_obni = 0;
- //Wyliczanie średniej:
- for(int i = 0; i < ceny.length; i++){
- suma += ceny[i];
- }
- srednia = suma/ceny.length;
- //Obniżka cen
- for(int i = 0; i < ceny.length; i++){
- if(ceny[i]>srednia){
- suma_obni = ceny[i] - (ceny[i]*0.90);
- ceny[i] = ceny[i] * 0.90;
- }
- else if(ceny[i]<srednia){
- suma_podw = (ceny[i]*1.15) - ceny[i];
- ceny[i] = ceny[i] * 1.15;
- }
- }
- //Wyswietlanie cen po promocji
- System.out.print("\nPo promocji: ");
- for(int i = 0; i < ceny.length; i++){
- System.out.print(ceny[i] + ", ");
- }
- System.out.println("\nSuma obnizek: " + suma_obni + ", suma podwyżek: " +suma_podw);
- return suma_podw - suma_obni;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement