Programming Logic and Design, 8th Edition Chapter 11 Programming Exercises 1.Complete the following tasks: a. Design a class named Circlewith fields named radius, area, and diameter. Include a constructor that sets the radius to 1. Include get methods for each field, but include a set method only for the radius. When the radius is set, do not allow 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 approximately 3.14). Create the class diagram and write the pseudocode that defines the class.
b. Design an application that declares two Circles. Set the radius of one manually, but allow the other to use the default value supplied by the constructor. Then, display each Circle’s values. 2.Complete the following tasks:a. Design a class named PhoneCallwith four fields: two strings that hold the 10-digit phone numbers that originated and received the call, and two numeric fields that hold the length of the call in minutes and the cost of the call. Include a constructor that sets the phone numbers to Xs and the numeric fields to 0. Include get and set methods for the phone number and call length fields, but do not include a set method for the cost field. When the call length is set, calculate the cost of the call at three cents 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() : num Pseudocode: class PhoneCall Declarations private string origCall private string recCall private num length private num cost public PhoneCall() origCall = “XXXXXXXXXX” recCall = “XXXXXXXXXX” length = 0 cost = 0 return public void setOrigCall(string number) origCall = number return public void setRecCall(string number) recCall = number return public void setLength(num len) length = len if length > 10 then cost = (3 * 10) + (2 * (length – 10)) else cost = 3 * length endif return public string getOrigCall() return origCall public string getRecCall() return recCall
You've reached the end of your free preview.
Want to read all 34 pages?
- Fall '15
- Object-Oriented Programming, Subroutine, NUM