Question

In: Computer Science

You will write classes from the last in-class assignment, R&DLibrary. R&DLibrary is the main file in...

  1. You will write classes from the last in-class assignment, R&DLibrary. R&DLibrary is the main file in which a user can choose to enroll themselves, check out an item, return an item, pay a fine and display their account (what is currently checked out, accumulated fines).
  2. Write a material class that calculates the fine based off of the type of item, the length it’s been checked out and whether or not it’s even been checked out.
  3. Lastly, write a employee Class that contains the username of a user, the items that person has checked out, a copy of the accumulated fines and the number of items checked out.

Solutions

Expert Solution

class RnD(material):
    def __init__(self):
        super().__init__()
        self.items = {1:['aa','ab', 'ac'], 2:['ba', 'bb', 'bc'], 3:['ca','cb','cc']}
        self.itm_chk = {'items' : [], 'type':[]}
        self.usr_dtl = {'usrnm' : [], 'fine':[]}
    
    def enroll(self):
        '''
        Docstring : Function to enroll a new student.
        '''
        while(True):
            usrnm = input('Enter your username')
            if  usrnm == 'exit':
                break
            if usrnm not in self.usr_dtl['usrnm']:
                self.usr_dtl['usrnm'].append(usrnm)
                self.usr_dtl['fine'].append(0)
                self.itm_chk['items'].append(-1)
                self.itm_chk['type'].append(-1)
                break
            print('Username is already taken try something different')
            print('If you want to exit enter "exit" as username')
            
    def login(self):
        '''
        Docstring : Function to login a user.
        '''
        while True:
            usrnm = input('Enter your username: ')
            if usrnm in self.usr_dtl['usrnm'] or usrnm == 'exit':
                break
            print('You have entered a wrong username. try again')
            print('If you want to exit enter "exit" as username')
        indx = self.usr_dtl['usrnm'].index(usrnm)
        #this will be a method in material class
        self.usr_dtl['fine'] = self.calc_fine(usrnm)
        return usrnm
    
    def checkout(self):
        '''
        Docstring :  Function to checkout a new item.
        '''
        print('Available Items are :')
        j = 1
        for i in self.items.keys():
            for k in self.items[i]:
                print(j, '. ', k)
                
        usrnm = self.login()
            
        if usrnm != 'exit':
            itm = input('Enter the name of the item you want to checkout')
            for i in self.items.keys():
                if itm in self.items[i]:
                    indx = self.usr_dtl['usrnm'].index(usrnm)
                    if self.itm_chk['items'][indx] == -1:
                        self.itm_chk['items'][indx] = itm
                        self.itm_chk['type'][indx] = i
                        self.items[i].pop(self.items[i].index(itm))
                        print('item has been issued to you')
                    else:
                        print('You have already issued an item first return that.')

    def return_itm(self):
        '''
        Docstring : Function to return an issued item.
        '''
        usrnm = self.login()
        if usrnm != 'exit':
            indx = self.usr_dtl['usrnm'].index(usrnm)
            
            if self.usr_dtl['fine'][indx] == 0:
                itm = self.itm_chk['items'][indx]
                self.itm_chk['items'][indx] = -1
                typ = self.itm_chk['type'][indx]
                self.itm_chk['type'][indx] = -1
                self.items[typ].append(itm)
                print('You have returned the item successfully.')
                
            else:
                print('Please first pay you pending fine and try again.')
                self.pay_fine(usrnm)
    
    def pay_fine(self, usrnm=123):
        '''
        Docstring : Function to pay a fine through a url. Can also be included in Fines class.
        '''
        if usrnm == 123:
            usrnm = self.login()
        print('https://visit_this_to_pay_fine.com')
        self.usr_dtl['fine'][self.usr_dtl['usrnm'].index(usrnm)] = 0
     
    def disp_account(self):
        '''
        Docstring : Function to show the user account details.
        '''
        usrnm = self.login()
        print('Username :  ', usrnm)
        indx = self.usr_dtl['usrnm'].index(usrnm)
        print('Issued item : ', self.itm_chk['items'][indx])
        print('Due fine : ', self.usr_dtl['fine'][indx])
    

This is the main class for R&D library with all the features you specified. You didn't mentioned any particular language so I chose python but if you want it in any another language you can easily convert this code into any other language. There were alot of features which you requested in the question but it is not feasible to impliment all those features all at once so I implimented the top 4-5 features you requested. The structure of the code will remain same for any language. I tried to make as distributed code as possible for better understanding and have inserted docstring for every method of the class.

I would suggest that you keep all the fine payment and calculation methods in material class and inherit that class in this main class for better segregation of the code. I have already written the code for inheritance in this main class you just need to write its class. If you have any doubt remaining then ask again in a different question with a little bit more background information and more elaborated functions. You don't need to write a different class for your employees I have integerated most of its features in the main class itself so you can access them from here, hence reducing the lenght of the code required and the code I have given you allows only a single item to be issued to a user at a time you and to issue a new item the user will have to first return the old item and pay all the accumaleted fine then only he/she will be issued a new item.


Related Solutions

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 this assignment you will write a PHP program that reads from a data file, creates...
In this assignment you will write a PHP program that reads from a data file, creates an associative array, sorts the data by key and displays the information in an HTML table. Create a PHP file called hw4.php that will do the following: - Display your name. - Read text data from a file. The data file is hw3.txt. The file hw3.txt will hold the following text: PQRParrot, Quagga, Raccoon DEFDo statements, Else statements, For statements GHIGeese, Hippos, If statements...
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 an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method...
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and  numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which will...
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method...
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which...
In this assignment you will write a program that encrypts a text file.  You will use the...
In this assignment you will write a program that encrypts a text file.  You will use the following encryption scheme. Ask the user for the name of the original file. Ask the user for the name of the output file. Ask the user for the encryption key, n. Read n2 characters from the file into the n rows and n columns of a 2-dimensional array. Transpose the array.  (Exchange the rows and columns.) Write the characters from the array to an output...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of...
Using JAVA: This assignment is about aggregation and class collaboration. You will create several Classes that...
Using JAVA: This assignment is about aggregation and class collaboration. You will create several Classes that will be part of an overall class named InstrumentDisplay. The classes are FuelGage, Odometer, MilesSinceLastGas, and CruisingRange. The FuelGage should assume a 15 gallon tank of gasoline and an average consumption of 1 gallon every 28 miles. It should increment in 1 gallon steps when you "add gas to the tank". It should decrement by 1 every 28 miles. It should display its current...
IN C++, ONE FILE Also include the main class that just runs these functions, thanks. Write...
IN C++, ONE FILE Also include the main class that just runs these functions, thanks. Write a recursive function to produce a pattern of n lines of asterisks. The first line contains one asterisk, the next line contains two, and so on, up to the nth line, which contains n asterisks. For example, if the non-negative integer is 5, the pattern generated is: * ** *** **** ***** Prototype: void pattern(unsigned n); Write a recursive function, sum_range that finds the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT