NOTE: The completed code must pass in the following compiler. Please make absolu
ID: 3576605 • Letter: N
Question
NOTE: The completed code must pass in the following compiler. Please make absolutely sure it does before posting: http://codecheck.it/codecheck/files?repo=jfe1cc&problem=ch09/c09_exp_9_102
PLEASE also make sure of the following:
-Post this as text, not as an image.
-Avoid making alterations to the original code unless necessary.
-Post the passing output- from the this compiler specifically- as evidence this code was accepted and passed.
~
Form a subclass Quarter from the class Coin. A quarter has a state theme.
(image included in link above)
The getDescription method should yield a string such as
Complete the following code:
The following classes are used to check your work:
Explanation / Answer
public class QuarterTester
{
public static void main(String[] args)
{
Coin c = new Quarter("Michigan");
System.out.println(c.getDescription());
System.out.println("Expected: Quarter, value=0.25, state=Michigan");
}
}
public class Quarter extends Coin
{
// your work here
private String state;
/**
Constructs a quarter.
@param aValue the monetary value of the quarter.
@param aName the name of the quarter
*/
public Quarter(String aState)
{
// your work here
super(0.25, "Quarter");
state = aState;
}
public String getDescription()
{
// your work here
return super.getDescription()+" state="+state;
}
}
/**
A coin with a monetary value.
*/
public class Coin
{
private double value;
private String name;
/**
Constructs a coin.
@param aValue the monetary value of the coin.
@param aName the name of the coin
*/
public Coin(double aValue, String aName)
{
value = aValue;
name = aName;
}
/**
Gets the coin value.
@return the value
*/
public double getValue()
{
return value;
}
/**
Gets the coin description.
@return a description of this coin
*/
public String getDescription()
{
return name + ", value=" + value;
}
}
Output:
Quarter, value=0.25 state=Michigan
Expected: Quarter, value=0.25, state=Michigan
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.