Course Hero Logo

Ch11_Examples - Programming Logic and Design, 8th Edition...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 4 out of 34 pages.

Programming Logic and Design, 8th EditionChapter 11Programming Exercises1.Complete the following tasks:a. Design a class namedCirclewith fields namedradius,area, anddiameter. Include a constructor that sets the radius to 1. Include get methods foreach field, but include a set method only for the radius. When the radius is set, do notallow it to be zero or a negative number. When the radius is set, calculate the diameter(twice the radius) and the area (the radius squared times pi, which is approximately3.14). Create the class diagram and write the pseudocode that defines the class.
returnpublic num getRadius()return radiuspublic num getArea()return areapublic num getDiameter()return diameterendClassb. Design an application that declares twoCircles. Set the radius of one manually,but allow the other to use the default value supplied by the constructor. Then, displayeachCircle’s values.
2.Complete the following tasks:a. Design a class namedPhoneCallwith four fields: two strings that hold the 10-digit phone numbers that originated and received the call, and two numeric fields thathold the length of the call in minutes and the cost of the call. Include a constructorthat sets the phone numbers toXs and the numeric fields to 0. Include get and setmethods for the phone number and call length fields, but do not include a set methodfor the cost field. When the call length is set, calculate the cost of the call at threecents per minute for the first 10 minutes, and two cents per subsequent minute. Createthe class diagram and write the pseudocode that defines the class.
Diagram:PhoneCall-origCall: string-recCall: string-length: num-cost: num+setOrigCall(number : string) : void+setRecCall(number : string) : void+setLength(len : num) : void+getOrigCall() : string+getRecCall() : string+getLength() : num+getCost() : numPseudocode:class PhoneCallDeclarationsprivate string origCallprivate string recCallprivate num lengthprivate num costpublic PhoneCall()origCall = “XXXXXXXXXX”recCall = “XXXXXXXXXX”length = 0cost = 0returnpublic void setOrigCall(string number)origCall = numberreturnpublic void setRecCall(string number)recCall = numberreturnpublic void setLength(num len)length = lenif length > 10 thencost = (3 * 10) + (2 * (length – 10))elsecost = 3 * lengthendifreturnpublic string getOrigCall()return origCallpublic string getRecCall()return recCall

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 34 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture