12.6k views
0 votes
Write a class called MonetaryCoin that is derived from the Coin class presented in Chapter 5 (the source code for Chapter 5 examples is available via Moodle). [6 pts] Store one integer and one float in the MonetaryCoin that represent its value and weight in grams, respectively. Add a third variable of your choice (related to a coin, of course) and use self-descriptive variable names for all three variables. Pass the values to the constructor in MonetaryCoin and save them to your variables.

User Beier
by
5.2k points

1 Answer

5 votes

Answer:

Step-by-step explanation:

The following Java code creates the MonetaryCoin class that extends the Coin class. It then creates three variables representing the MonetaryCoin object which are its value, weight, and coinYear. These are all passed as arguments to the constructor and saved as instance variables.

public class MonetaryCoin extends Coin {

int value;

float weight;

int coinYear;

public void MonetaryCoin(int value, float weight, int coinYear) {

this.value = value;

this.weight = weight;

this.coinYear = coinYear;

}

}

User Dlm
by
5.0k points