Answered You can buy a ready-made answer or pick a professional tutor to order an original one.

QUESTION

Ex 8.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 ge

Ex 8.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 get 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.

Ex : 8.6 (Savings Account Class) Create class SavingsAccount. Use a static variable annualInterestRate 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 calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12—this interest should be added to savings- Balance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a program to test class SavingsAccount. Instantiate two savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest for each of 12 months and print the new balances for both savers. Next, set the annualInterestRate to 5%, calculate the next month’s interest and print the new balances for both savers.

Ex :8.14 (Date Class) Create class Date with the following capabilities:

a) Output the date in multiple formats, such as

MM/DD/YYYY

June 14, 1992

DDD YYYY

b) Use overloaded constructors to create Date objects initialized with dates of the formats

in part (a). In the first case the constructor should receive three integer values. In the

second case it should receive a String and two integer values. In the third case it should

receive two integer values, the first of which represents the day number in the year.

Show more
  • @
  • 22 orders completed
ANSWER

Tutor has posted answer for $10.00. See answer's preview

$10.00

** ** ********** ****** ****** a ***** ********* **** attributes ****** *** ***** **** ** ***** ******** ** * ******* ******* **** ********* *** rectangle’s ********* *** area ** *** *** *** get methods for both ****** *** ***** *** *** methods should verify **** ****** *** width *** each floating-point ******* ****** **** 00 *** **** **** *** Write * ******* ** test ***** Rectangle Solution ********** ************ class Rectangle *** ******* float ******* ******* ***** ******** ****** Rectangle() * ********** * 1; ********* * ** *** ****** *************** ****** float ****** * ********************** thissetWidth(width); }  ****** ***** *********** { ****** ******* *** public **** *************** length) * ** ***************** { thislength * ******* * }  ****** ***** getWidth() { ****** ****** *** ****** void setWidth(float ****** * if **************** * ********* = width; * }  private ******* ************* ****** * if (value **** && value <= 20) { return ***** * **** * ************************ enter ***** ** range ******* ****** ****** * *** ****** ***** ************** *** ***** ********* = * * *********** * *********** ****** perimeter; *** ****** ***** ********* *** ***** **** * thislength * ********** return area; ********** ************ ***** ************* *** ****** static void main(String[] ***** {  ********* **** * *** ************ ************************** = " + *************** + * ***** * ** **************** ********************** ** Rectangle * * + *************** *************************** of ********* * " * rec1getPerimeter());  ********** length *** ***** ***************** ****************** ************************** = " * rec1getLength() * * ***** = * + **************** ********************** ** Rectangle : " * *************** Systemoutprintln("Perimeter ** ********* * " * ********************** ** ******* *** ****** *** width **** **** ** ******************* ***************** ****************** ************************** * " * rec1getLength() * * ***** * * * **************** ********************** ** ********* : * * *************** *************************** ** Rectangle * * * rec1getPerimeter()); *********************** * ** ***** * ****** ** Rectangle * *********** of Rectangle : ********** = ** Width * ****** ** ********* * ************ ** ********* : *********** enter value ** ***** ********** ***** ***** ** range 1-20 Length * ** ***** * ****** ** ********* * 320Perimeter ** ********* * ***** * ** ******** ******* ****** ****** ***** ************** *** * static variable ****************** ** store *** annual ******** **** *** *** ******* ******* Each ****** ** *** ***** contains * ******* instance variable ************** ********** the ****** *** ***** currently *** ** ************** ****** ************************ ** calculate *** ******* interest by *********** *** ************** ** ****************** ******* ** ********* ******** ****** ** added ** ******** Balance ******* * ****** method ****************** **** sets *** ****************** to * new ***** ***** * program ** **** ***** ************** Instantiate two ************** ******* saver1 *** ****** **** balances ** ******* *** $300000 respectively *** ****************** to ** **** calculate the monthly ******** *** each ** 12 ****** *** print *** new ******** *** both savers **** *** the ****************** ** ** ********* the **** ********* ******** *** ***** the *** ******** *** **** *********************** ******* ************ class SavingAccount *** ****** ****** ***** annualInterestRate * **** ******* float **************** ****** *************** * *** ****** ******************* savingBalance) * thissavingBalance * ************** *** ****** ***** ************************** * ***** interest = ****************** * ******************* / ***** ********************************** * ********** ****** ********* }  ****** ****** **** ************************ interest) { ****************** * interest; *** ****** ***** ****************** * return savingBalance; }  ****** void setSavingBalance(float ************** * ***************** * ************** *************** **** Class public ***** ***************** *** ****** ****** **** ************* ***** *** SavingAccount ****** = *** ******************** ************* ****** = *** SavingAccount(3000);  ************************************* Systemoutprintln("\nAnnual Interest -> * * *********************************** ************************** ******* * ********* ****************** ************************** Account * Saver2"); ****************** SavingAccountmodifyInterestRate(5);  Systemoutprintln("\nAnnual Interest ***** * * SavingAccountannualInterestRate);  ************************** ******* * ********* ****************** Systemoutprintln("\nSaving ******* * Saver2"); ****************** *** public ****** **** display(SavingAccount savingAccount) * for **** i = 1; i ***** *** i++) * ************************** *** ***** * * * * * -> ** ****************** ****************************************** ************************ ******* after month * + i + " -> * * Stringformat("%2f" ********************************** * } }Output: Annual ******** ***** 40 Saving ******* * ************** *** ***** 1 ***** 667Saving Balance after ***** * ***** ************** *** month * ***** ********* Balance ***** ***** * -> ************** *** ***** * ***** ********* ******* after month 3 ***** ************** *** ***** * ***** ********* ******* ***** ***** * ***** ************** for month * -> ********* Balance ***** ***** * ***** ************** for month * ***** 678Saving Balance ***** ***** * ***** 204033Interest for ***** 7 ***** ********* ******* ***** ***** * ***** ************** for ***** * -> ********* Balance ***** month 8 ***** ************** *** ***** 9 ***** ********* ******* ***** ***** * ***** ************** *** ***** 10 ***** ********* Balance ***** ***** ** ***** ************** *** month 11 ***** ********* ******* ***** ***** ** -> ************** for ***** ** -> ********* ******* ***** ***** ** ***** ************** ******* * Saver2Interest for ***** 1 ***** 1000Saving ******* ***** ***** * ***** ************** *** month 2 ***** ********** ******* ***** ***** * -> 302003Interest for month 3 ***** 1007Saving ******* ***** ***** 3 ***** ************** *** ***** 4 ***** 1010Saving Balance ***** ***** * -> 304020Interest *** ***** * ***** ********** ******* after month * ***** 305033Interest *** ***** * ***** ********** ******* ***** ***** * ***** ************** *** month * ***** ********** Balance after ***** 7 ***** ************** for ***** * -> 1024Saving Balance ***** ***** * -> ************** *** ***** * ***** 1027Saving ******* ***** ***** 9 -> ************** *** ***** ** ***** ********** ******* ***** month ** ***** 310151Interest for ***** ** -> ********** ******* ***** month ** ***** ************** *** month ** ***** ********** ******* ***** ***** 12 ***** ************** ******** -> ********** ******* : ************** *** ***** * -> ********* ******* ***** ***** * ***** 209016Interest *** month 2 ***** 871Saving ******* after ***** * ***** ************** for month 3 ***** ********* ******* after ***** 3 -> ************** for month * ***** 878Saving Balance ***** ***** 4 ***** ************** for ***** * -> 882Saving Balance ***** month 5 ***** ************** for ***** 6 ***** ********* ******* after month * ***** 213407Interest *** month 7 ***** ********* ******* ***** ***** * ***** ************** *** ***** * ***** ********* ******* ***** ***** * ***** ************** for ***** 9 -> 897Saving ******* after ***** * -> ************** *** ***** ** ***** 900Saving ******* ***** ***** ** ***** ************** *** ***** ** ***** ********* ******* ***** ***** 11 -> ************** *** ***** 12 ***** ********* ******* ***** ***** ** ***** ************** ******* * ************** *** ***** * -> ********** Balance ***** ***** * ***** ************** *** ***** * -> ********** ******* ***** ***** 2 ***** ************** *** ***** 3 ***** ********** Balance ***** ***** * ***** ************** for ***** * -> 1317Saving ******* ***** ***** 4 -> 317459Interest *** ***** * ***** ********** Balance after ***** * ***** ************** for ***** * -> 1328Saving ******* ***** ***** * ***** ************** *** ***** * ***** ********** ******* after ***** 7 ***** ************** for month * ***** ********** ******* ***** month * ***** ************** *** ***** * ***** 1345Saving ******* ***** month * ***** ************** *** ***** 10 ***** 1351Saving ******* ***** ***** ** ***** ************** for ***** ** ***** ********** ******* ***** month ** -> 326835Interest for ***** ** ***** ********** Balance ***** ***** ** ***** ************** **** ***** ****** Create class **** with *** ********* *************** ****** *** date in ******** formats **** **************** ** 1992DDD ****** *** overloaded constructors to ****** **** ******* initialized **** ***** ** the ********* **** *** In *** first case *** *********** should receive ***** integer ****** ** thesecond case ** ****** receive * ****** *** *** ******* ****** ** the ***** **** ** shouldreceive *** ******* values the ***** ** which represents *** *** ****** ** *** ***************** ************** ***** **** * ******* *** ****** ******* *** **** private *** ***** ****** Date(int month *** *** *** ***** * ********* * month; ******* * **** ******** * ***** } public *********** ***** int *** *** ***** * thismonth = **************** thisday * **** thisyear * year; * private ***** *************** { // ** ** **** in **** month ***** ************* * * 31 // January **** % 4 ** * 29 : ** ** ******** *** **** **** **** 29 days else ** ***** ** ** March ** // ***** ** ** *** ** ** **** 31 // July 31 ** August 30 // ********* ** // ******* ** ** ******** ** // ******** ** ****** days_in_month; } ****** Date(int dayOfYear int year) { thisyear = year; *** * * ** *** ********* = ********** for ** * ** * < days_in_month()length; i++) ** ********** > days_in_month()[i]) ********* ** ******************* **** ****** ********* = * + ** thisday * ********** * private *** ************** * *** ****** * ** *** (int * * ** * **** ********* - ** i++) daySum += ******************* daySum ** ******** ****** daySum; *** ********* public ****** ********** { ****** ********* * **** * ********* * **** * format3() + "\n" * ***** * ******* ****** **************** * ****** ***** * ************************* ** (monthlength() ** 1) ***** = *** * ****** return ****** } ******* String getDayString() * ****** *** = StringvalueOf(thisday); ** ************ ** ** day * *** + day; return day; } private String *************** * return StringvalueOf(thisyear); } private ****** getDayOfYearString() * ****** *** * StringvalueOf(getDayOfYear()); ** ******* ****** for **** * = 0; * < ** **** *** * ************ ***** * * ** * "0") * day; ****** **** } private ****** format1() * ****** **************** * "/" * getDayString() * *** * **************** * private ****** format2() * String month * ******************** - 1]toLowerCase(); ** ***** ******** ******* month * monthsubstring(0 *************** + ****************** return ***** * * " + getDayString() + " " * **************** } ******* ****** format3() * ****** ******************** * * * * getYearString(); * private ****** final ******** ********** * * "JANUARY" ********** ******* "APRIL" ***** ****** ****** ******** "SEPTEMBER" ********* "NOVEMEBER" ********** ** ******* static *** *************** ****** { for **** * * ** * **** ***************** i++) ** ***************************************** return i * ** return -1; ******** Class: public class DateTest { ****** ****** **** ************* ***** { **** ***** * new Date(6 ** ****** ********************************** ******************* Date ***** * *** Date("January" 12 ****** ********************************** ******************* **** ***** * new ******** ****** Systemoutprintln(date3toString()); ******************* ************************* ** ******* *************************** 12 ******* 1987   05/02/1998May ** ******* ****

Click here to download attached files: Chapter 1-2_ProgrammingAssignment.docx
or Buy custom answer
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question