Java eigne Klasse (Bücher ausleihen)?

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?

Bild zum Beitrag
programmieren, Java, Informatik

In C: Celsius in Fahrenheit?

Moin,

ich habe ein Programm geschrieben, welches Celsius in Fahrenheit umrechnet. Jedoch bekomme ich nicht die richtigen Ergebnisse, da ich ja rein theoretisch die Ergebnisse der Rechnung (Formel für Umrechnung: Temp(in Celsius) * 9/5 + 32 in einer float-Variable speichern müsste, oder?

Hier meine Header:

#ifndef TEMPERATURE
#define TEMPERATURE

#define MAX_LENGTH 10

#define converter(c)((c * (9 / 5)) + 32)

double output_temperatures(double temp[]);
int string_length(double temp[]);
double widening(double temp2[]);
/* double appendix(double temp3[], temp4[]); */

#endif

Hier meine Funktionen:

#include "aufgabe2930b.h"
#include <stdio.h>

double output_temperatures(double temp[])
{
  int i;
  printf("Temperaturen in Fahrenheit: ");

  for (i = 0; i < string_length(temp); ++i) {
    if (temp[i] <= 100 && temp[i] >= -273.15) {
      printf("%f  ", converter(temp[i]));
    }
    else {
      printf("Falsche Eingabe! ");
      break;
    }
  }

  printf("\n");
  return 0;
}

int string_length(double temp[])
{
  int i = 0;
  int length = 0;

  while (temp[i] != '\0') {
    ++length;
    ++i;
  }

  return length;
}

double widening(double temp[])
{
  int i = 0;

  while (i < MAX_LENGTH - 1) {
    if (temp[i] == '\0') {
      printf("Bitte anzuhängende Temperatur eingeben: ");
      scanf("%lf", &temp[i]);
      temp[i + 1] = '\0';
      break;
    }
    else {
      ++i;
    }
  }

  for (i = 0 ; i < string_length(temp); ++i) {
    if (temp[i] <= 100 && temp[i] >= -273.15) {
      printf("%f  ", converter(temp[i]));
    }
    else {
      printf("Falsche Eingabe! ");
      break;
    }
  }

  return 0;
}

Hier meine main:

#include <stdio.h>
#include "aufgabe2930b.h"

int main(void)
{
  double temp[MAX_LENGTH] = { 1, 2 };
  output_temperatures(temp);
  widening(temp);

  return 0;
}
Temperatur, programmieren, Informatik
Weitere Inhalte können nur Nutzer sehen, die bei uns eingeloggt sind.