Sketch a class hierarchy of employees from two departments, Sales and Accounts R
ID: 3719300 • Letter: S
Question
Sketch a class hierarchy of employees from two departments, Sales and Accounts Receivable. Show the attributes (data variables) and functionality (methods/functions/operations) of each. Show an abstract superclass, and place attributes and functionality that is common to both subclasses in this superclass. Override functionality, as is appropriate, in your subclasses.
This assignment requests a class diagram showing 1) encapsulation and 2) inheritance. There is no multiplicity/cardinality necessary or appropriate in this case. Make sure you provide enough attributes and functionality to properly model the classes in your hierarchy.
Explanation / Answer
//Sketch for class hierarchy of employees
interface Sales
{
public void setDeptType(int type);
public int getSalesItems();
public void setSalesItems(int Items);
public void purchaseItems(int no);
public int avaliablityItems();
}
interface Accounts
{
public void setDeptType(int type);
public void getTaxAccounts();
public void getNonTaxAccountDetails();
public void getEmpSalaryAccounts();
}
//Department class inherits Sales and Accouns interfaces
class Department implements Sales,Accounts
{
String deptCode;
String deptName;
int soldItemsCount;
int deptType;
int totalItemsCount;
double totalEmpSalary;
public Department(int type)
{
deptCode="D";
deptName="";
soldItemsCount=0;
totalItemsCount=100;
deptType = type;
}
public void setDeptType(int type)
{
deptType =type;
}
public String getDeptName()
{
if (deptType == 1)
deptName ="Sales";
else
deptName ="Accounts";
return deptName;
}
public int getSalesItems()
{
return soldItemsCount;
}
public void setSalesItems(int totalItemsCount)
{
this.totalItemsCount =totalItemsCount;
}
public int avaliablityItems()
{
return totalItemsCount;
}
public void purchaseItems(int no)
{
if(totalItemsCount < no)
System.out.println(" Items are not avaliable... !");
else
totalItemsCount -= no;
soldItemsCount +=no;
}
public void getTaxAccounts()
{
System.out.println(" Add Details of Taxible accounts");
}
public void getNonTaxAccountDetails()
{
System.out.println(" Add Details of Non Taxible accounts");
}
public void getEmpSalaryAccounts()
{
System.out.println(" Add the emp salary account Details"+totalEmpSalary);
}
}
// Employee Class extneds Department
class Employee extends Department
{
String empId;
String empName;
double empSalary;
String address;
String phoneNo;
public Employee(String eid,String ename,double esal,String addr,String phno,int type)
{
super(type);
empId = eid;
empName = ename;
empSalary = esal;
address = addr;
phoneNo = phno;
}
public double getSalary()
{
return empSalary;
}
public String getId()
{
return empId;
}
public String getName()
{
return empName;
}
public String getAddress()
{
return address;
}
public void getEmployeeDetails()
{
System.out.println("Emp Id " + empId);
System.out.println("Emp Name " + empName);
System.out.println("Emp Salary " + empSalary);
System.out.println("Emp Address " + address);
System.out.println("Depart Name " + getDeptName());
}
}
public class HelloWorld{
public static void main(String []args){
Employee obj=new Employee("S001","Kumar",17899,"New Yark","1234567891",1);
obj.getDeptName(); // return Emp Department Name
obj.getEmployeeDetails();
obj.getTaxAccounts(); // It will taxable account deatils
obj.purchaseItems(5); //purchase items list
System.out.println("Total Sold Items " + obj.getSalesItems());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.