Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Some coffee shop wants to implement a system to allow its registered Custom

ID: 3875375 • Letter: J

Question

JAVA

Some coffee shop wants to implement a system to allow its registered Customers to view their purchases. Initially, the system is required to allow its Salesperson to view and create sales records. Later, the system will also be required to allow the ShopManager to view, create and update sales records. Answer the questions below:

Using UML class diagram, to represent the objects of above system.

Write source codes in Java programming language to define classes required to create the Customer and Salesperson objects while maintaining the underlying principles of inheritance. Assume Customer, Salesperson and ShopManager have employeeID, empoyeeName and contactDetails attributes in common. Note any assumptions that you may have made when writing the source codes. Note: You can implement the methods to view, create and update sales records by simply displaying different messages. Demonstrate how a Salesperson can create new sales records and how a Salesperson and Customer can view the existing sales records. Note any assumptions that you may have made when writing the program.

Explanation / Answer

Assumption : 1.We assumed that Person is a super class of Customer,Salesperson and ShopManager..

2.Customer has a customer Id.

3.Create an interface SalesOperation with some commin methods

UML Class Diagram

1.Interface

package coffee.shop;

public interface SalesOperation {

   public void viewSalesRecord();
   public void createSalesRecord();
}

2.Person Class.

package coffee.shop;

public class Person {

   private String employeeId;
   private String employeeName;
   private String contactDetails;
   public Person() {
      
   }
   public Person(String employeeId, String employeeName, String contactDetails) {
       this.employeeId = employeeId;
       this.employeeName = employeeName;
       this.contactDetails = contactDetails;
   }
   public String getEmployeeId() {
       return employeeId;
   }
   public void setEmployeeId(String employeeId) {
       this.employeeId = employeeId;
   }
   public String getEmployeeName() {
       return employeeName;
   }
   public void setEmployeeName(String employeeName) {
       this.employeeName = employeeName;
   }
   public String getContactDetails() {
       return contactDetails;
   }
   public void setContactDetails(String contactDetails) {
       this.contactDetails = contactDetails;
   }
  
  
}

3.Cutomer Class

package coffee.shop;

public class Customer extends Person {

   private String customerID;
  
   public Customer(String employeeId, String employeeName, String contactDetails, String customerID) {
       super(employeeId, employeeName, contactDetails);
       this.customerID = customerID;
   }
   public Customer()
   {
super();      
   }

   public String getCustomerID() {
       return customerID;
   }

   public void setCustomerID(String customerID) {
       this.customerID = customerID;
   }


}

4.SalesPerson Class

package coffee.shop;

public class Salesperson extends Person implements SalesOperation
{

   public Salesperson(String employeeId, String employeeName, String contactDetails) {
       super(employeeId, employeeName, contactDetails);
      
   }

   @Override
   public void viewSalesRecord() {
       System.out.println("Inside viewSalesRecord method of SalesPerson Class");
       System.out.println("Here Sales person can see sales records");
   }

   @Override
   public void createSalesRecord() {
       System.out.println("Inside createSalesRecord method of SalesPerson Class");
       System.out.println("Here Sales person can create sales records");
   }
  
   public void updateSalesRecord(String recordId) {
       System.out.println("Inside updateSalesRecord method of SalesPerson Class");
       System.out.println("Here Sales person can update sales records based on the record Id");
   }
}


5.ShopManager Class

package coffee.shop;

public class ShopManager extends Person implements SalesOperation {

   public ShopManager(String employeeId, String employeeName, String contactDetails) {
       super(employeeId, employeeName, contactDetails);
      
   }

   @Override
   public void viewSalesRecord() {
       System.out.println("Inside viewSalesRecord method of ShopManager Class");
       System.out.println("Here Shop Manager can see sales records");
   }

   @Override
   public void createSalesRecord() {
       System.out.println("Inside createSalesRecord method of ShopManager class");
       System.out.println("Here Shop Manager can create sales records");
   }

}

6.CoffeeShop Tester Class

package coffee.shop;

public class CoffeeShop {

   public static void main(String[] args) {
       //create a sales person object
       Salesperson salesPerson=new Salesperson("11111", "XYZ", "11112 ,Delhi ,India");

       //By calling this method a new sales record can be created .
       salesPerson.createSalesRecord();

       //By calling this method a new sales record can be updated .
       //Here you may need one more class for storing item details , then based on the Id of that item item can be updated .
       salesPerson.updateSalesRecord("122121");
       //sales person can see the existing sales record using this method
       salesPerson.viewSalesRecord();
      
       //Create Customer class object
       Customer customer =new Customer();
       //By calling methods of customer class customer can perform the desired operations
   }

}