assign6/Assignment6.docx Use inheritance and polymorphism to implement a Java application, called ShopingApplication. Each item that is sold by the store has the following attributes: code, price, and...

1 answer below »
This is very straight forward and will be easy. Should not take the expert more than 2 hours to complete. Use the java files in the zip file as examples to implement the requirement


assign6/Assignment6.docx Use inheritance and polymorphism to implement a Java application, called ShopingApplication. Each item that is sold by the store has the following attributes: code, price, and quantity. In the same time, items in the store are categorized into three categories where each category has another set of identifying attributes as explained below. Implementation Implement 7 classes as explained below. class SalesItem SalesItem is an abstract class that is defined by the following private instance variables: · code (type int) · price (type double) · quantity (type int). And the following methods: 1. A constructor that takes three input parameters to initialize the three instance variables. 2. Getters and setters for all the instance variables. 3. itemTotalCost: a method that returns the total cost of that item (i.e., price*quantity). 4. monthlyPromo: an abstract method that is used to apply a monthly discount to the item where the discount is dependent on the type of the item. 5. toString: a method that returns a String representation of the sales item. Class Book Book is a subclass of SalesItem such that, in addition to the SalesItem’s instance variables, a Book is also defined by the following instance variables: · author (type String) · numPages (type int) And the following methods: 1. A constructor that takes five input parameters to initialize all the instance variables. 2. Setter and getter methods for the book's additional instance variables. 3. An implementation of the monthlyPromo method where, for a book, a price reduction of 3% is applied each month. 4. Override the toString method from the SalesItem class to add the book's specific instance variables to the output string. class Dictionary Dictionary is a subclass of Book and it extends the Book class by adding the following instance variables: · language (type String) · numDefinitions (type int) And the following methods: 1. A constructor to initialize all the dictionary's instance variables. 2. Setter and getter methods for the additional instance variables. 3. Override the toString method from the Book class to include the additional instance variables in the output. 4. A method called getRatio that returns the number of definitions (on average) for each page in the dictionary (i.e., number of definitions divided by the number of pages). class AudioCD The AudioCD is a subclass of SalesItem by adding the following additional Instance variables: · label (type String) · playingTime (type int) And the following methods: 1. A constructor to initialize all the instance variables. 2. Setter and getter methods for artist, label and playing time. 3. An implementation of the monthlyPromo method where, for a CD, a price reduction of 5% is applied each month. 4. Override the toString methods to include the audio cd's specific instance variables. class Cart Cart is basically a collection class of SalesItem that is defined by the following two instance variables: · itemsList: an array of SalesItem · currentNumItems: the current number of items on the cart. And the following methods: 1. Cart’s constructor that takes as input an integer parameter that determines the maximum number of items that can be placed in the cart. The constructor then uses this number to create the itemsList array. 2. addItem: a method that takes one input parameter of type SalesItem as input and adds it to the itemsList array. 3. cartTotalCost: a method that returns the total cost of all items in the cart. 4. getAtIndex: a method that takes an input parameter of type integer that represents an array index and returns the SalesItem object that is located at this index in the itemsList array. 5. countType: a method that takes as input one integer that represents the type of items to be counted where 1 means Book, 2 means Dictionary, and 3 means AudioCD. The method then counts how many items of this type are there in the cart. For example, if the input is 1 and the cart has an item of type Book and quantity 2 then this adds 2 the output count. The method returns 0 for any input value other than 1,2, or 3. 6. toString: a method that prints a nicely formatted output of the cart where each item is printed in one line. The method also prints the cart's total cost. class ItemDiscount The ItemDiscount class is used to calculate the discount amount on a given sales item. The class has two instance variables: · discount: an integer value that represent the discount percent. For example, discount of 10 means 10% discount. · qualifiedQuantity: an integer value that represents the required quantity in order for the item to be qualified for discount. And the following two methods: 1. A constructor to initialize the two instance variables 2. calculateDiscount: a method that takes one input of type SalesItem. The method checks whether the item is qualified for discount or no. If the item is qualified, then the method returns a double value that represent amount of money to be deducted from the item. For example, assume the store would like to apply 10% discount if 5 or more entities of the same item are sold together. To implement that, the following ItemDiscount object created. ItemDiscount d = new ItemDiscount(10,5); Then, for each sales item, itm, the discount amount can be calculated as follows: d.calcualteDiscount(itm); class ShoppingDriver The driver class includes only the main method that does the following: 1. Instantiate a Cart Object that can hold up to 5 items. 2. Add one Book, one Dictionary, and one AudioCD to the cart. 3. Add two other items of your choice. 4. Display the cart. 5. Create an ItemDiscount class to apply 15% discount if 10 entities or more of any item are soled together. 6. Write a loop that loops over all items in the cart and does the following: · Apply the monthlyPromo method. · calculate and display the discount that will applied to each item, if any. 7. Display the total discount to be applied to the cart. 8. Display the total cart cost before and after the discount. assign6/Driver.java assign6/Driver.java public class Driver {     public static void main(String[] args) {         Employee[] staff = new Employee[3];         TaxInformation tax = new TaxInformation(2);                  staff[0] = new ProductionWorker("worker1",100,2,10);         staff[1] = new ProductionWorker("worker2",200,1,20);         staff[2] = new TeamLeader("leader",200,1,30,100);                  for (int i=0; i < staff.length; i++) {             =""             if (staff[i] instanceof productionworker)=""                 ((productionworker)staff[i]).addhours(20);=""             =""             system.out.println(staff[i].getmonthlysalary());=""             double emptax =" tax.calculateTax(staff[i]);"             system.out.println(emptax);=""         }=""         =""         system.out.println(equalsalary(staff[1],staff[2]));=""     }=""     =""     public static boolean equalsalary(employee e1, employee e2){=""         =""         return e1.getmonthlysalary() ="= e2.getMonthlySalary();" }="" }="" assign6/employee.java="" assign6/employee.java="" public abstract class employee extends object {=""     =""     private string name;=""     private int empid;=""     =""     =""     public employee(string name, int empid){=""         this.name =" name;"         this.empid =" empID;"     }=""     @override=""     public string tostring(){=""         =""         string outputstr =" "";"         =""         outputstr +=" this.name;"         outputstr +="\t" +this.empid;=""         =""         return outputstr;=""     }=""     =""     abstract public double getmonthlysalary();="" }="" assign6/productionworker.java="" assign6/productionworker.java="" public class productionworker extends employee {=""     =""     private int shift;=""     private double hourlyrate;=""     private int hoursworked;=""     =""     public productionworker(string name, int empid, int shift, double rate) {=""         =""         super(name,empid);=""         this.shift =" shift;"         this.hourlyrate =" rate;"         this.hoursworked =" 0;"     }=""     =""     public double getmonthlysalary() {=""         =""         double output =" this.hourlyRate*hoursWorked;"         =""         return output;=""     }=""     public void addhours(int hours) {=""         =""         this.hoursworked +=" hours;"     }=""     =""     @override=""     public string tostring(){=""         =""         string outputstr =" "";"         outputstr +=" super.toString();"         outputstr +=" "\t"+this.shift;"         outputstr +=" "\t"+this.hourlyRate;"         outputstr +=" "\t"+this.hoursWorked;"         outputstr +=" "\t"+this.getMonthlySalary();"         =""                 return outputstr;=""     }="" }="" assign6/shiftsupervisor.java="" assign6/shiftsupervisor.java="" public class shiftsupervisor extends employee{=""     private double annualsalary;=""     private double annualbonus;=""     =""     public  shiftsupervisor(string name, int empid, double annualsalary){=""         =""         super(name,empid);=""         this.annualsalary =" annualSalary;"     }=""     =""     public void addannualbonus(double bonus){=""         =""         this.annualbonus+=" bonus;"     }=""     =""     public void setannualbonus(double bonus){=""         =""         this.annualbonus=" bonus;"     }=""     @override=""     public double getmonthlysalary(){=""         =""         double salary =" 0;"         =""         salary =" (this.annualBonus + this.annualSalary)/12;"         =""         return salary;=""     }=""     =""     @override=""     public string tostring(){=""         =""         string outputstr =" "";"         outputstr +=" super.toString();"         outputstr +=" "\t"+this.annualSalary;"         outputstr +=" "\t"+this.annualBonus;"         =""         =""         =""         return outputstr;=""     }="" }="" assign6/taxinformation.java="" assign6/taxinformation.java="" public class taxinformation {=""     =""     private int basededuction;=""     =""     public taxinformation(int base) {=""         =""         this.basededuction =" base;"     }=""     =""     public double calculatetax(employee e) {=""         =""         double output =" 0;"         =""         double salary =" e.getMonthlySalary();"         ="">< 300)             output =" salary*this.baseDeduction*1.0/100;">< 500)             output = 2.0*salary*this.basededuction/100;         else                 output = 4.0*salary*this.basededuction/100;                           return output;     } } assign6/teamleader.java assign6/teamleader.java public class teamleader extends productionworker{     private double montlybonus;          public teamleader(string name, int empid, int shift, double hourlypayrate, double monthlybonus){         super(name,empid,shift,hourlypayrate);              this.montlybonus = monthlybonus;              }          public void addmonthlybonus(double bonus){                  this.montlybonus += bonus;     }          public void setmonthlybonus(double bonus){                  this.montlybonus = bonus;     }     @override     public double getmonthlysalary(){                  double salary = super.getmonthlysalary() + this.montlybonus;         return salary;     }     @override     public string tostring(){                  string outputstr = "";         outputstr += super.tostring();         outputstr += "\t"+this.montlybonus;                  return outputstr;     } }             output =" 2.0*salary*this.baseDeduction/100;"         else=""                 output =" 4.0*salary*this.baseDeduction/100;"         =""         =""         return output;=""     }="" }="" assign6/teamleader.java="" assign6/teamleader.java="" public class teamleader extends productionworker{=""     private double montlybonus;=""     =""     public teamleader(string name, int empid, int shift, double hourlypayrate, double monthlybonus){=""         super(name,empid,shift,hourlypayrate);=""     =""         this.montlybonus =" monthlyBonus;"         =""     }=""     =""     public void addmonthlybonus(double bonus){=""         =""         this.montlybonus +=" bonus;"     }=""     =""     public void setmonthlybonus(double bonus){=""         =""         this.montlybonus =" bonus;"     }=""     @override=""     public double getmonthlysalary(){=""         =""         double salary =" super.getMonthlySalary() + this.montlyBonus;"         return salary;=""     }=""     @override=""     public string tostring(){=""         =""         string outputstr =" "";"         outputstr +=" super.toString();"         outputstr +=" "\t"+this.montlyBonus;"         =""         return outputstr;=""     }="">
Answered Same DayApr 27, 2021

