Answer:
Here is the Tile class:
class Tile { //class name
// declare private data members of Tile class
private int value; //int type variable to hold the integer
private String letter; //String type variable to hold the letter
public void setValue(int value){ //mutator method to set the integer value
this.value = value; }
public void setLetter(String letter){ //mutator method to set the letter
this.letter = letter; }
public int getValue() //accessor method to access or get the value
{return value;} //returns the current integer value
public String getLetter() //accessor method to access or get the letter
{return letter;} //returns the current string value
public Tile(String letter, int value){ //constructor that takes parameters named letter and value
setValue(value); //uses setValue method to set the value of value field
setLetter(letter); } } //uses setValue method to set the value of letter field
/* you can also use the following two statements inside constructor to initializes the variables:
this.letter = letter;
this.value = value; */
Step-by-step explanation:
Here is the driver class named Main:
public class Main{ //class name
public static void main(String[] args) { //start of main method
Tile tile = new Tile("Z", 10); //creates object of Tile class named tile and calls Tile constructor to initialize the instance variables
printTile(tile); } //calls printTile method by passing Tile object as a parameter
public static void printTile(Tile tile) { //method to displays the instance variables (letter and value) in a reader-friendly format
System.out.println("The tile " + tile.getLetter() + " has the score of " + tile.getValue()); } } //displays the string letter and integer value using getLetter() method to get the letter and getValue method to get the value
The screenshot of the output is attached.