Can anyone help with this assignment I am okay with the conc
Can anyone help with this assignment? I am okay with the concepts....writing the actual code is a little harder for me. I will include my UML later today. Thanks!SS
Modify your Account superclass so that it is abstract and contains the abstract method, computeSales(). If you added default behavior in the earlier task for computeSales(), remove this default behavior.
Leave your implementation of computeSales() in the subclasses as:
Supplies = office supplies sold dollar amount + books sold dollar amount + apparel sold dollar amount
Services = number of hours * rate per hour.
Paper = number of pounds * price per pound
Update your design document so that the UML class diagrams reflect the abstract class and abstract method.
Modify your application so that it polymorphically processes any account objects created. Store each account object created into an array of type Account. For each element in this array, call the computeSales() method and display the results. Use the example of polymorphically processing employee objects in Chapter 10 as inspiration.
Test your application and verify your results. Take screenshots to demonstrate that your application works.
Intermediate-level Java programming should be demonstrated in your application:
There should be implemented constructors for each class.
The toString() method should be overridden to provide readable string representation of each object.
Getters and setters need to be implemented to enforce data hiding.
Code should be fully commented.
Program flow should be logical.
Behavior should be encapsulated into methods avoiding all encompassing large main() methods.
Solution
Account.java
public abstract class Account {
//Declaring Abstract method
public abstract void computerSales();
}
____________________________
Paper.java
public class Paper extends Account {
// Declaring instance variables
private int no_of_pounds;
private double price_per_pound;
// Parameterized constructor
public Paper(int no_of_pounds, double price_per_pound) {
super();
this.no_of_pounds = no_of_pounds;
this.price_per_pound = price_per_pound;
}
// Setters and getters
public int getNo_of_pounds() {
return no_of_pounds;
}
public void setNo_of_pounds(int no_of_pounds) {
this.no_of_pounds = no_of_pounds;
}
public double getPrice_per_pound() {
return price_per_pound;
}
public void setPrice_per_pound(double price_per_pound) {
this.price_per_pound = price_per_pound;
}
// toString() method which is used to display the contents of an object
@Override
public String toString() {
return \"\ ____Paper Object___\ No_of_pounds=\" + no_of_pounds+ \"\ Price_per_pound=\" + price_per_pound;
}
// This method will calculate and display total
@Override
public void computerSales() {
double total = getNo_of_pounds() + getPrice_per_pound();
System.out.println(\"Total :\" + total);
}
}
__________________________________
Services.java
public class Services extends Account {
// Declaring instance variables
private int no_of_hours;
private double rate_per_hour;
// Parameterized constructor
public Services(int no_of_hours, double rate_per_hour) {
super();
this.no_of_hours = no_of_hours;
this.rate_per_hour = rate_per_hour;
}
// Setters and getters
public int getNo_of_hours() {
return no_of_hours;
}
public void setNo_of_hours(int no_of_hours) {
this.no_of_hours = no_of_hours;
}
public double getRate_per_hour() {
return rate_per_hour;
}
public void setRate_per_hour(double rate_per_hour) {
this.rate_per_hour = rate_per_hour;
}
// toString() method which is used to display the contents of an object
@Override
public String toString() {
return \"\ ____Services Object___\ No_of_hours=\" + no_of_hours + \",\ Rate_per_hour=\" + rate_per_hour;
}
// This method will compute and display total payroll
@Override
public void computerSales() {
double total = getNo_of_hours() + getRate_per_hour();
System.out.println(\"Total :\" + total);
}
}
____________________________________
Supplies.java
public class Supplies extends Account {
// Declaring instance variables
private double officeSuppliesAmount;
private double booksSoldAmount;
private double aprealSoldAmount;
// Parameterized constructor
public Supplies(double officeSuppliesAmount, double booksSoldAmount,
double aprealSoldAmount) {
super();
this.officeSuppliesAmount = officeSuppliesAmount;
this.booksSoldAmount = booksSoldAmount;
this.aprealSoldAmount = aprealSoldAmount;
}
// Setters and getters
public double getOfficeSuppliesAmount() {
return officeSuppliesAmount;
}
public void setOfficeSuppliesAmount(double officeSuppliesAmount) {
this.officeSuppliesAmount = officeSuppliesAmount;
}
public double getBooksSoldAmount() {
return booksSoldAmount;
}
public void setBooksSoldAmount(double booksSoldAmount) {
this.booksSoldAmount = booksSoldAmount;
}
public double getAprealSoldAmount() {
return aprealSoldAmount;
}
public void setAprealSoldAmount(double aprealSoldAmount) {
this.aprealSoldAmount = aprealSoldAmount;
}
// toString() method which is used to display the contents of an object
@Override
public String toString() {
return \"\ ____Supplies Object___\ OfficeSuppliesAmount=\"
+ officeSuppliesAmount + \"\ BooksSoldAmount=\" + booksSoldAmount
+ \"\ AprealSoldAmount=\" + aprealSoldAmount;
}
// This method will calculate the total cost of supplies
@Override
public void computerSales() {
double totSupplies = 0.0;
totSupplies = getOfficeSuppliesAmount() + getBooksSoldAmount()+ getAprealSoldAmount();
System.out.println(\"Total Supplies :\" + totSupplies);
}
}
_______________________________________
TestClass.java (This class contains main() method.so run this program)
public class TestClass {
public static void main(String[] args) {
//Creating an Account array which holds different class objects
Account arr[]={new Services(42, 9.5),
new Supplies(2000,1500,1200),
new Paper(50,100)};
//This for loop will call the methods on the Class Objects
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i].toString());
arr[i].computerSales();
}
}
}
________________________________________
Output:
____Services Object___
No_of_hours=42,
Rate_per_hour=9.5
Total :51.5
____Supplies Object___
OfficeSuppliesAmount=2000.0
BooksSoldAmount=1500.0
AprealSoldAmount=1200.0
Total Supplies :4700.0
____Paper Object___
No_of_pounds=50
Price_per_pound=100.0
Total :150.0
_______________________Thank You



