Finish the Java code: Code: class Tile { char letter; int value; //Constructor Tile(char l, int v) { letter = l; value = v; } //The function returns value of data member value. public int getValue() { return value; } //The function returns value of data member letter. public char getLetter() { return letter; } //the function return string for value and letter public String toString() { return(letter + " with value " + value); } //The function checks for equality of two objects. public boolean equals(Tile t) { if(this.letter == t.letter && this.value == t.value) return true; else return false; } } Output: The word HELLO is worth 8 points Its tile with the highest value is: H with value: 4 You have used a total of 5 tiles so far.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Finish the Java code:
Code:
class Tile
{
char letter;
int value;
//Constructor
Tile(char l, int v)
{
letter = l;
value = v;
}
//The function returns value of data member value.
public int getValue()
{
return value;
}
//The function returns value of data member letter.
public char getLetter()
{
return letter;
}
//the function return string for value and letter
public String toString()
{
return(letter + " with value " + value);
}
//The function checks for equality of two objects.
public boolean equals(Tile t)
{
if(this.letter == t.letter && this.value == t.value)
return true;
else
return false;
}
}
Output:
The word HELLO is worth 8 points
Its tile with the highest value is:
H with value: 4
You have used a total of 5 tiles so far.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images