Resto de carbono - Exercício em java, ProgOOII PDF

Title Resto de carbono - Exercício em java, ProgOOII
Course Algoritmos e Programação Orientada a Objetos I
Institution Universidade Federal de Mato Grosso do Sul
Pages 5
File Size 43.4 KB
File Type PDF
Total Downloads 89
Total Views 122

Summary

Exercício em java, ProgOOII...


Description

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Carbon; /** * * @author Lucas */ public class Building implements CarbonFootprint { public double consumoMensalEnergia; public double consumoMensalGasCozinha; public double consumoMensalGasAquecimento; public Building(double consumoMensalEnergia, double consumoMensalGasCozinha, double consumoMensalGasAquecimento) { this.consumoMensalEnergia = consumoMensalEnergia; this.consumoMensalGasCozinha = consumoMensalGasCozinha; this.consumoMensalGasAquecimento = consumoMensalGasAquecimento; } @Override public double getCarbonFootprint(){ return (consumoMensalEnergia*0.295 + consumoMensalGasAquecimento*22.7 + consumoMensalGasCozinha*467); } } /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Carbon; /** * * @author Lucas */ public class Bycicle implements CarbonFootprint{ public String modelo; public Bycicle(String modelo) {

this.modelo = modelo; }

@Override public double getCarbonFootprint() { return 0; } } /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Carbon; /** * * @author Lucas */ public class Car implements CarbonFootprint { public String tipoCombustivel; public double kmPercorridos; public Car(String tipoCombustivel, double kmPercorridos) { this.tipoCombustivel = tipoCombustivel; this.kmPercorridos = kmPercorridos; } @Override public double getCarbonFootprint() { switch (tipoCombustivel) { case "G": return kmPercorridos * 2.184; case "E": return kmPercorridos * 0.720; case "D": return kmPercorridos * 3.091; } return kmPercorridos * 3.128; } }

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Carbon; /** * * @author Lucas */ public interface CarbonFootprint { public double getCarbonFootprint(); } /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Carbon; import java.util.Scanner; /** * * @author Lucas */ public class testeCarbon { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner teclado = new Scanner(System.in); CarbonFootprint Vetor[] = new CarbonFootprint[30]; double cmE, cmGC, cmGA, kmPerc; int op = 5, index = 0; String tipoComb, modelo; while (op != 0) { System.out.println("Entre com um tipo de item");

System.out.println("1 - Imovel // 2 - Carro // 3 - Bicicleta // 4 - Mostrar Pegada de Carbono // 0 - Sair"); op = teclado.nextInt(); switch (op) { case 1: System.out.println("Entre com o seu consumo mensal de: Eletrecidade (KW), Gas de Cozinha (Botijão), Gas para Aquicimento(M³)"); cmE = teclado.nextDouble(); cmGC = teclado.nextDouble(); cmGA = teclado.nextDouble(); Building casa = new Building(cmE, cmGC, cmGA); Vetor[index] = casa; index++; break; case 2: System.out.println("Entre com o tipo de combustivel: G para gasolina // E para etanol // D para Diesel // GNV para Gas Natural Veicular"); tipoComb = teclado.next(); System.out.println("Entre com sua quilometragem mensal"); kmPerc = teclado.nextDouble(); Car carro = new Car(tipoComb, kmPerc); Vetor[index] = carro; index++; break; case 3: System.out.println("Entre com o modelo de sua bicicleta"); modelo = teclado.next(); Bycicle bike = new Bycicle(modelo); Vetor[index] = bike; index++; break; case 4: System.out.println("A Pegada de Carbono correspondente a cada item de sua lista eh:"); for (int i = 0; i < index; i++) { System.out.println("Item "+(i+1)+" = " +Vetor[i].getCarbonFootprint()+ " Toneladas de CO2 emitidas"); } break; } } }

}...


Similar Free PDFs