Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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


image text in transcribed imageimageimageimageimageimageimageimageimage

(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 classthe 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

Step by Step Solution

3.49 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

What is the likelihood function for a logistic regression model?

Answered: 1 week ago

Question

List the 10 main sections of the systems proposal.

Answered: 1 week ago

Question

What is it that a use case model describes?

Answered: 1 week ago