Question

Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name=''...

Using the following code:

store.py

from abc import ABC,abstractmethod
class Store(ABC): #creating a abstract class
name='' #declaring attributes in class
address=''
status=''
sales_tax_percentage=0.0

def __init__(self,name,address,status,sales_tax_percentage): #init method to initialize the class attributes
self.name=name
self.address=address
self.status=status
self.sales_tax_percentage=sales_tax_percentage

def get_name(self): #Getter and setter methods for variables
return self.name

def set_name(self,name):
self.name=name

def get_address(self):
return self.address

def set_address(self,address):
self.address=address

def set_status(self,status):
self.status=status

def get_status(self):
return self.status

def set_sales_tax_percentage(self,sales_tax_percentage):
self.sales_tax_percentage=sales_tax_percentage

def get_sales_tax_percentage(self):
return self.sales_tax_percentage

def is_store_open(self): #check store status or availability
if self.status=="open": #Return true if store is open
return True
elif self.status=="closed": #Return false if store is closed
return False

def calculate_total_sales_tax(self): #abstract method
pass

def calculate_total_sales(self): #abstract method
pass

  1. Create a file called restaurant.py which contains a class called Restaurant which is type of Store. It should possess all the attributes and functions present in the Store class without having to re-implement those in the Restaurant class. The Restaurant class is made up of the following:
    • Attributes/Properties o Total number of people served
      • Max occupancy o Current occupancy o Price per person
    • Functions/Functionality o Constructor which provides the ability to pass and set the values for the various attributes
      • seat_patrons should do the following:
        • Take the number of people to be seated as input
        • Update the values of the appropriate attributes
        • If number of people to be seated does not exceed or equals the max occupancy
          • Print “Welcome to [replace with name of restaurant]” • Return True
        • If number of people to be seated exceeds the max occupancy
          • Print “We are at capacity, we appreciate your patience”
          • Return False
      • serve_patrons which should do the following:
        • Take the number of people to serve as input
        • Update the values of the appropriate attributes
        • Return the number of people being served currently o checkout_patrons (this is when the patrons are ready to leave the restaurant) which should do the following:
        • Take the number of people leaving as input
        • Update the values of the appropriate attributes
        • Return the current occupancy of the restaurant o Create a getter and setter for the attribute: Price per person
0 0
Add a comment Improve this question Transcribed image text
Answer #1

This is Restaurant class which extending the store class defined in the question. As the ques states, without implementing the store class... I just extend it to fetch the name of restaurant.

class Restaurant extends store{
   int total_people_served, max_occupancy, current_occupancy;
   double price_per_person;
  
   public Restaurant(int total_people_served, int max_occupancy, int current_occupancy, double price_per_person){
       this.total_people_served= total_people_served;
       this.max_occupancy= max_occupancy;
       this.current_occupancy= current_occupancy;
       this.price_per_person= price_per_person;
          
   }
  
  
   public int seat_patrons(int numOfPeopleSeated){
         
       int check= this.current_occupancy+numOfPeopleSeated;
       if(check <= this.max_occupancy){
           serve_patrons(numOfPeopleSeated);
           this.total_people_served+=numOfPeopleSeated;
           this.current_occupancy+=numOfPeopleSeated;
           return 1 ;
       }
       else
           return 0;
       }
     
      public void serve_patrons(int num){
         
       System.out.println("number of people being served: "+ num);
         
         
   }
     
      public void checkOut(int checkout_total){
         
       this.current_occupancy-=checkout_total;
       System.out.println("current occupancy: "+ this.current_occupancy);
         
       }
public static void main(String[] args){
      
       int ch, ch_in;
       Scanner sc= new Scanner(System.in);
       store s1= new store();
       s1.setName("KFC");
       Restaurant r1= new Restaurant(100, 15, 10, 500);
       System.out.println("Enter number of people arrive: ");
       ch_in= sc.nextInt();
       int res= r1.seat_patrons(ch_in);
       if(res == 1){
           System.out.println("Welcome to "+ s1.getName());
       }else
           System.out.println("We are at capacity, we appreciate your patience");
       System.out.println("Enter number of people for checkout: ");
       ch= sc.nextInt();
       r1.checkOut(ch);
      
   }
}

The Store class:

public store(){
  
}

public store(String name,String address, int status, double sales_tax_percentage){
  
   this.name= name;
   this.address=address;
   this.status=status;
   this.sales_tax_percentage= sales_tax_percentage;
  
}

public String getName(){
   return this.name;
}
public void setName(String name){
   this.name= name;
}

public String getAddress(){
   return this.address;
}

public void setAddress(String address){
   this.address= address;
}

public int getStatus(){
   return this.status;
}
public void setStatus(int status){
   this.status= status;
}
public double getsales_tax_percentage(){
   return this.sales_tax_percentage;
}

public void settsales_tax_percentage(double sales_tax_percentage){
   this.sales_tax_percentage= sales_tax_percentage;
}
}

Now run the program and outputs are follows:

in here max capacity= 15, So when I gave input 4 as number of people arrived

current occupancy was 10, 10+4 = 14,

14< 15, that's why it prints welcome message.

Then check out people input is given as 3, so,

current occupancy= 14,, 14- 3= 11,

and it shows current occupancy as 11 in output.

On 2nd time running of code:

I gave input as 7,

So, current occupancy= 10, i.e. 10+7= 17,

Max occupancy = 15, Which is smaller then current arrival of people

Thus shows "the patience" message.

Images showing the code implementation on Notepad++


Add a comment
Know the answer?
Add Answer to:
Using the following code: store.py from abc import ABC,abstractmethod class Store(ABC): #creating a abstract class name=''...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

    In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...

  • USING JAVA, Class Design: Person The Person class is intended to be an abstract and simplified representation of a pers...

    USING JAVA, Class Design: Person The Person class is intended to be an abstract and simplified representation of a person. Each person will have an array of "friends" - which are other "Person" instances. Data to Store (2 Points) Name private instance variable with only private setter (2 Points) Friends private instance array with neither getter nor setter Actions Constructor o 1 Point) Take in as argument the name of the person (enforce invariants) o (1 Point) Initialize the array...

  • Use your Food class, utilities code, and sample data from Lab 1 to complete the following...

    Use your Food class, utilities code, and sample data from Lab 1 to complete the following Tasks. def average_calories(foods):     """     -------------------------------------------------------     Determines the average calories in a list of foods.     foods is unchanged.     Use: avg = average_calories(foods)     -------------------------------------------------------     Parameters:         foods - a list of Food objects (list of Food)     Returns:         avg - average calories in all Food objects of foods (int)     -------------------------------------------------------     """ your code here is the...

  • class Livestock: def __init__(self,name,price_in,utilizations): self.name,self.price_in,self.utilizations = name,float(price_in),utilizations def __lt__(self,other): if self.utilizations is None: return True elif...

    class Livestock: def __init__(self,name,price_in,utilizations): self.name,self.price_in,self.utilizations = name,float(price_in),utilizations def __lt__(self,other): if self.utilizations is None: return True elif other.utilizations is None: return False else: return self.utilizations.count(';') < other.utilizations.count(';') def __eq__(self,other): return self.name == other.name def __repr__(self): return ("{}, {}".format(self.name,self.price_in)) raw_livestock_data = [ # name, price_in, utilizations ['Dog', '200.0', 'Draught,Hunting,Herding,Searching,Guarding.'], ['Goat', '1000.0', 'Dairy,Meat,Wool,Leather.'], ['Python', '10000.3', ''], ['Cattle', '2000.75', 'Meat,Dairy,Leather,Draught.'], ['Donkey', '3400.01', 'Draught,Meat,Dairy.'], ['Pig', '900.5', 'Meat,Leather.'], ['Llama', '5000.66', 'Draught,Meat,Wool.'], ['Deer', '920.32', 'Meat,Leather.'], ['Sheep', '1300.12', 'Wool,Dairy,Leather,Meat.'], ['Rabbit', '100.0', 'Meat,Fur.'], ['Camel', '1800.9', 'Meat,Dairy,Mount.'], ['Reindeer', '4000.55', 'Meat,Leather,Dairy,Draught.'],...

  • Type up the GeometricObject class (code given on the back of the paper). Name this file Geometric...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • Task 2: SecretWord class: Download and save a copy of LinkedLists.py (found at the bottom of...

    Task 2: SecretWord class: Download and save a copy of LinkedLists.py (found at the bottom of this assignment page on eClass). In this file, you have been given the complete code for a LinkedList class. Familiarize yourself with this class, noticing that it uses the Node class from Task 1 and is almost identical to the SLinkedList class given in the lectures. However, it also has a complete insert(pos, item) method (which should be similar to the insert method you...

  • Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...

    Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...

  • 1. Extending the answer from Python HW #7 for question #1, write the following python code...

    1. Extending the answer from Python HW #7 for question #1, write the following python code to expand on the Car class. Include the python code you developed when answering HW #7. Add class “getter” methods to return the values for model, color, and MPG Add class “setter” methods to change the existing values for model, color, and MPG. The value to be used in the methods will be passed as an input argument. Add class method that will calculate...

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT