leniuch

lekarstwa

Feb 25th, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. public class lekarstwa {
  2.  
  3.     static private String[] nazwa;
  4.     static private double[] cena;
  5.     static private double[] refundacja;
  6.    
  7.     lekarstwa(String[] nazwa, double[] cena, double[] refundacja){
  8.     this.nazwa = new String[nazwa.length];
  9.     this.cena = new double[cena.length];
  10.     this.refundacja = new double[refundacja.length];
  11.    
  12.     for(int i=0;i<nazwa.length;i++){
  13.     char[] znaki = nazwa[i].toCharArray();
  14.     String poprawione = Character.toString(znaki[0]).toUpperCase();
  15.     int lk = 0;
  16.         for(char a:znaki){
  17.             if(lk>0) poprawione+= Character.toString(a).toLowerCase();
  18.             lk++;
  19.         }
  20.     this.nazwa[i] = poprawione;
  21.     }
  22.    
  23.     for(int i=0;i<cena.length;i++){
  24.     this.cena[i] = cena[i];
  25.     }
  26.    
  27.     for(int i=0;i<refundacja.length;i++){
  28.     this.refundacja[i] = refundacja[i];
  29.     }
  30.    
  31.     }
  32.    
  33.     public static double Cena(String lek, boolean ubezpieczony){
  34.         int lk=0;
  35.         for(String a:nazwa){
  36.             if(a.equals(lek)) break;
  37.             lk++;
  38.         }
  39.         if(ubezpieczony==true) return cena[lk]*(1-refundacja[lk]);
  40.         else return cena[lk];}
  41.    
  42.     public static double kosztCalkowity(){
  43.     double suma=0;
  44.         for(double a:cena){
  45.             suma+=a;
  46.         }
  47.     return suma;}
  48.    
  49.     public static void wyswietl(int index_leku){
  50.         System.out.println(nazwa[index_leku]+", cena: "+cena[index_leku]+", refundacja: "+(refundacja[index_leku])*100+"%");}
Add Comment
Please, Sign In to add comment