Hi, also ich soll eine Klasse erstellen nach folgenden Kriterien:
Erstmal sry für den vielen Text, wollte nicht , dass durch das Zusammenfassen mögliche wichtige Informationen verloren gehen ;)
Nun sieht mein Ansatz bis jetzt so aus:
public class Book {
private String author;
private String title;
private LocalDate returnDate;
private String status;
public Book(String author, String title, String Status) throws IllegalArgumentException{
setAuthor(author);
setTitle(title);
setReturnDate(returnDate);
setStatus(status);
}
private static boolean checkAuthor(String author){
return (author.matches("[a-zA-ZäÄöÖüÜß ]") && author.length() >= 2);
}
private static boolean checkTitle(String title){
return (title.length() >= 1 && title.length() < 10);
}
public static boolean checkReturnDate(LocalDate returnDate){
return ( );
}
public static boolean checkStatus(String status){
return (status.equals("rent") || status.equals("not rent"));
}
public final void setAuthor(String author) throws IllegalArgumentException{
if(!checkAuthor(author)){
throw new IllegalArgumentException("author not valid: "+ author);
}
this.author = author;
}
public final void setTitle(String title) throws IllegalArgumentException{
if(!checkTitle(title)){
throw new IllegalArgumentException("title not valid: "+ title);
}
this.title = title;
}
private void setReturnDate(LocalDate returnDate) throws IllegalArgumentException{
if(!checkReturnDate(returnDate)){
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
throw new IllegalArgumentException("Return Date not valid: " + returnDate.format(dtf));
}
this.returnDate = returnDate;
}
private void setStatus(String status){
if(!checkStatus(status)){
throw new IllegalArgumentException("Status not valid:" + status);
}
this.status = status;
}
Mir fehlt noch eine Check Methode für LocalDate returnDate, hier bin ich nicht so ganz weiter gekommen.
Nun war meine Idee eine Unterklasse zu erstellen die von der Klasse Book erbt. In dieser soll dann der ganze Vorgang mit Ausleihen usw geschehen . Macht dies so Sinn?
Sollte ich dann returnDate erst in dieser erstellen?