Guest User

Untitled

a guest
Jun 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. //parreira
  2.  
  3. public class HardDrive {
  4.    
  5.     //const
  6.  
  7.     private static final int TAMANHOGB = 1024;
  8.     private static final int ESCALAO1 = 150;
  9.     private static final float TAXA1 = 0.02f;
  10.     private static final float TAXA2 = 0.005f;
  11.    
  12.     //var
  13.    
  14.     private int serial;
  15.     private String provider;
  16.     private int capacity;
  17.     private float basePrice;
  18.    
  19.     public HardDrive(int serial, String provider, int capacity, float basePrice) {
  20.         this.serial = serial;
  21.         this.provider = provider;
  22.         this.capacity = capacity;
  23.         this.basePrice = basePrice;
  24.     }
  25.    
  26.     public int getSerialNumber() {
  27.         return serial;
  28.     }
  29.    
  30.     public String getProvider() {
  31.         return provider;
  32.     }
  33.    
  34.     public float getBasePrice() {
  35.         return basePrice;
  36.     }
  37.    
  38.     public int getCapacity() {
  39.         return capacity;
  40.     }
  41.    
  42.     public void setNewBasePrice(float newBasePrice) {
  43.         basePrice = newBasePrice;
  44.     }
  45.    
  46.     public float getTax() {
  47.         float tax = 0;
  48.         if (getCapacity() > TAMANHOGB)
  49.             tax = ( getCapacity() - TAMANHOGB) * TAXA2 + TAMANHOGB * TAXA1;
  50.         if (getCapacity() >= ESCALAO1)
  51.             tax = getCapacity() * TAXA1;
  52.         return tax;
  53.     }
  54.    
  55.     public boolean lessExpensiveThan(HardDrive other) {
  56.         float preco = (getBasePrice() + getTax()) / getCapacity();
  57.         float precoOther = (other.getBasePrice() + other.getTax()) / other.getCapacity();
  58.         boolean maisBarato = false;
  59.         if (preco > precoOther)
  60.             maisBarato = true;
  61.         return maisBarato;
  62.     }
  63. }
Add Comment
Please, Sign In to add comment