Share Pastebin
Guest
Public paste!

Francisco

By: a guest | Jul 3rd, 2009 | Syntax: D | Size: 1.73 KB | Hits: 65 | Expires: Never
Copy text to clipboard
  1. module classes.BombaDeCombustivel;
  2.  
  3. import std.stdio;
  4.  
  5. class BombaDeCombustivel {
  6.  
  7.     private:
  8.         char[] tipoCombustivel;
  9.         double valorLitro;
  10.         double quantidadeCombustivel;
  11.        
  12.     public:
  13.         this() { }
  14.        
  15.         this(char[] tipo, double valorLitro, double quantidadeCombustivel) {
  16.             this.tipoCombustivel = tipo;
  17.             this.valorLitro = valorLitro;
  18.             this.quantidadeCombustivel = quantidadeCombustivel;
  19.         }
  20.        
  21.         void abastecerPorValor(double valor) {
  22.             double litros = valor / this.valorLitro;
  23.             this.quantidadeCombustivel += litros;
  24.             writefln("Foram abastecidos %.2f litros.", litros);
  25.         }
  26.        
  27.         void abastecerPorLitro(double litros) {
  28.             double preco = litros * this.valorLitro;
  29.             this.quantidadeCombustivel += litros;
  30.             writefln("O cliente deve pagar R$ %.2f.", preco);
  31.         }
  32.        
  33.         void alterarValor(double novoValor) {
  34.             this.valorLitro = novoValor;
  35.         }
  36.        
  37.         void alterarCombustivel(char[] novoCombustivel) {
  38.             this.tipoCombustivel = novoCombustivel;
  39.         }
  40.        
  41.         void alterarQuantidadeCombustivel(double novaQuantidade) {
  42.             this.quantidadeCombustivel = novaQuantidade;
  43.         }
  44.        
  45.         void imprimir() {
  46.             writefln("Tipo de Combustível: %s\nValor do litro: R$ %.2f\nQuantidade de combustível: %.2f", this.tipoCombustivel, this.valorLitro, this.quantidadeCombustivel);
  47.         }
  48. }
  49.  
  50. void main(char[][] args) {
  51.     BombaDeCombustivel b = new BombaDeCombustivel("Francisco", 2.3, 0);
  52.     b.abastecerPorLitro(20);
  53.     b.abastecerPorValor(10);
  54.     b.imprimir();
  55. }