Question

In: Computer Science

Convert the following UML diagram into the Java code. Write constructor, mutator and accessor methods for...

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.      

Solutions

Expert Solution

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());
    }
}


Related Solutions

1.) According to the UML Class Diagram, these are the mutator and accessor methods that you...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you need to define: 1a.) +setName(value:String):void 1b.) +setGPA(value:double):void 1c.) +setID(value: String):void 1d.) +getName(): String 1e.) +getLastName():String 2.) Working with constructors 2a.) +Student() : This is the default constuctor. For the Strings properties, initialize them to null. The order is String ID, String name, String lastName, and double GPA. 2b.) +Student(value:String) - This constructor receives just the ID. 2c.) +Student(value:String, var: String) - This constructor receives...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence; Message() { sentence=""; } Message(String text) { setSentence(text); } void setSentence(String text) { sentence=text; } String getSentence() { return sentence; } int getVowels() { int count=0; for(int i=0;i<sentence.length();i++) { char ch=sentence.charAt(i); if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { count=count+1; } } return count; } int getConsonants() { int count=0; for(int i=0;i<sentence.length();i++)...
Java Write a Payroll class as demonstrated in the following UML diagram. Member variables of the...
Java Write a Payroll class as demonstrated in the following UML diagram. Member variables of the class are: NUM_EMPLOYEES: a constant integer variable to hold the number of employees. employeeId. An array of integers to hold employee identification numbers. hours. An array of integers to hold the number of hours worked by each employee payRate. An array of doubles to hold each employee’s hourly pay rate wages. An array of seven doubles to hold each employee’s gross wages The class...
Implement the constructor, accessor (getter) and mutator (setter) methods indicated in the comments below for the...
Implement the constructor, accessor (getter) and mutator (setter) methods indicated in the comments below for the following class Player. public class PlayerTester { public static void main(String[] args) { Player p = new Player("John Adam"); p.addScore(70); p.addScore(80); System.out.println("Average score is " + p.averageScore()); } } public class Player { private String name; private double totalScore; private int gamesPlayed; //constructor with one parameter for the player name - 2 points //Three accessor methods: getName(), getTotalScore(), getGamesPlayed() - 2 points each //One...
Please perform reverse engineering to compose a UML class diagram for the provided java code /*...
Please perform reverse engineering to compose a UML class diagram for the provided java code /* Encapsulated family of Algorithms * Interface and its implementations */ public interface IBrakeBehavior { public void brake(); } public class BrakeWithABS implements IBrakeBehavior { public void brake() { System.out.println("Brake with ABS applied"); } } public class Brake implements IBrakeBehavior { public void brake() { System.out.println("Simple Brake applied"); } } /* Client that can use the algorithms above interchangeably */ public abstract class Car {...
Please write code in java and comment . thanksItem classA constructor, with a String...
Please write code in java and comment . thanksItem classA constructor, with a String parameter representing the name of the item.A name() method and a toString() method, both of which are identical and which return the name of the item.BadAmountException ClassIt must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it.It must have a default constructor.It must have a constructor which...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
Please write code in java and comment . thanks Item class A constructor, with a String...
Please write code in java and comment . thanks Item class A constructor, with a String parameter representing the name of the item. A name() method and a toString() method, both of which are identical and which return the name of the item. BadAmountException Class It must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it. It must have a default...
A simple way to write the code to convert millileters to ounces in java
A simple way to write the code to convert millileters to ounces in java
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor...
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor should take the name of a file as an argument A method save (String line): This method should open the file defined by the constructor, save the string value of line at the end of the file, and then close the file. - In the same package create a new Java class and it DisplayFile in which write the following: Constructor: The class's constructor...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT