Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws Exception {
- // Your code here!
- Veiculo bugattiVeyron = new BugattiVeyron();
- VeiculoAdapter bugattiVeyronAdapter = new VeiculoAdapterImpl(bugattiVeyron);
- System.out.println(bugattiVeyronAdapter.getSpeed());
- }
- }
- public interface Veiculo {
- // retorna a velocidade em MPH
- double getSpeed();
- }
- public class BugattiVeyron implements Veiculo {
- @Override
- public double getSpeed() {
- return 268;
- }
- }
- public interface VeiculoAdapter {
- // retorna a valocidade em KM/H
- double getSpeed();
- }
- public class VeiculoAdapterImpl implements VeiculoAdapter {
- private Veiculo luxuryCars;
- public VeiculoAdapterImpl(Veiculo luxuryCars){
- this.luxuryCars = luxuryCars;
- }
- @Override
- public double getSpeed() {
- return convertMPHtoKMPH(luxuryCars.getSpeed());
- }
- private double convertMPHtoKMPH(double mph) {
- return mph * 1.60934;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement