11
Here is an outline for a working class OldCellPhone that has no errors (you may see this exact class several times in this exam):
class OldCellPhone: MIN_MEM_CAP, MAX_MEM_CAP = 10, 100000 MIN_DSCR_LEN, MAX_DSCR_LEN = 10, 100 DEFAULT_DSCR = "(generic phone)" DEFAULT_BOOL = False DEFAULT_CAP = 1000 # constructor def __init__(self, dscr = DEFAULT_DSCR, mem = DEFAULT_CAP, cam = DEFAULT_BOOL, gp = DEFAULT_BOOL): """ expcted string, int, 'boolean', 'boolean' """ if (not self.set_mem_cap(mem)): self.mem_capacity = OldCellPhone.DEFAULT_CAP if (not self.set_description(dscr)): self.description = OldCellPhone.DEFAULT_DSCR if (not self.set_camera(cam)): self.camera = OldCellPhone.DEFAULT_BOOL if (not self.set_gps(gp)): self.gps = OldCellPhone.DEFAULT_BOOL def set_mem_cap(self, mem): # def not shown def set_camera(self, bool): """ member only wants a "boolean" literal, True or False (True means 'has cam', False means 'does not have cam' """ # def not shown def set_gps(self, bool): """ member only wants a "boolean" literal, True or False (True means 'has gps', False means 'does not have gps' """ # def not shown def to_string(self): # def not shown # other accessors and mutators not shown
A programmer decides to add an instance
method add_memory() whose job it
will be to increase the instance attribute
mem_capacity by an amount specified by the
client as long as the new, increased memory capacity,
after adding the amount, is still <=
MAX_MEM_CAP. Otherwise, it will not touch
mem_capacity.
Check the true statements (there may be more than one correct
answer):
a
If correctly defined, a client could add 333 units of memory to the OldCellPhone object, my_cell, by using the syntax: my_cell.add_memory(333) |
b
This should be a static or class method. |
c
If correctly defined, a client could add 333 units of memory to the OldCellPhone object, my_cell, by using the syntax: OldCellPhone.add_memory( my_cell(333) ) |
d
This should be an instance method. |
e
If correctly defined, a client could add 333 units of memory to the OldCellPhone object, my_cell, by using the syntax: OldCellPhone.add_memory(333) |
The correct options is a and d.
add_memory() as defined in the description is given as an instance
method so that automatically rules out any possibility of it being
static and so all the options pertaining to static is automatically
ruled out (Option b, c and e).
Just for clarification: - Major difference b/w static and instance
methods is that instance methods operate on every new instances of
classes (objects). So options a and d are valid in this
case.
- Static methods doesn't require any new class instances altogether
for them to work. Options b and e are valid in case of static
methods, are ruled out in our case.
- Option c is altogether invalid with OldCellPhone.add_memory(
my_cell(333) ). Since in constructor definition of
OldCellPhone class, we have no definition that allows for operating
only with inputted memory value as a constructor parameter.
11 Here is an outline for a working class OldCellPhone that has no errors (you may...
Consider the class as partially defined here: //class Pizzaorder class Pizzaorder // static public members public static final int MAX TOPPINGS 20: // instance members private String toppings[]; private int numToppings; // constructor public PizzaOrder () { numToppings toppings 0; String[MAX TOPPINGS]; new // accessor tells # toppings on pizza, i.e., #toppings in array public int getNum Toppings ()return numToppings; // etc. We want to write an instance method, addTopping) that will take a String parameter, topping, and add it...
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...
Can someone help me with the main class of my code. Here is the assignment notes. Implement project assignment �1� at the end of chapter 18 on page 545 in the textbook. Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that the method is delcared static. Therefore, you do not need to create a new instance of the object before the method is called. Simply use "SkipSearch.jumpSearch(...)" with the appropriate 4 parameter values. When...
class WorkoutClass: """A workout class that can be offered at a gym. === Private Attributes === _name: The name of this WorkoutClass. _required_certificates: The certificates that an instructor must hold to teach this WorkoutClass. """ _name: str _required_certificates: List[str] def __init__(self, name: str, required_certificates: List[str]) -> None: """Initialize a new WorkoutClass called <name> and with the <required_certificates>. >>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class.get_name() 'Kickboxing' """ def get_name(self) -> str: """Return the name of this WorkoutClass. >>> workout_class =...
IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....
Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user if they want to add a customer to the queue, serve the next customer in the queue, or exit. When a customer is served or added to the queue, the program should print out the name of that customer and the remaining customers in the queue. The store has two queues: one is for normal customers, another is for VIP customers. Normal customers can...
Modify the LinkedCollection class to be a SortedLinkedCollecton class and see how that effects our implementation for adding and removing items. You should reference the SortedArrayCollection class provided for how these algorithms should be implemented. What needs to change here? Is it a lot of code or not much? Include a toString method that creates and returns a string that correctly represents the current collection. Include a test driver application that demonstrates your class correctly. //--------------------------------------------------------------------------- // LinkedCollection.java // //...
Copy the program AmusementRide.java to your computer and add your own class that extends class AmusementRide. Note: AmusementRide.java contains two classes (class FerrisWheel and class RollerCoaster) that provide examples for the class you must create. Your class must include the following. Implementations for all of the abstract methods defined in abstract class AmusementRide. At least one static class variable and at least one instance variable that are not defined in abstract class AmusementRide. Override the inherited repair() method following the...
please answer "class playerexception(exception):" in python Notes Two players will face each other. They each decide independently to "cooperate" or "cheat". If they both cooperated, they each win two points. If they both cheated, nobody wins anything. one cheats, the cheater gets +3 and the cooperator loses a point. That wasn't very kind! One turn is defined as each player making a choice, and winning or losing some points as a result. Shared history against this player is available to...
Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...