Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Desafio Animais e Carros

Animais Pacote Animals: Classe Animals

package br.com.diego.Animals;

public class Animals {

    public String getEmitSound() {
        return emitSound;
    }

    public void setEmitSound(String emitSound) {
        this.emitSound = emitSound;
    }
    String emitSound;

    public String getFunction() {
        return function;
    }

    public void setFunction(String function) {
        this.function = function;
    }

    String function;
    public void TestAnimals() {
        System.out.println("Sound: " + emitSound);
        System.out.println("Function: " + function);
}}

Classe Cat

package br.com.diego.Animals;

public class Cat extends Animals {
//    Cat cat = new Cat();
    String emitSound = "Meow";
    String function = "Scratch the furniture";

    @Override
    public void setEmitSound(String Meow) {
        super.setEmitSound(emitSound);
    }

    @Override
    public String getEmitSound() {
        return super.getEmitSound();
    }
}

Classe Dog

package br.com.diego.Animals;

public class Dog extends Animals {
//    Dog dog = new Dog();
    String emitSound = "Woof";
    String function = "Move tail";

    @Override
    public void setEmitSound(String Woof) {
        super.setEmitSound(emitSound);
    }

    @Override
    public String getEmitSound() {
        return super.getEmitSound();
    }
}

Classe Test Animals

package br.com.diego.Animals;

import org.w3c.dom.ls.LSOutput;

public class TestAnimals extends Animals {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.setEmitSound("Woof");
        System.out.println("Dog's noise is: " + dog.emitSound);
        System.out.println("Dog's function is: " + dog.function);
        Cat cat = new Cat();
        cat.setEmitSound("Meow");
        System.out.println("Cat's noise is: " + cat.emitSound);
        System.out.println("Cat's function is: " + cat.function);
    }
}
2 respostas
**Pacote Vehicles**
**Classe Car**

`package br.com.diego.vehicles;

public class Car { String model; int yearOfRelease;

public String getModel() {
    return model;
}

public void setModel(String model) {
    this.model = model;
}

public int getYearOfRelease() {
    return yearOfRelease;
}

public void setYearOfRelease(int yearOfRelease) {
    this.yearOfRelease = yearOfRelease;
}

public int getAveragePrice() {
    return averagePrice;
}

public void setAveragePrice(int averagePrice) {
    this.averagePrice = averagePrice;
}

int averagePrice;

    public void showSpecs() {
        System.out.println("Model: " + model);
        System.out.println("Average price: " + averagePrice);
        System.out.println("Year of Release: " + yearOfRelease);
}

}

Classe Main

package br.com.diego.vehicles;

public class Main {
    public static void main(String[] args) {

        Car newCar = new Car();
        newCar.setModel("Ford T");
        newCar.setAveragePrice(250);
        newCar.setYearOfRelease(1910);
        newCar.showSpecs();

        Car otherCar = new Car();
        otherCar.setModel("Hyundai");
        otherCar.setYearOfRelease(2023);
        otherCar.setAveragePrice(120000);

        otherCar.showSpecs();
    }
}

Classe Test Drive (queria rodar os códigos ShowSpecs aqui, mas não consegui, só retorna 0 e null)

package br.com.diego.vehicles;

public abstract class TestDrive extends Main {
    public static void main(String[] args) {

}}
solução!

Oi Diego, tudo bem?

Obrigada muito por compartilhar o código! É notável ver seu comprometimento em praticar e aprimorar suas habilidades de programação. Parabéns pela iniciativa de trabalhar com classes e herança para representar diferentes animais e veículos.

A organização do código está bastante clara, e é encorajador ver o uso adequado de conceitos como herança, sobreposição de métodos e encapsulamento. Além disso, a estruturação dos pacotes demonstra uma boa prática de organização.

Um abraço e bons estudos.