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...
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...
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....
C++ Classes & Objects Create a class named Student that has three private member: string firstName...
C++ Classes & Objects Create a class named Student that has three private member: string firstName string lastName int studentID Write the required mutator and accessor methods/functions (get/set methods) to display or modify the objects. In the 'main' function do the following (1) Create a student object "student1". (2) Use set methods to assign StudentID: 6337130 firstName: Sandy lastName: Santos (3) Display the students detail using get functions in standard output using cout: Sandy Santos 6337130
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
Part A: Create a project with a Program class and write the following two methods (headers...
Part A: Create a project with a Program class and write the following two methods (headers provided) as described below: A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number if the number is not in the range or a non-numeric...
1. You are to write a simple program with two classes. One controller class and a class to hold your object definition.
1. You are to write a simple program with two classes. One controller class and a class to hold your object definition. (Similar to what we used in class) 2. Use a package in your project, the package name should be xxxprojectname. xxx is your initials taken from the first three characters of your Cal Poly email address. 3. Read in the following from the JOptionPane input window: a. Customer First Name b. Customer Last Name c. Customer Phone Number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT