In: Computer Science
Convert the following UML diagram into the Java code. Write constructor, mutator and accessor methods for the given class. Create an instance of the class in a main method using a Practice class.
Note: The structure of the class can be compiled and tested without having bodies for the methods. Just be sure to put in dummy return values for methods that have a return type other than void.
public class Player {
private String name;
private int level;
private float Ext;
private float money;
public Player() {
}
public Player(String name, int level, float ext, float money) {
this.name = name;
this.level = level;
Ext = ext;
this.money = money;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public float getExt() {
return Ext;
}
public void setExt(float ext) {
Ext = ext;
}
public float getMoney() {
return money;
}
public void setMoney(float money) {
this.money = money;
}
public static void main(String[] args) {
Player player = new Player();
player.setLevel(7);
player.setName("Ronaldo");
player.setExt(23.0f);
player.setMoney(220000.0f);
System.out.println("Name: " + player.getName());
System.out.println("Level: " + player.getLevel());
System.out.println("Money: " + player.getMoney());
System.out.println("Ext: " + player.getExt());
}
}
