EXE 1
public class ContaBancaria {
//variaveis
private int numeroConta;
private double saldo;
public String titular;
//getters e setters conta
public int getNumeroConta() {
return numeroConta;
}
public void setNumeroConta(int numeroConta) {
this.numeroConta = numeroConta;
}
//getters e setters saldo
public double getSaldo() {
return saldo;
}
public void setSaldo(double saldo) {
this.saldo = saldo;
}
//getters e setters titular
public String getTitular() {
return titular;
}
public void setTitular(String titular) {
this.titular = titular;
}
}
EXE 2
public class IdadePessoa {
// Variaveis
private String name;
private int age;
// getters e setters name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
// getters e setters age
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
// metodo
public void verificarIdade () {
if (age < 18) {
System.out.println(name + " é menor de idade");
} else
System.out.println(name + " é maior de idade");
}
}
EXE 3
public class Produto {
//Varivel
private String name;
private double price;
// getters e setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
//Metodo
public void applyDiscount (double percentage) {
if (percentage > 0 && percentage <= 100) {
double discount = price * (percentage / 100);
price -= discount;
System.out.println("Discount of " + percentage + "% applied. New price: " + price);
} else {
System.out.println("Invalid discount percentage!");
}
}}
EXE 4
public class Aluno {
// Variáveis
private String name;
private double[] grades;
// Getters e Setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double[] getGrades() {
return grades;
}
public void setGrades(double[] grades) {
this.grades = grades;
}
// Metodo
public double calcularMedia() {
double sum = 0.0;
if (grades == null || grades.length == 0) {
System.out.println("No grades registered!");
return 0;
}
// soma todas as notas
for (int i = 0; i < grades.length; i++) {
sum = sum + grades[i];
}
// calcula média
double average = sum / grades.length;
System.out.println("Student average: " + average);
return average;
}
}
EXE 5
public class Book {
// atributos
private String title;
private String author;
// setters e getters title
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
// setters e getters author
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
//metodo
public void exibirDetalhes() {
System.out.println("Title: " + title );
System.out.println("Author: " + author );
}
}