Answer To: assign6/Assignment6.docx Use inheritance and polymorphism to implement a Java application, called...

Valupadasu answered on May 01 2021
130 Votes
Assign6/.idea/codeStyles/codeStyleConfig.xml




Assign6/.idea/description.html
Simple Java application that includes a class with main() method
Assign6/.idea/encodings.xml




Assign6/.idea/misc.xml










Assign6/.idea/modules.xml






A
ssign6/.idea/project-template.xml

IJ_BASE_PACKAGE
Assign6/.idea/workspace.xml
































































1588301035439


1588301035439

































Assign6/Assign6.iml









Assign6/out/production/Assign6/AudioCD.class
public synchronized class AudioCD extends SalesItem {
private String label;
private int playingTime;
public String getLabel();
public void setLabel(String);
public int getPlayingTime();
public void setPlayingTime(int);
public void AudioCD(int, double, int, String, int);
public void monthlyPromo();
public String toString();
}
Assign6/out/production/Assign6/Book.class
public synchronized class Book extends SalesItem {
private String author;
private int numPages;
public String getAuthor();
public void setAuthor(String);
public int getNumPages();
public void setNumPages(int);
void Book(int, double, int, String, int);
public void monthlyPromo();
public String toString();
}
Assign6/out/production/Assign6/Cart.class
public synchronized class Cart {
SalesItem[] itemsList;
private int currentNumItems;
public SalesItem[] getItemsList();
public void setItemsList(SalesItem[]);
public int getCurrentNumItems();
public void setCurrentNumItems(int);
public void Cart(int);
public void addItem(SalesItem);
public double cartTotalCost();
public SalesItem getAtIndex(int);
public int countType(int);
public String toString();
}
Assign6/out/production/Assign6/Dictionary.class
public synchronized class Dictionary extends Book {
private String language;
private int numDefinitions;
public String getLanguage();
public void setLanguage(String);
public int getNumDefinitions();
public void setNumDefinitions(int);
public void Dictionary(int, double, int, String, int, String, int);
public double getRatio();
public String toString();
}
Assign6/out/production/Assign6/ItemDiscount.class
public synchronized class ItemDiscount {
private int discount;
private int qualifiedQuantity;
void ItemDiscount(int, int);
public double calculateDiscount(SalesItem);
}
Assign6/out/production/Assign6/META-INF/Assign6.kotlin_module
Assign6/out/production/Assign6/SalesItem.class
public abstract synchronized class SalesItem {
private int code;
private double price;
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here