Advertisement
Al3X044

wizzard contest

Dec 11th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. abstract class Vrajitor {
  2.     protected String nume;
  3.     protected int putere, v_bag;
  4.     protected double moral;
  5.    
  6.     public Vrajitor(String nume, int putere, int v_bag, double moral) {
  7.         this.nume = nume;
  8.         this.putere = putere;
  9.         this.v_bag = v_bag;
  10.         this.moral = moral;
  11.     }
  12.    
  13.     public abstract double obtineDistanta();
  14.    
  15.     public abstract double timpulNecesar();
  16.    
  17.     public String toString() {
  18.         return nume + " are moralul " + moral + " si puterea " + putere + ", iar varsta baghetei lui este de " + v_bag + " ani.";
  19.     }
  20. }
  21.  
  22. class RunnerWizzard extends Vrajitor {
  23.     public RunnerWizzard(String nume, int putere, int v_bag) {
  24.         super(nume, putere, v_bag, 10 * Math.random());
  25.     }
  26.    
  27.     public double obtineDistanta() {
  28.         return putere * v_bag - moral;
  29.     }
  30.    
  31.     public double timpulNecesar() {
  32.         return 40;
  33.     }
  34. }
  35.  
  36. class TimeStopperWizzard extends Vrajitor{
  37.     public TimeStopperWizzard(String nume, int putere, int v_bag, double moral) {
  38.         super(nume, putere, v_bag, moral);
  39.     }
  40.    
  41.     public double timpulNecesar() {
  42.         return 0;
  43.     }
  44.    
  45.     public double obtineDistanta() {
  46.         return 2 * moral;
  47.     }
  48. }
  49.  
  50. class Competitie {
  51.     private double distantaNecesara;
  52.    
  53.     public Competitie(double distantaNecesara) {
  54.         this.distantaNecesara = distantaNecesara;
  55.     }
  56.    
  57.     public double startCompetitie(Vrajitor[] membru) {
  58.         double timpTotal = 0; int i = 0;
  59.         double distantaNecesaraAux = distantaNecesara;
  60.         while(distantaNecesaraAux > 0){
  61.             distantaNecesaraAux -= membru[i].obtineDistanta();
  62.             timpTotal += membru[i].timpulNecesar();
  63.             i++;
  64.             if(i == membru.length)
  65.                 i = 0;
  66.         }
  67.         return timpTotal;
  68.     }
  69. }
  70.  
  71. class test2 {
  72.     public static void main(String[] argv) {
  73.         Vrajitor[] membruE1 = new Vrajitor[4];
  74.         membruE1[0] = new TimeStopperWizzard("Harry", 10, 2, 8.65);
  75.         membruE1[1] = new TimeStopperWizzard("Potter", 8, 1, 7.35);
  76.         membruE1[2] = new RunnerWizzard("Henry", 6, 1);
  77.         membruE1[3] = new TimeStopperWizzard("TipaBlonda", 9, 2, 9.60);
  78.        
  79.         Vrajitor[] membruE2 = new Vrajitor[3];
  80.         membruE2[0] = new RunnerWizzard("prost1", 5, 2);
  81.         membruE2[1] = new TimeStopperWizzard("prost2", 6, 1, 6.85);
  82.         membruE2[2] = new RunnerWizzard("prost3", 7, 2);
  83.        
  84.         Competitie vrajitoruii_anului = new Competitie(100);
  85.         if(vrajitoruii_anului.startCompetitie(membruE1) > vrajitoruii_anului.startCompetitie(membruE2))
  86.         {
  87.             for(int i = 0; i < membruE1.length; i++)
  88.                 System.out.println(membruE2[i]);
  89.         } else {
  90.             for(int i = 0; i < membruE1.length; i++)
  91.                 System.out.println(membruE1[i]);
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement