(Rectangle Class) Create a class Rectangle with attributes length and width, each of which defaults to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(Rectangle Class) Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the rectangle's perimeter and area. It has set and methods for both length and width. The set methods should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. Write a program to test class Rectangle. get /* Ex 8.4 */ 1. Set Length 2. Set Width 3. Exit Choice: 1 Enter length: 3.0 Length: 3.000000 Width: 1.000000 Perimeter: 8.000000 Area: 3.000000 1. Set Length 2. Set Width 3. Exit Choice: 2 Enter width: 4 Length: 3.000000 Width: 4.000000 Perimeter: 14.000000 Area: 12.000000 1. Set Length 2. Set Width 3. Exit Choice: 3 // Note: you can create a default rectangle, print rectangle, //call set method to update, print again /* Ex 8.6 */ Monthly balances for one year at .04 Balances: Saver 1 Saver 2 Base $2000.00 $3000.00 Month 1: $2006.67 $3010.00 Month 2: $2013.36 $3020.03 Month 3: $2020.07 $3030.10 Month 1. 82006 on 33010 20 8.6 (Savings Account Class) Create class Savings Account. Use a static variable annual Inter- estRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculate Monthly Interest to calculate the monthly interest by multiplying the savingsBalance by annual Interest Rate divided by 12-this interest should be added to savings- Balance. Provide a static method modify Interest Rate that sets the annual InterestRate to a new value. Write a program to test class Savings Account. Instantiate two savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annual InterestRate to 4%, then calculate the monthly interest for each of 12 months and print the new balances for both savers. Next, set the annual Interest Rate to 5%, calculate the next month's interest and print the new balances for both savers. Perimeter: 14.000000 Area: 12.000000 1. Set Length 2. Set Width 3. Exit Choice: 3 // Note: you can create a default rectangle, print rectangle, //call set method to update, print again /* Ex 8.6 */ Monthly balances for one year at .04 Balances: Base Saver 1 Saver 2 $2000.00 $3000.00 Month 1: $2006.67 $3010.00 Month 2: Month 3: Month 4: Month 5: Month 6: Month 7: $2013.36 $3020.03 $2020.07 $3030.10 $2026.80 $3040.20 $2033.56 $3050.33 $2040.33 $3060.50 $2047.14 $3070.70 Month 8: Month 9: $2053.96 $3080.94 $2060.81 $3091.21 Month 10: $2067.68 $3101.51 Month 11: $2074.57 $3111.85 Month 12: $2081.48 $3122.22 After setting interest rate to .05 Balances: Saver 1 $2090.16 /* Ex 8.8 */ Saver 2 $3135.23 Checking increment Date object constructor for date 11/27/1988 8.8 (Enhancing Class Date) Modify class Date of Fig. 8.7 to perform error checking on the ini- tializer values for instance variables month, day and year (currently it validates only the month and day). Provide a method nextDay to increment the day by one. Write a program that tests method nextDay in a loop that prints the date during each iteration to illustrate that the method works cor- rectly. Test the following cases: a) incrementing into the next month and b) incrementing into the next year. After setting interest rate to .05 Balances: Saver 1 $2090.16 Ex 8.8 */ Saver 2 $3135.23 Checking increment Date object constructor for date 11/27/1988 Incremented Date: 11/28/1988 11/30/1988 Incremented Date: 11/29/1988 Incremented Date: Incremented Date: 12/1/1988 Incremented Date: 12/2/1988 Incremented Date: 12/3/1988 Incremented Date: 12/4/1988 Incremented Date: 12/5/1988 Incremented Date: 12/6/1988 Incremented Date: 12/7/1988 Incremented Date: 12/8/1988 Incremented Date: 12/9/1988 Incremented Date: 12/10/1988 Incremented Date: 12/11/1988 Tncromonted Dato. 12/12/1999 8.15 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class—the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to 1/2 and would be stored in the object as 1 in the numerator and 2 in the denomina- tor. Provide a no-argument constructor with default values in case no initializers are provided. Pro- vide public methods that perform each of the following operations: a) Add two Rational numbers: The result of the addition should be stored in reduced form. Implement this as a static method. b) Subtract two Rational numbers: The result of the subtraction should be stored in re- duced form. Implement this as a static method. c) Multiply two Rational numbers: The result of the multiplication should be stored in reduced form. Implement this as a static method. d) Divide two Rational numbers: The result of the division should be stored in reduced form. Implement this as a static method. e) Return a String representation of a Rational number in the form a/b, where a is the numerator and b is the denominator. f) Return a String representation of a Rational number in floating-point format. (Con- sider providing formatting capabilities that enable the user of the class to specify the number of digits of precision to the right of the decimal point.) Incremented Date: 11/28/1988 Incremented Date: 11/29/1988 Incremented Date: 11/30/1988 Incremented Date: 12/1/1988 Incremented Date: 12/2/1988 Incremented Date: 12/3/1988 Incremented Date: 12/4/1988 Incremented Date: 12/5/1988 Incremented Date: 12/6/1988 Incremented Date: 12/7/1988 Incremented Date: 12/8/1988 Incremented Date: 12/9/1988 Incremented Date: 12/10/1988 Incremented Date: 12/11/1988 Incremented Date: 12/12/1988 Incremented Date: 12/13/1988 Incremented Date: 12/14/1988 Incremented Date: 12/15/1988 Incremented Date: 12/16/1988 Incremented Date: 12/17/1988 Incremented Date: 12/18/1988 Incremented Date: 12/19/1988 Incremented Date: 12/20/1988 Incremented Date: 12/21/1988 Incremented Date: 12/22/1988 Incremented Date: 12/23/1988 Incremented Date: 12/24/1988 Incremented Date: 12/25/1988 Incremented Date: 12/26/1988 Incremented Date: 12/27/1988 Incremented Date: 12/28/1988 Incremented Date: 12/29/1988 Incremented Date: 12/30/1988 Incremented Date: 12/31/1988 Incremented Date: 1/1/1989 Incremented Date: 1/2/1989 Incremented Date: 1/1/1989 Incremented Date: 1/2/1989 Incremented Date: 1/3/1989 Incremented Date: 1/4/1989 Incremented Date: 1/5/1989 Incremented Date: 1/6/1989 /* Ex 8.15 */ Enter 1 for format: MM/DD/YYYY Enter for format: Month DD, YYYY Enter 3 for format: DDD YYYY Enter 4 to exit Choice: 1 Enter Month (1-12): 7 Enter Day of Month: 8 Enter Year: 2013 MM/DD/YYYY: 7/8/2013 Month DD, YYYY: July 8, 2013 DDD YYYY: 189 2013. Enter 1 for format: MM/DD/YYYY DDD YYYY: 189 2013 Enter 1 for format: MM/DD/YYYY Enter 2 for format: Month DD, YYYY Enter 3 for format: DDD YYYY Enter 4 to exit Choice: 2 Enter Month Name: July Enter Day of Month: 8 Enter Year: 2013 MM/DD/YYYY: 7/8/2013 Month DD, YYYY: July 8, 2013 DDD YYYY: 189 2013 Enter 1 for format: MM/DD/YYYY Enter 2 for format: Month DD, YYYY Enter 3 for format: DDD YYYY Enter 4 to exit Choice: 3 Enter Day of Year: 190 Enter Year: 2013 MM/DD/YYYY: 7/9/2013 Month DD, YYYY: July 9, 2013 DDD YYYY: 190 2013 Enter 1 for format: MM/DD/YYYY Enter 2 for format: Month DD, YYYY Enter 3 for format: DDD YYYY Enter 4 to exit Choice: 4 (Rectangle Class) Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the rectangle's perimeter and area. It has set and methods for both length and width. The set methods should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. Write a program to test class Rectangle. get /* Ex 8.4 */ 1. Set Length 2. Set Width 3. Exit Choice: 1 Enter length: 3.0 Length: 3.000000 Width: 1.000000 Perimeter: 8.000000 Area: 3.000000 1. Set Length 2. Set Width 3. Exit Choice: 2 Enter width: 4 Length: 3.000000 Width: 4.000000 Perimeter: 14.000000 Area: 12.000000 1. Set Length 2. Set Width 3. Exit Choice: 3 // Note: you can create a default rectangle, print rectangle, //call set method to update, print again /* Ex 8.6 */ Monthly balances for one year at .04 Balances: Saver 1 Saver 2 Base $2000.00 $3000.00 Month 1: $2006.67 $3010.00 Month 2: $2013.36 $3020.03 Month 3: $2020.07 $3030.10 Month 1. 82006 on 33010 20 8.6 (Savings Account Class) Create class Savings Account. Use a static variable annual Inter- estRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculate Monthly Interest to calculate the monthly interest by multiplying the savingsBalance by annual Interest Rate divided by 12-this interest should be added to savings- Balance. Provide a static method modify Interest Rate that sets the annual InterestRate to a new value. Write a program to test class Savings Account. Instantiate two savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annual InterestRate to 4%, then calculate the monthly interest for each of 12 months and print the new balances for both savers. Next, set the annual Interest Rate to 5%, calculate the next month's interest and print the new balances for both savers. Perimeter: 14.000000 Area: 12.000000 1. Set Length 2. Set Width 3. Exit Choice: 3 // Note: you can create a default rectangle, print rectangle, //call set method to update, print again /* Ex 8.6 */ Monthly balances for one year at .04 Balances: Base Saver 1 Saver 2 $2000.00 $3000.00 Month 1: $2006.67 $3010.00 Month 2: Month 3: Month 4: Month 5: Month 6: Month 7: $2013.36 $3020.03 $2020.07 $3030.10 $2026.80 $3040.20 $2033.56 $3050.33 $2040.33 $3060.50 $2047.14 $3070.70 Month 8: Month 9: $2053.96 $3080.94 $2060.81 $3091.21 Month 10: $2067.68 $3101.51 Month 11: $2074.57 $3111.85 Month 12: $2081.48 $3122.22 After setting interest rate to .05 Balances: Saver 1 $2090.16 /* Ex 8.8 */ Saver 2 $3135.23 Checking increment Date object constructor for date 11/27/1988 8.8 (Enhancing Class Date) Modify class Date of Fig. 8.7 to perform error checking on the ini- tializer values for instance variables month, day and year (currently it validates only the month and day). Provide a method nextDay to increment the day by one. Write a program that tests method nextDay in a loop that prints the date during each iteration to illustrate that the method works cor- rectly. Test the following cases: a) incrementing into the next month and b) incrementing into the next year. After setting interest rate to .05 Balances: Saver 1 $2090.16 Ex 8.8 */ Saver 2 $3135.23 Checking increment Date object constructor for date 11/27/1988 Incremented Date: 11/28/1988 11/30/1988 Incremented Date: 11/29/1988 Incremented Date: Incremented Date: 12/1/1988 Incremented Date: 12/2/1988 Incremented Date: 12/3/1988 Incremented Date: 12/4/1988 Incremented Date: 12/5/1988 Incremented Date: 12/6/1988 Incremented Date: 12/7/1988 Incremented Date: 12/8/1988 Incremented Date: 12/9/1988 Incremented Date: 12/10/1988 Incremented Date: 12/11/1988 Tncromonted Dato. 12/12/1999 8.15 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class—the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to 1/2 and would be stored in the object as 1 in the numerator and 2 in the denomina- tor. Provide a no-argument constructor with default values in case no initializers are provided. Pro- vide public methods that perform each of the following operations: a) Add two Rational numbers: The result of the addition should be stored in reduced form. Implement this as a static method. b) Subtract two Rational numbers: The result of the subtraction should be stored in re- duced form. Implement this as a static method. c) Multiply two Rational numbers: The result of the multiplication should be stored in reduced form. Implement this as a static method. d) Divide two Rational numbers: The result of the division should be stored in reduced form. Implement this as a static method. e) Return a String representation of a Rational number in the form a/b, where a is the numerator and b is the denominator. f) Return a String representation of a Rational number in floating-point format. (Con- sider providing formatting capabilities that enable the user of the class to specify the number of digits of precision to the right of the decimal point.) Incremented Date: 11/28/1988 Incremented Date: 11/29/1988 Incremented Date: 11/30/1988 Incremented Date: 12/1/1988 Incremented Date: 12/2/1988 Incremented Date: 12/3/1988 Incremented Date: 12/4/1988 Incremented Date: 12/5/1988 Incremented Date: 12/6/1988 Incremented Date: 12/7/1988 Incremented Date: 12/8/1988 Incremented Date: 12/9/1988 Incremented Date: 12/10/1988 Incremented Date: 12/11/1988 Incremented Date: 12/12/1988 Incremented Date: 12/13/1988 Incremented Date: 12/14/1988 Incremented Date: 12/15/1988 Incremented Date: 12/16/1988 Incremented Date: 12/17/1988 Incremented Date: 12/18/1988 Incremented Date: 12/19/1988 Incremented Date: 12/20/1988 Incremented Date: 12/21/1988 Incremented Date: 12/22/1988 Incremented Date: 12/23/1988 Incremented Date: 12/24/1988 Incremented Date: 12/25/1988 Incremented Date: 12/26/1988 Incremented Date: 12/27/1988 Incremented Date: 12/28/1988 Incremented Date: 12/29/1988 Incremented Date: 12/30/1988 Incremented Date: 12/31/1988 Incremented Date: 1/1/1989 Incremented Date: 1/2/1989 Incremented Date: 1/1/1989 Incremented Date: 1/2/1989 Incremented Date: 1/3/1989 Incremented Date: 1/4/1989 Incremented Date: 1/5/1989 Incremented Date: 1/6/1989 /* Ex 8.15 */ Enter 1 for format: MM/DD/YYYY Enter for format: Month DD, YYYY Enter 3 for format: DDD YYYY Enter 4 to exit Choice: 1 Enter Month (1-12): 7 Enter Day of Month: 8 Enter Year: 2013 MM/DD/YYYY: 7/8/2013 Month DD, YYYY: July 8, 2013 DDD YYYY: 189 2013. Enter 1 for format: MM/DD/YYYY DDD YYYY: 189 2013 Enter 1 for format: MM/DD/YYYY Enter 2 for format: Month DD, YYYY Enter 3 for format: DDD YYYY Enter 4 to exit Choice: 2 Enter Month Name: July Enter Day of Month: 8 Enter Year: 2013 MM/DD/YYYY: 7/8/2013 Month DD, YYYY: July 8, 2013 DDD YYYY: 189 2013 Enter 1 for format: MM/DD/YYYY Enter 2 for format: Month DD, YYYY Enter 3 for format: DDD YYYY Enter 4 to exit Choice: 3 Enter Day of Year: 190 Enter Year: 2013 MM/DD/YYYY: 7/9/2013 Month DD, YYYY: July 9, 2013 DDD YYYY: 190 2013 Enter 1 for format: MM/DD/YYYY Enter 2 for format: Month DD, YYYY Enter 3 for format: DDD YYYY Enter 4 to exit Choice: 4
Expert Answer:
Related Book For
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall
Posted Date:
Students also viewed these programming questions
-
Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the rectangles perimeter and area. Use set and get methods for both length and...
-
The pressure at the bottom of a swimming pool is evenly distributed. Suppose we look at a cast iron plate of 7272 kg lying on the ground with an area of 100 m2. What is the average pressure below...
-
Use Figure 15-9 to describe potential differences between leasing a piece of equipment with a capital lease and purchasing the equipment using a bank loan. In figure 15-9 Buying Leasing Capital...
-
The annual earnings of 14 randomly selected computer software engineers have a sample standard deviation of $3725. Use an 80% level of confidence. Assume the sample is from a normally distributed...
-
You are considering purchasing a defunct mine in Africa. Your firm has developed a method to extract valuable rare earth minerals from the mining entrails. The cost of the mine together with the...
-
Standard-costing method, assigning costs. Refer to the information in Exercise 17-24. Suppose Bio Doc determines standard costs of $8.25 per equivalent unit for direct materials and $12.70 per...
-
Write a program call seq-multiplier which will print out numbers in a sequence multiplied by a number input by a user. Your program should store the sequence [52, 1, 34, 23, 18, -9, 21, 4, 79] in a...
-
Maria Sawatsky has $3000 to invest in a financial institution. She decides to purchase a step bond that guarantees her 334 percent for the first year, 412 percent for the second year, and 514 percent...
-
Your client was fired from her job. She claims the employer engaged in discrimination and that the employer's actions violated the law. Your client worked for the employer in Maryland. The employer...
-
1. What are the three criteria necessary for an effective and efficient network? 2. What are the advantages of a multipoint connection over a point-to-point connection? 3. For n devices in a network,...
-
Dalton Enterprises, a manufacturing firm specializing in custom products, utilizes a job-order costing system. The following data was provided for the recently concluded financial year: Beginning...
-
Write two html elements that displays one checkbox and one label as shown below. When the label is clicked, the checkbox is selected/unselected. If the form is submitted, the valueems "RRR is sent to...
-
You have just won $2 million in a lottery. You use the money to purchase an apartment building that brings you $800000 per year in profits indefinitely. What is your internal rate of return in %?...
-
A jet of water impinges on a series of curved vanes at an angle of 30 to the direction of motion of the vanes while entering and leaves the vanes horizontally. The head under which the jet issues...
-
TRUE-FALSE QUESTIONS 1. In terms of preliminary analytical procedures, assume that the company has introduced a new product with a low price point and significant customer demand. The auditor would...
-
With your group, write a plan for a JAD session that takes the place of personal interviews. Include relevant participants, suggested setting, and so on.
-
List the 10 main sections of the systems proposal.
-
What is it that a use case model describes?
-
Canada removed all duties and quotas on imports from Bangladesh in 2003. Since that time, Bangladesh has become the second largest source (after India) of Canadian merchandise imports from South...
-
A firm has the cost curve \(C(q)=100+150 q-\) \(46 q^{2}+5 q^{3}\). What are the equations of the firm's marginal cost, average variable cost, and average cost curves? What are the minimum values of...
-
A firm in Saudi Arabia uses capital and labor in its production process. The hourly cost of labor is SR30 and the initial rental rate of capital is SR60 per hour. What is the firm's isocost line? How...
Study smarter with the SolutionInn App