The class below describes an Instrument, perhaps to keep track of inventory at a
ID: 3677929 • Letter: T
Question
The class below describes an Instrument, perhaps to keep track of inventory at a store. Write a child class- you can choose the class. Add at least one instance data variable and include all appropriate methods. The class should also implement the Breakable interface, shown below.
public abstract class Instrument {
private double price;
public Instrument(double price) {
this.price = price;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
if(price > 0 ) {
this.price = price;
}
}
public abstract void tune();
}
public interface Breakable {
void careIntructions();
}
Explanation / Answer
java program:
import java.io.*;
abstract class Instrument {
private double price;
public Instrument(double price) {
this.price = price;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
if(price > 0 ) {
this.price = price;
}
}
public abstract void tune();
}
interface Breakable {
public void careIntructions();
}
class InstrumentChild extends Instrument implements Breakable
{
public InstrumentChild(double price)
{
super(price);
}
public void careIntructions()
{
System.out.println("Instrument Cleaning and Maintenance");
}
public void tune()
{
System.out.println("adjusting the pitch of one or many tones from musical instruments");
}
}
public class InstrumentTest {
public static void main(String []args)throws IOException
{
InstrumentChild ins1=new InstrumentChild(6000.25);
System.out.println("Instrument 1 price "+ins1.getPrice());
ins1.setPrice(5555.55);
System.out.println("Instrument 1 price after setting new one "+ins1.getPrice());
System.out.println("tune:");
ins1.tune();
System.out.println("care instruction");
ins1.careIntructions();
}
}
output:
run:
Instrument 1 price 6000.25
Instrument 1 price after setting new one 5555.55
tune:
adjusting the pitch of one or many tones from musical instruments
care instruction
Instrument Cleaning and Maintenance
BUILD SUCCESSFUL (total time: 0 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.