Student information system
I'm new to setters and getters so I have no idea what's going on here. This code is supposed to print "Invalid age" if age entered < 0. Then it's supposed to set the age attribute to 0. import java.util.Scanner; class Main { 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 student.age = age; if (age < 0){ System.out.println("Invalid age"); } System.out.println("Name: " + student.name); System.out.println("Age: " + student.getAge()); } } class Student { public String name; public int age; public int getAge() { //complete Getter return age; } public void setAge(int age) { //complete Setter this.age = 0; }