Respuesta :
Answer:
Here is the Coin class:
public class Coin { //class names
private int value; // private member variable of type int of class Coin to store the value
private String coinName; // private member variable of type String of class Coin to store the coint name
private double weight; //private member variable of type double of class Coin to store the weight
public void setValue (int v) { //mutator method to set the value field
value = v; }
public void setName(String n){ //mutator method to set coinName field
coinName = n;}
public void setWeight (double w) { //mutator method to set weight field
weight = w; }
public int getValue () { //accessor method to get the value
return value; } // returns the current value
public String getName () { //accessor method to get the coin name
return coinName; } //returns the current coin name
public double getWeight () { //accessor method to get the weight
return weight; } } //returns the current weight
Explanation:
Here is the Main.java
public class Main{ //class name
public static void main(String[] args) { //start of main method
Coin penny = new Coin(); //creates object of Coin class called penny
penny.setName("Penny"); //calls setName method of Coin using object penny to set the coinName to Penny
penny.setValue(1); //calls setValue method of Coin using object penny to set the coin value to 1
penny.setWeight(0.003); //calls setWeight method of Coin using object penny to set the coin weight to 0.003
System.out.println("Coin name: " + penny.getName()); // calls getName method of Coin using penny object to get the current coin name stored in coinName field
System.out.println("Coin value: " + penny.getValue()); // calls getValue method of Coin using penny object to get the coin value stored in value field
System.out.println("Coin weight: " +penny.getWeight()); }} // calls getWeight method of Coin using penny object to get the coin weight stored in weight field
The value of coinName is set to Penny, that of value is set to 1 and that of weight is set to 0.003 using mutator method and then the accessor methods to access these values and prinln() to display these accessed values on output screen. Hence the output of the entire program is:
Coin name: Penny Coin value: 1 Coin weight: 0.003
The screenshot of the program along with its output is attached.
