HW 8

pdf

School

Ohio State University *

*We aren’t endorsed by this school

Course

2221

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

4

Uploaded by sritanvigottumukkala64

Report
Answer all Still Awake? questions (1-1..1-3) from Organizing Theme for SW1/SW2 1-1) Imagine a car rolling down the assembly line. List some of the components that will be used to assemble the car. Which of the components do you think are manufactured from scratch at the assembly plant? I don’t think most of these components are made from scratch at the assembly factory, they might have been manufactured somewhere else and shipped to the assembly factory. Here are components that will be used to assemble the car: - Engine - Hood - Seats - Doors - Roof - Tires 1-2) We know that student housing can sometimes be a little lacking. Nonetheless, take a look around your room and list some of the components that were assembled to build your room. - Desk - Bed - Microwave - Fridge - Walls - Window - Floor - Tile - Door 1-3) Suppose you were to select components for your dream computer. What components do you think you’ll need to select? Which of the components do you think are built from scratch by the computer company that puts the system together? I think some of the parts might be bought by the company from scratch but most of them might be manufactured from somewhere else and shipped to the company to assemble it. Keyboard, keys, touchpad, CPU (possibly built by company), and display screen Answer all Still Awake? questions (2-1..2-5) from Review of Basic Concepts 2-1) What is the purpose of the import command in Java?
Using the import command in Java, you can bring in classes and packages from external libraries or other parts of your program. 2-2) What are the fundamental differences between primitive types and component types in Java? The difference between primitive types and component types in Java is that primitive types are basic data types that are built into the Java language (Example: Boolean, byte, char, int), while component types are classes that represent data types (Example: String, Arraylist) 2-3) Suppose a program wanted to keep track of whether a water valve is open. For this purpose, which (primitive or component) type would the programmer choose? Boolean because it has two possible values, true or false. And the water valve is either open or closed. True for open valve and False for closed valve. Answer all Still Awake? questions (3-1..3-6) from Component Client View: Model 3-1) Name two things that you understand how to use and, yet, you do not understand the internal details of how these things work. - How a camera is able to capture pictures - How bluetooth works 3-2) Consider two possibilities. First, people understand all the details of how something works before they use it. Second, people figure out what to do to use something before trying to figure out all the details of how something works. As a general rule, which of these two possibilities do you think is most prominent in society? Can you think of any reason why the same should not apply to using software components? I think the second possibility is more prominent in society because most of the time its unnecessary for them to understand the details on how it works. I think the same could be used for software components but maybe trying to understand the details as you try to figure out how to use it might be a better approach. 3-3) Give two additional examples of mathematical models. The examples need not be from computer science. Exponential decay and Exponential growth 3-4) Why do you think scientists and engineers use mathematics to describe or model things that are of interest to them? Explain They use mathematics to describe things because it is precise and provides clarity.
3-5) Give three example values that lie in the gray-shaded region in the figure “The Effect of a Constraint”. 12, 0, True (hours, minutes, seconds) 3-6) There is no constraint in the definition of the math subtype? AM_PM_CLOCK_MODEL. Why not? The math subtype still awake isn't constrained because abstract concepts like time, AM/PM, and clocks don't inherently possess a state of wakefulness. Answer all Still Awake? questions (4-1..4-13) from Component Client View: Methods 4-1) Carefully consider what kinds of methods you’d like to have available for a clock variable. What do you think a client should be able to do with a clock variable? The client should be able to change the time, the clock has to adjust to time zones and when its daylight saving 4-2) How do we know that variables described by AMPMClock have values that are 4-tuples? AMPMClock variables are 4-tuples because the class definition specifies they are made up of hour, minute, second, and microsecond components. 4-3.) Do you think that requires clauses are concerned with incoming values or with outgoing values of parameters? Explain. If your answer is incoming values, explain why the requires clause for setHours is not specified as 1 <= #new_hours <= 12. 4-4. Suppose that myClock = (11,25,48,true) and that newHours = 3. What will be the value of myClock and newHours after the method call myClock.setHours(newHours)? Parameter values are what require clauses are concerned with. The requires clause for setHours is not specified as 1 <= #new_hours <= 12 because the setHours method is intended to set the hour value of the clock, and it is reasonable to allow any integer value within the range of valid hour values (i.e., 0-23). The range 1-12 would only be appropriate if the method were specifically designed to handle 12-hour time formats. 4-4) Give the complete client description of setSeconds. - void setSeconds(int newSeconds) - Sets this.minutes to newMinutes. - Parameters: newSeconds – the new seconds for this - Updates:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
this.seconds - Requires: 0 <= newSeconds <= 59 - Ensures: this.seconds = newSeconds 4-6) Suppose that myClock = (11,25,48,true) and that newMinutes = 31. What will be the value of myClock and newMinutes after the method call myClock.setMinutes(newMinutes)? How about after the method call myClock.setMinutes(52)? myClock will be set to (11,31,48,true) and then (11,52,48,true). 4-7) Suppose that myClock = (11,25,48,true) and am = true. What will be the value of myClock and am after the method call myClock.setAM(am)? myClock will be set to (11,25,48,true). 4-8) What is the type of the return value for the function isAM? Explain why this is the type. Boolean because AM is a true of false value. 4-9) Explain how to read the ensures clause of isAM. Ensures clause states that the return value of isAM is equal to the value of this.am. 4-10) In the function isAM, what is the outgoing value of this? 4-11. Provide a complete client description of the minutes method. The outgoing value of this is #this. 4-12) Provide a complete client description of the seconds method. - void seconds() Reports this.seconds - Returns: this.seconds - Ensures: seconds = this.seconds