Witam,
poniższy kod chciałbym zmodyfikować w taki soposób, żeby stworzyć nową metodę w klasie UserValidator (validator(User user)) i wywołać w niej dwie pozostałe metody (validateName, validateAgeAndHeight) za pomocą obiektu user przekazanego w metodzie .Ma ktoś jakiś pomysł?
Obecnie wyskakuje błąd o treści :
method validateName in class UserValidator cannot be applied to given types; required: java.lang.String found: no arguments reason: actual and formal argument lists differ in length, line 24
method validateAgeAndHeight in class UserValidator cannot be applied to given types; required: double,double found: no arguments reason: actual and formal argument lists differ in length, line 25
class UserValidator
{
public boolean validateName(String name) {
if(name != null) {
return true;
} else {
return false;
}
}
public void validateAgeAndHeight(double age, double height) {
if(age > 30 && height > 160) {
System.out.println("User is older than 30 and higher than 160cm");
} else {
System.out.println("User is younger than 30 and smaller than 160cm");
}
}
public void validator(User user) {
this.validateName();
this.validateAgeAndHeight();
}
}
class User {
private String name;
private int age;
private double height;
public User(String n, int a, double h) {
name = n;
age = a;
height = h;
}
public String getName() {
return name;
}
public double getAge() {
return age;
}
public double getHeight() {
return height;
}
}
class Application {
public static void main(String[] args) {
User user = new User("Adam", 40, 178);
UserValidator validator = new UserValidator();
boolean hasName = validator.validateName(user.getName());
if(hasName) {
validator.validateAgeAndHeight(user.getAge(), user.getHeight());
}
}
}