Getters and Setters problem
Hello future programmers, im having difficulties whith the "Student Information System" problem. Cant make it print "Invalid age". Sorry for my bad english. public static void main(String[] args) { Scanner read = new Scanner(System.in); String name = read.nextLine(); int age = read.nextInt(); Student student = new Student(); student.name = name; //set the age via Setter System.out.println("Name: " + student.name); System.out.println("Age: " + student.getAge()); } } class Student { public String name; private int age; public int getAge() { //complete Getter return age; } public void setAge(int age) { //complete Setter if(age>0) { this.age= age; } else if(age<0){ System.out.println("Invalid age"); this.age =0; } } }