Beggning of java Use inheritance with the Product application modify the Product
ID: 3786918 • Letter: B
Question
Beggning of java
Use inheritance with the Product application
modify the Product application so it provides for an additional kind of product: a music album. When you enter the code for a music album, it should look like this:
Enter product code sgtp
Description Sgt. Peppers(The Beatles)
Price $14.99 Product count 1
Create a new subclass named Album
I. Import the project named ch 11-ex l-Product that's in the ex-starts folder. Then, review the code.
2. In the murach business package, create a new class named Album that inherits the Product class. This new class should store data about the artist of the album. In addition, its toString method should append the name of the artist to the end of the string
Modify the ProductDB class so it returns an Album object
3. Modify the ProductDB class so it creates at least one Album object.
4. Run the application to make sure that it works correctly.
Modify the protected variable
5, open the Product class and delete the protected access modifier for the count variable. This restricts the availability of this variable even further, making it only available to the other classes in the current package.
6 Run the application to make sure that the count is maintained properly.
I want the code for this the product application code please
Explanation / Answer
import java.util.*;
import java.io.*;
class Product {
public String code;
public String desc;
public double price;
protected int count;
}
class Album extends Product {
String artist;
public void Album() {
this.code=this.desc=null;
this.price=0.0;
this.count=0;
}
public void setProduct(String cd, String ds, double pr, int cn) {
this.code=cd;
this.desc=ds;
this.price=pr;
this.count=cn;
}
public void setArtist(String ar) {
this.artist=ar;
}
}
public class ProductDB {
public static void main(String args[]) {
Album temp=returnObject();
System.out.println(temp.code);
}
public static Album returnObject() {
Album myAlbum=new Album();
myAlbum.setProduct("abcd","abcdwxyz",12.0,1);
myAlbum.setArtist("myname");
return myAlbum;
}
}
/*
aaabcdec
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.