Develop a Java application which implements an application for a store chain tha
ID: 3728778 • Letter: D
Question
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.
Hints:
Most of your classes should override the toString method. So, to print store items you should use the toString method.
To calculate promotionValue (i.e. price after promotionRate is applied), you need to implement this equation (price = price – price*promotionRate).
PromotionRate for book items is 0.8, and for movie items is 0.5. There is no promotionRate for music items.
To calculate total price including taxes, you need to implement this equation (price = price + price*taxRate).
TaxRate for book items is 0.2, taxRate for multimedia items is 0.25.
The interface IPromotion and part of the code for class Lookup are provided below.
public interface IPromotion {
/**
* This method is called by the getPrice methods for Book
* and Movie classes.
* @return promotion value which is 0.8 for Book item
* and 0.5 for movie item
*/
public double salesPromotion();
}
public class Lookup{
public User[] userList;
public Item[] storeItemList;
public Lookup() {
userList = createUsers();
storeItemList = loadItems();
}
/**
*
* @param userName
* @param password
* @return Return the user object it it exist
*/
public User checkLoginAuth(String userName, String password) {
}
public User[] getUserList() {
}
public void setUserList(User[] userList) {
}
public Item[] getStoreItemList() {
}
public void setStoreItemList(Item[] mStoreItemList) {
}
/**
* This method adds two users to the user list,
* "You should not change these users, but you
* can add new users
*/
public User[] createUsers() {
User[] list = new User[2];
list[0] = new User(1, "sara", "123");
list[1] = new User(2, "adam", "321");
return list;
}
/**
* This method load data to the item list, this list has all the
* items in your application "You should not change these data
* but you can add new items".
*
*/
public Item[] loadItems() {
Item[] itemList = new Item[5];
String[] languages = new String[2];
languages[0] = "English";
languages[1] = "Arabic";
itemList[0] = new Book(1, "Engineering Analysis with SOLIDWORKS Simulation 2017",
"SDC Publications", " Engineering Analysis with SOLIDWORKS Simulation 2017"
+ " goes beyond the standard software manual."
+ " Its unique approach concurrently introduces you to the SOLIDWORKS"
+ " Simulation 2017 software and the fundamentals of Finite Element Analysis"
+ " (FEA) through hands-on exercises. A number of projects are presented"
+ " using commonly used parts to illustrate the analysis features of "
+ " SOLIDWORKS Simulation. Each chapter is designed to build on the skills, "
+ " experiences and understanding gained from the previous chapters.",
false, 10, 578, "Paul Kurowski", "9781630570767", languages);
itemList[1] = new Book(2, "SQL Queries for Mere Mortals",
"Addison-Wesley Professional",
" SQL Queries for Mere Mortals ® has earned worldwide praise "
+ " as the clearest, simplest tutorial on writing effective SQL queries."
+ " The authors have updated this hands-on classic to reflect new "
+ " SQL standards and database applications and teach valuable new techniques." +
" Step by step, John L. Viescas and Michael J. Hernandez guide you through "
+ " creating reliable queries for virtually any modern SQL-based database. "
+ " They demystify all aspects of SQL query writing, from simple data selection"
+ " and filtering to joining multiple tables and modifying sets of data.",
true, 0, 792, "John L. ViescasMichael J. Hernandez", "9780133824841", languages);
itemList[2] = new Movie(101, "Smurfs: The Lost Village", "Dupuis",
" Fully animated with new characters looking like the original"
+ " Peyo's animation. This film will answer all of the questions "
+ " of the Smurfs such as "Why do the Smurfs live in "
+ " sara mushrooms?" and "Why don't the Smurfs wear shirts?"",
false, 20, 89, "English", "Animation");
itemList[3] = new Movie(101, "Black Panther", "Ryan Coogler",
" After the death of his father, the king of Wakanda,"
+ " young T’Challa returns home to the isolated high-tech "
+ " African nation to succeed to the throne and take his rightful"
+ " place as king. But when a powerful enemy reappears,"
+ " T’Challa’s mettle as king – and Black Panther – is tested when"
+ " he’s drawn into a formidable conflict that puts the fate of"
+ " Wakanda and the entire world at risk.",
false, 20, 89, "English", "Action & Adventure");
itemList[4] = new Music(201,
"Le rossignol", "Modest Mussorgsky",
" 1-The Nutcracker (Suite), Op.71a: 3. Waltz of the Flowers" +
" 2- The Nutcracker (Suite), Op.71a: 2b. Dance of the Sugar Plum Fairy"+
" 3- Prelude in C Major, Op. 12, No. 7",
false, 2, 4, "MP3", "Russian Album");
return itemList;
}
/**
* Print Movie list from storeItemList
*/
public void printMovieList() {
}
/**
* Print Books list from storeItemList
*/
public void printBookList() {
}
/**
* Print Music list from storeItemList
*/
public void printMusicList() {
}
/**
* This method searches for the item by its key
* and then return the item object if the item exist
* else return null
*/
public Item getItemById(int key) {
}
}
Explanation / Answer
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 +" 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);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.