Question

In: Computer Science

Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...

Classes and Objects

Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for the Services class is computed as numberOfHours times ratePerHour, and for the Supplies class the cost will be numberOfItems times pricePerItem. Each class should have a function __str__() that will return all the required information.

Write a main() program that applies Python list to store at least two objects of each class mentioned above. Implement all available functions to demonstrate your understanding of applying those methods in your program. Make up your own data when creating each object and print out each object information accordingly. Please submit your UML diagram. Your code is expected to be commented and user-friendly.

Solutions

Expert Solution

I have implemented the Sales, Service, and main() per the given description.

Please find the following Code Screenshot, Output, and Code.

ANY CLARIFICATIONS REQUIRED LEAVE A COMMENT

1.CODE SCREENSHOT :

2.OUTPUT :

3.CODE :

class Services:
  #construtor to declare that initlize numberOfHours and ratePerHour
  def __init__(self, numberOfHours:int, ratePerHour:float):
    self._numberOfHours = numberOfHours  # private
    self._ratePerHour = ratePerHour   # private
  #setter method for numberOfHours and ratePerHour
  def setNumberOfHours(self,numberOfHours:int):
    self._numberOfHours = numberOfHours  
  def setRatePerHour(self,ratePerHour:float):
    self._ratePerHour=ratePerHour
  #getter method for numberOfHours and ratePerHour
  def getNumberOfHours(self):
    return self._numberOfHours
  def getRatePerHour(self):
    return self._ratePerHour
  #method to calcuate the total cost
  def calculateSales(self):
    return self.getNumberOfHours()*self.getRatePerHour();
  #a to string method to return all the information in string format 
  def __str__(self):
    return "Service \nNumber of Hours : "+str(self.getNumberOfHours())+"\nRate Per Hour   : "+str(self.getRatePerHour())+"\nCost Accrued    : "+str(self.calculateSales());
class Supplies:
  #Constructor to declare and intilize numberOfItems and pricePerItem 
  def __init__(self, numberOfItems :int, pricePerItem :float):
    self._numberOfItems  = numberOfItems  # private
    self._pricePerItem  = pricePerItem    # private
  #setter method for numberOfItems and pricePerItem 
  def setNumberOfItems (self,numberOfHours:int):
    self._numberOfItems = numberOfHours  
  def setPricePerItem (self,pricePerItem :float):
    self._pricePerItem =pricePerItem 
  #getter method for numberOfItems and pricePerItem 
  def getNumberOfItems (self):
    return self._numberOfItems 
  def getPricePerItem(self):
    return self._pricePerItem
  #method to calcuate the total cost
  def calculateSales(self):
    return self.getPricePerItem()*self.getNumberOfItems();
  #a to string method to return all the information in string format 
  def __str__(self):
    return "Supplies \nNumber of Hours : "+str(self.getNumberOfItems())+"\nRate Per Hour   : "+str(self.getPricePerItem())+"\nCost Accrued    : "+str(self.calculateSales());
def main():
  #Creat a empty list 
  lst=[]
  #create a service class object 
  Ser=Services(16,2.2)
  #add the abject to list 
  lst.append(Ser)
  #Create a Supplies class object 
  sup=Supplies(18,3.2)
  #add that to list 
  lst.append(sup)
  #Print the elements in the list 
  #please note the __str()__ will call all the getter and calculateSales methods 
  for i in lst:
    print(i)
main()

UML calss Diagram:


Related Solutions

Using Eclipse, create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours...
Using Eclipse, create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type double. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type double. For each class, provide its getter and setter functions, a default constructor, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for the Services class...
Q.We design classes to create objects in java. Write step wise procedure for (a).How these objects...
Q.We design classes to create objects in java. Write step wise procedure for (a).How these objects created in memory? (b). Which area of memory is used for creation of the objects? (c). What is difference between stack and heap memory in java?
Create a class of DSA with two pointer objects of Employee and Customer. These objects will...
Create a class of DSA with two pointer objects of Employee and Customer. These objects will represent the head pointer of corresponding linkedlists. Add new data member functions searchCustomer & searchEmployee, to search for customers and employees separately in DSA.
Write a Java Program using the concept of objects and classes. Make sure you have two...
Write a Java Program using the concept of objects and classes. Make sure you have two files Employee.java and EmployeeRunner.java. Use the template below for ease. (Please provide detailed explanation) Class Employee Class Variables: Name Work hour per week Hourly payment Class Methods: - Get/Sets - generateAnnualSalary(int:Duration of employment)               annual salary = Hourly payment * Work hours per week * 50 If the employee is working for more than 5 years, 10% added bonus             -void displayAnnualSalary ( )...
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel....
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel. A dog consists of the following information: • An integer age. • A string name. If the given name contains non-alphabetic characters, initialize to Wolfy. • A string bark representing the vocalization the dog makes when they ‘speak’. • A boolean representing hair length; true indicates short hair. • A float weight representing the dog’s weight (in pounds). • An enumeration representing the type...
In Python, create a program with 2 classes that do the following. HashCreate class, this class...
In Python, create a program with 2 classes that do the following. HashCreate class, this class will accept a directory and hash each file in the directory and store the results in a dictionary. The dictionary will contain the hash value and file name. HashVerify, the second class will accept the dictionary as input and save that in an instance attribute. This class must also contain a method for lookups that require a file path as input. The lookup method...
In this class add Comparable interface. In the driver program create a few objects and In...
In this class add Comparable interface. In the driver program create a few objects and In the driver program create a few objects and compare them . then create a list of those objects and sort them .A Quadratic is bigger than another Quadratic if it opens faster package pack2; /** * This is a program for defining a quadratic equation * @author sonik */ public class Quadratic { public int coeffX2 = 0; public int coeffX = 0; public...
Java program Create two classes based on the java code below. One class for the main...
Java program Create two classes based on the java code below. One class for the main method (named InvestmentTest) and the other is an Investment class. The InvestmentTest class has a main method and the Investment class consists of the necessary methods and fields for each investment as described below. 1.The Investment class has the following members: a. At least six private fields (instance variables) to store an Investment name, number of shares, buying price, selling price, and buying commission...
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments....
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to do the following: 1....
6.13 Lab: Patient Class - process an array of Patient objects This program will create an...
6.13 Lab: Patient Class - process an array of Patient objects This program will create an array of 100 Patient objects and it will read data from an input file (patient.txt) into this array. Then it will display on the screen the following: 1. The names of the underweight patients. 2. The names of the overweight patients. 3. The names of the obese patients. Finally, it writes to another file (patientReport.txt) a table as shown below: Weight Status Report ====================...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT