I built a football class and I want to take features like age from the user. How do I do this with objects?
package player; public class SoccerPlayer { private final String name = "Cristiano"; private final String family = "Ronaldo"; private int age; private int height; private int weight; public int sumGoals = 0; public static final int numberOfMatches = 5; private int[] goal = new int[numberOfMatches]; public void setAge(int age) { this.age = age; } public int getAge() { return age; } public SoccerPlayer(int h, int w) { if ((h >= 180 || h <= 190) && (w >= 70 || w <= 80)) { height = h; weight = w; } else System.out.println("Error"); } public void print() { System.out.println("_______________Player information_____________"); System.out.printf("Name: %s \nFamily: %s \n", name, family); System.out.printf("Height: %d \nWeight: %d \n", height, weight); } } ///////////////////////////////////////// package player; public class MainClass { public static void main(String[] args) { SoccerPlayer player = new SoccerPlayer(187,79); player.setAge(35); player.print(); System.out.println("Age:"+player.getAge()); } }
print
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)