In: Computer Science
You are tasked to design an application to keep track of sales for your company. Sales should be tracked for two types of accounts: supplies and services. Complete the following:
Create a UML class diagram for the Account
inheritance hierarchy. Your subclasses should be Supplies and
Services.
All sales accounts will have an account ID
(accountId).
You will need attributes to keep track of the
number of hours (numberOfHours) and rate per hour of services
provided (ratePerHour).
You should also keep track of the number of
items sold (numberOfItems) and the price per item for the sold
supplies (pricePerItem).
All classes should have a constructor.
Add getters and setters to all of your
classes.
Override the method toString in all 3
classes.
Add a method to calculate the sales in each
class [calculateSales()].
Submit your UML diagram in a zip file.
This Submission Node will demonstrate the following:
class Sales
{
private int accountId;
public Sales(int accountId)
{
this.accountId =
accountId;
}
public String toString()
{
return "Sales : AccountId :
"+accountId;
}
public void setAccountId(int accountId)
{
this.accountId =
accountId;
}
public int getAccountId()
{
return accountId;
}
}
class Supplies extends Sales
{
private int numberOfHours;
private double ratePerHour;
public Supplies(int accountId,int numberOfHours,double
ratePerHour)
{
super(accountId);
this.numberOfHours = numberOfHours;
this.ratePerHour = ratePerHour;
}
public String toString()
{
return "Supplies : Number of
hours : "+numberOfHours +" Rate per hour : "+ratePerHour;
}
public double calculateSales()
{
return numberOfHours * ratePerHour;
}
public void setNumberOfHours(int numberOfHours)
{
this.numberOfHours = numberOfHours;
}
public int getNumberOfHours()
{
return numberOfHours;
}
public void setRatePerHour(double ratePerHour)
{
this.ratePerHour = ratePerHour;
}
public double getRatePerHour()
{
return ratePerHour;
}
}
class Services extends Sales
{
private int numberOfItems;
private double pricePerItem;
public Services(int accountId,int numberOfItems,double
pricePerItem)
{
super(accountId);
this.numberOfItems = numberOfItems;
this.pricePerItem = pricePerItem;
}
public String toString()
{
return "Services: Number Of Items : "+numberOfItems +"
Price per Item : "+pricePerItem;
}
public double calculateSales()
{
return numberOfItems * pricePerItem;
}public void setNumberOfItems(int numberOfItems)
{
this.numberOfItems = numberOfItems;
}
public int getNumberOfItems()
{
return numberOfItems;
}
public void setPricePerItem(double pricePerItem)
{
this.pricePerItem = pricePerItem;
}
public double getPricePerItem()
{
return pricePerItem;
}
}
class TestSales
{
public static void main (String[] args)
{
Supplies supp = new
Supplies(1234,34,4.5);
System.out.println(supp);
Services serv = new
Services(4556,6,16.5);
System.out.println(serv);
}
}
Output:
Supplies : Number of hours : 34 Rate per hour : 4.5 Services: Number Of Items : 6 Price per Item : 16.5
UML
Do ask if any doubt. Please upvote.