In: Computer Science
Develop a Java application which implements an application for a store chain that has three types of stores which are Book, Music, and Movie stores.
Your application should have an Item abstract class which should be extended by the Book and Multimedia classes. Item class has abstract priceAfterTax method, you need to implement this method in derived classes. Multimedia class is a superclass for Music and Movie classes. Your project should also include the IPromotion interface, which should be implemented by Book and Movie classes. Also, your application should have the Lookup class (which is provided in part in this document). Lookup class works as the datastore: it contains all the various items available - books, movies, music items - as well as the list of users.
In your main class you should initiate a lookup object in the main method. You also need to include a User class which has the fields and the methods shown for that class in the class diagram. User class has a library of items; once a user downloads or purchases any item, you should add this item to that user’s library. If the user just plays music or watches a movie you should not add this item to the user’s library.
abstract class Item
{
private String name;
private double price;
private double taxInPercentage;
public abstract double priceAfterTax();
public void download(User user)
{
user.library.add(this);
}
public static double totalPrice()
{
return price+((price)*taxi percentage)/100)
}
public String toString()
{
return "Name = "+name +"\t priceIncludingTax"+totalPrice();
}
}
interface Ipromotion
{
}
class Book extends Item implements Ipromotion
{
public Book(String name,double price,double taxInPercentage)
{
this.name= name;
this.price=price;
this.taxInPercentage=taxInPercentage;
}
public double priceAfterTax()
{
return totalPrice()
}
public Item download()
{
return this;
}
}
class Multimedia extends Item
{
public void play()
{
}
}
class Music extends Multimedia
{
public Book(String name,double price,double taxInPercentage)
{
this.name =name;
this.price=price;
this.taxInPercentage=taxInPercentage;
}
public double priceAfterTax()
{
return totalPrice()
}
}
class Movie extends Multimedia implements Ipromotion
{
public Book(String name,double price,double taxInPercentage)
{
this.name=name;
this.price=price;
this.taxInPercentage=taxInPercentage;
}
public double priceAfterTax()
{
return totalPrice()
}
}
class Lookup
{
public List<Book> books= new ArrayList<Book>();
books.add(new Book("Book1"),100,10));
books.add(new Book("Book2"),100,10));
public List<Movie> movies= new ArrayList<Movie>();
movies.add(new Movie("Movie1"),100,10));
movies.add(new Movie("Movie2"),100,10));
public List<Music> music= new ArrayList<Music>();
music.add(new Music("Music1"),100,10));
music.add(new Music("Music2"),100,10));
}
public class User
{
public static void main(String[] args) throws Exception
{
public List<Item> library= new ArrayList<Item>();
Lookup lookup = new Lookup();
lookup.books.get("Book1").download(this);
lookup.movies.get("Movie2").play();
lookup.music.get("Music1"). download (this);
System.out.println(library);
}
}