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 ( )...
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...
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...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until...
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
Write two classes Class A and Class B in class A you should read from the...
Write two classes Class A and Class B in class A you should read from the keyboard a number and you should call a public method of the class B that will print on the screen whether the number that was read from the keyboard in class A is multiple of 7 and has the last digit 5.
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside...
In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside of the ServerClass class, that: 1. Takes the IP 2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128) 3. Returns the Server object with the larger sum Example: server_one = ServerClass("127.0.0.1") server_two = ServerClass("192.168.0.1") result = biggest_ip_sum(server_one, server_two) print(result) Hint Modify get_server_ip in the previous problem. -------------------- Please use this code to start class ServerClass: """ Server class for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT