Eu fiz da seguinte forma:
public class BankAccount {
private int accountNumber;
private double balance;
public String holder;
public int getAccountNumber() {
return accountNumber;
}
public double getBalance() {
return balance;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
public void setBalance(double balance) {
this.balance = balance;
}
}
public class PersonAge {
private String name;
private int age;
public String systemMessage;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void testAge() {
if (age >= 18) {
systemMessage = """
ATENÇÃO: O usuário %s é MAIOR de idade
""".formatted(name);
System.out.println(systemMessage);
} else {
systemMessage = """
ATENÇÃO: O usuário %s é MENOR de idade
""".formatted(name);
System.out.println(systemMessage);
}
}
}
public class Product {
private String productName;
private double price;
public String getProductName () {
return productName;
}
public double getPrice () {
return price;
}
public void setProductName (String productName) {
this.productName = productName;
}
public void setPrice (double price) {
this.price = price;
}
public double discount (double percentage) {
double discount = price * (percentage / 100);
price -= discount;
return discount;
}
}
public class Student {
private String studentName;
private double[] studentNotes;
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public void setStudentNotes(double[] studentNotes) {
this.studentNotes = studentNotes;
}
public String getStudentName() {
return studentName;
}
public double[] getStudentNotes() {
return studentNotes;
}
public double calculateAverage () {
if (studentNotes.length == 0) {
return 0;
}
double total = 0;
for (double notes: studentNotes) {
total += notes;
}
return total / studentNotes.length;
}
public int numberOfNotes () {
if (studentNotes.length == 0) {
return 0;
} else {
return studentNotes.length;
}
}
}
public class Book {
private String titleBook;
private String authorBook;
public void setTitleBook(String titleBook) {
this.titleBook = titleBook;
}
public void setAuthorBook(String authorBook) {
this.authorBook = authorBook;
}
public String getTitleBook() {
return titleBook;
}
public String getAuthorBook() {
return authorBook;
}
public void displayDetails () {
String systemMessage;
systemMessage = """
Nome do Livro: %s
Autor do Livro: %s
""".formatted(getTitleBook(), getAuthorBook());
System.out.println(systemMessage);
}
}