Card for a car object:
Consider a “Car” class, which simulates fuel consumption in a car.
On the front side of the card, the methods that the object can execute are written. The methods for efficiency, adding gas, driving a given distance, and checking the amount of gas left in the tank that is as follows:
Car myCar Car(mpg) addGas(amount) drive(distance) getGasLeft |
On the back side of the card, the values of the instance variables are noted down. After creating the objects, the values of the instance variables will be as follows:
gasLeft | milesPerGallon |
0 | 25 |
Here, the initial value of “gasLeft” will be zero and the efficiency calculated in miles per gallon will be 25mpg.
Tracing the methods of Self Check 32:
The following method calls are given:
//Call the methods
Car myCar(25);
myCar.addGas(20);
myCar.drive(100);
myCar.drive(200);
myCar.addGas(5);
Cross out the old values whenever a mutator method is called, and write down the new one below.
gasLeft | milesPerGallon |
13 | 25 |
- Initially, the value of “gasLeft” and “milesPerGallon” was “0” and “25” respectively.
- When the method myCar.addGas(20)is called, the value “0” is cut-off and the value of “gasLeft” will be updated to “20”.
- It is because the addGas method adds the value of gas and thus, the gas left will be 0+20=20.
- When the method myCar.drive(100)is called, the value “20” is cut-off and the value of “gasLeft” will be updated to “16”.
- It is because a gas of value “4” is required to travel a distance of “100miles” and thus, the gas left will be 20-4=16.
- When the method myCar.drive(200)is called, the value “16” is cut-off and the value of “gasLeft” will be updated to “8”.
- It is because a gas of value “8” is required to travel a distance of “200miles” and thus, the gas left will be 16-8=8.
- When the method myCar.addGas(5)is called, the value “8” is cut-off and the value of “gasLeft” will be updated to “13”.
- It is because the addGas method adds the value of gas and thus, the gas left will be 8+5=13.
Instance variable added in Self Check 33:
It is given that the odometer of the car is simulated by adding a method “getMilesDriven”.
After adding the instance variables to the card, the card will be as follows:
gasLeft | milesPerGallon | totalMiles |
0 | 25 | 0 |
The initial value of the variable “totalMiles” is assigned to zero.

Want to see the full answer?
Check out a sample textbook solution
Chapter 8 Solutions
BIG JAVA: LATE OBJECTS
- What resources are used when a thread is created? How do these differ from those used when a process is created?arrow_forward(c) Consider the following set of processes: Process ID Arrival Time Priority Burst Time A 2 3 100 B 6 C 10 1 (highest) 2 40 80 D 16 4 (lowest) 20arrow_forward(3e) Test-and-Set. The Test-and-Set instruction is used in hardware to achieve synchronization. It can be defined in the following way: function Test-and-Set (var target: boolean): boolean; begin Test-and-Set:= target; target := true; end; Now show how the Test-and-Set instruction can be used to protect a critical region and hence achieve mutual exclusion (do not worry about satisfying the bounded waiting condition). (8 points) repeatarrow_forward
- Consider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigarette and then smokes it. But to roll and smoke a cigarette, the smoker needs three ingredients: tobacco, paper and matches. One of the smoker processes has paper, another has tobacco and the third has the matches. The agent has an infinite supply of all three materials. The agent places two of the ingredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts out another two of the three ingredients, and the cycle repeats. Given below is a solution to the Cigarette-Smokers Problem. Give initial conditions for the semaphores as well as plausible values for the variables i & j and r & s, such that the agent and smokers are synchronized. Write a couple of sentences on why these initial conditions are necessary and sufficient. Solution: var a: array [0..2] of semaphore (initial condition =…arrow_forwardLevel-0 Diagram for this: A customer sends in an order form containing details of their order and their membership number. A check is made to verify that they are a member. When their order is verified, a check is made to validate that the items ordered are produced by the company. Next, the valid order is used to update the daily order file, and then used to create a shipping list and invoice, which are sent on to the Order Fulfilment System.arrow_forwardIn this assignment, you will use all of the graphics commands you have learned to create an animated scene. Your program should have a clear theme and tell a story. You may pick any school-appropriate theme that you like. The program must include a minimum of: 5 circles 5 polygons 5 line commands 2 for loops 1 global variable You may wish to use the standard code for simplegui graphics below: import simplegui def draw_handler(canvas): frame = simplegui.create_frame('Testing', 600, 600) frame.set_canvas_background("Black") frame.set_draw_handler(draw_handler) frame.start() Submit Your Code After you write your code here in the programming environment, you will check it and submit it as usual. However, the grader will only perform basic checks against some requirements. If your code passes, you should submit your work, and your teacher will manually grade your submitted work using a rubric.arrow_forward
- 1. What is the difference between a relative cell reference and an absolute cell reference and give an example of when you would use each.arrow_forwardWhat is the goal of using a chart in excel, and how is a chart useful and what is the goal of using sparklines in excel, and how are sparklines useful?arrow_forwardProve for each pair of expression f(n) and g(n) whether f(n) is big O, little o Ω,ω or Θ of g(n). Use limits to find these. For each case it is possible that more than one of these conditions is satisfied:1. f(n) =log(n2^n), g(n) = log(sqrt(n)2^(n^2))2. f(n) =nsqrt(n) +log(n^n), g(n) =n + sqrt(n)lognarrow_forward
- Need this expression solved for mu. This can be done using a symbolic toolbox, however it needs to end up being mu = function (theta, m, L, g). If using MATLAB or something similar, run the code to make sure it works.arrow_forwardA business case scenario and asked to formulate an appropriate software design solution. Theyshould complete the case and upload the solution. will be required to read the case,identify and document the key issues, problems, and opportunities presented, and then design,and develop an appropriate integrated design solution to the problem. mustdemonstrate good spreadsheet, database, analytical, and word-processing skills whendeveloping solutions. Additionally, must be creative and demonstrate synthesising andapplying Database Management and Data Analytics Principles learned in the course. They willalso need to research some aspects of the assessment. CASE BACKGROUNDMGMT SS STATS, an umbrella body that facilitates and serves various Social SecurityOrganizations/Departments within the Caribbean territories, stoodpoised to meet the needs of its stakeholders by launching an onlinedatabase at www.SSDCI.gov. The database will provide membersand the public access to the complete set of…arrow_forwardA business case scenario and asked to formulate an appropriate software design solution. Theyshould complete the case and upload the solution. will be required to read the case,identify and document the key issues, problems, and opportunities presented, and then design,and develop an appropriate integrated design solution to the problem. mustdemonstrate good spreadsheet, database, analytical, and word-processing skills whendeveloping solutions. Additionally, must be creative and demonstrate synthesising andapplying Database Management and Data Analytics Principles learned in the course. They willalso need to research some aspects of the assessment. CASE BACKGROUNDMGMT SS STATS, an umbrella body that facilitates and serves various Social SecurityOrganizations/Departments within the Caribbean territories, stoodpoised to meet the needs of its stakeholders by launching an onlinedatabase at www.SSDCI.gov. The database will provide membersand the public access to the complete set of…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





