1
resposta

Resolução

Abaixo as soluções que cheguei.

A classe Main contem todas as instancias.

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

        // EXERCICIO PESSOA
        Pessoa humano = new Pessoa();
        humano.salutation();
        //----------*******************-----------

        // EXERCICIO MUSICA
        Musica faixaMusical = new Musica();
        faixaMusical.artist = "O Rappa";
        faixaMusical.title = "Rodo Cotidiano";
        faixaMusical.releaseYear = 2003;
        faixaMusical.evaluateMovie(9);
        faixaMusical.evaluateMovie(8.5);
        faixaMusical.evaluateMovie(9.3);
        faixaMusical.evaluateMovie(9.8);
        faixaMusical.displayDatasheet();
        //----------*******************-----------

        //EXERCICIO CALCULADORA
        Calculadora novaCalculadora = new Calculadora();
        int userInput = novaCalculadora.newNumber();
        int result = novaCalculadora.calculateDouble(userInput);
        System.out.println("O dobro do número escolhido é: " + result + "\n");
        //----------*******************-----------

        //EXERCICIO CARRO
        Carro novoCarro = new Carro();
        novoCarro.model = "Ferrari";
        novoCarro.year = 2020;
        novoCarro.color = "Vermelha";
        novoCarro.displayDatasheet();
        System.out.println("A idade do veículo é: " + novoCarro.calculateAge() + "\n");
        //----------*******************-----------

        //EXERCICIO ALUNO
        Aluno novoAluno = new Aluno();
        novoAluno.name = "Caio";
        novoAluno.age = 1;
        novoAluno.displayDatasheet();
        //----------*******************-----------

    }

}
public class Pessoa {
    void salutation () {
        System.out.println("Olá mundo!!\n");
    }
}
import java.util.Scanner;

public class Calculadora {
    String systemMessage;

    int newNumber () {
        Scanner scanner = new Scanner(System.in);
        systemMessage = "Digite um numero inteiro qualquer: ";
        System.out.println(systemMessage);
        return scanner.nextInt();
    }


    int calculateDouble (int userNumber) {
        return userNumber * 2;
    }
}
public class Musica {
    String systemMessage;
    String title;
    String artist;
    int releaseYear;
    int totalRatings;
    double sumOfReviews;

    void displayDatasheet () {
        systemMessage = """
                Título: %s
                Artista: %s
                Ano de Lançamento: %s
                Avaliação: %s
                Total de Avaliações: %s
                """.formatted(title, artist, releaseYear, ratingAverage(), totalRatings + "\n");
        System.out.println(systemMessage);
    }

    void evaluateMovie (double rating) {
        sumOfReviews += rating;
        totalRatings++;
    }

    String ratingAverage() {
        if (totalRatings > 0) {
            return String.format("%.1f\n", sumOfReviews / totalRatings).replace("\n", "");
        } else {
            return "0.0";
        }
    }
}
import java.time.LocalDate;

public class Carro {
    String model;
    int year;
    String color;
    String systemMessage;

    void displayDatasheet () {
        systemMessage = """
                Modelo: %s
                Cor: %s
                Ano: %s
                """.formatted(model, color, year);
        System.out.println(systemMessage);
    }

    int calculateAge () {
        LocalDate today = LocalDate.now();
        int currentYear = today.getYear();
        return currentYear - year;
    }
}
public class Aluno {
    String name;
    int age;
    String systemMessage;

    void displayDatasheet () {
        systemMessage = """
                Nome: %s
                Idade: %s
                """.formatted(name, age);
        System.out.println(systemMessage);
    }

}
1 resposta

Oi, Rodrigo! Tudo bem?

Ótimo código! Espero que continue a explorar os conteúdos para ampliar seu conhecimento e desenvolver novas habilidades. Caso tenha restado alguma dúvida em relação a qualquer conteúdo do curso ou atividade, não hesite em perguntar, estou disponível e ficarei super feliz em poder ajudar!

Um forte abraço e bons estudos!