Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.time.LocalDate; import java.time.temporal.ChronoUnit; public class MyDate { private int year; private int month; private int day; // default constructor public MyDate() { year =
import java.time.LocalDate; import java.time.temporal.ChronoUnit; public class MyDate { private int year; private int month; private int day; // default constructor public MyDate() { year = 2000; month = 1; day = 1; } // parameterized constructor public MyDate(int year, int month, int day) { this.year = year; this.month = month; this.day = day; } // getter for year public int getYear() { return year; } // getter for month public int getMonth() { return month; } // getter for day public int getDay() { return day; } // addDays to current day public void addDays(int days) { // using localdate class to add days. LocalDate date = LocalDate.of(year, month, day).plusDays(days); year = date.getYear(); month = date.getMonthValue(); day = date.getDayOfMonth(); } public void addWeeks(int week) { // adding weeks(1 week = 7 days) using addDays method addDays(7 * week); } // number of days between two dates public int daysTo(MyDate other) { LocalDate date1 = LocalDate.of(year, month, day); LocalDate date2 = LocalDate.of(other.getYear(), other.getMonth(), other.getDay()); return (int) ChronoUnit.DAYS.between(date1, date2); } // check if current year is a leapYear. public boolean isLeapYear() { if(year % 100 == 0 && year % 400 == 0) return true; if(year % 100 != 0 && year % 4 == 0) return true; return false; } // toString method. @Override public String toString() { return year + "/" + month + "/" + day; } }Problem 3: The Account Class (Account.java and Account_Test.java) Given the following UML, finish the definition of the Account class in java source file Account.java. One of the data field of the Account class is the MyDate class, which is the class you defined in Problem 2. Account - id: String -balance: double - annualInterestRate: double -date Created: MyDate + Account + Account(id:String , balance double rate:double, date_MyDate) + getID():String + getBalance():double + getAnnualInterestRate():double + getDate():MyDate + setAnnuallnterestRate(rate:double) + get MonthlyInterestRate():double + getMonthlyInterest():double + withdraw(amount:double):void + depositamount.double):void + transfer(other:Account, amount:double):void + toString: String The non-argument constructor will create an Account object with id to be null, balance and annuallnterestRate to be 0, and date Created to be null. The argument Constructor will create an Account object with id, balance, annualinterest Rate and dateCreated set to specific values. getID(): return the ID of an account object .getBalance(): return the current balance of this account object .getDate(); return the Date of this account object .setAnnualInterestRate(double): set the annual interest rate to be specific value .getMonthlyInterestRate(): return the monthly interest rate of this account. MonthlyInterestRate is annualInterestRate/12. Please return the MonthlyInterestRate in its percentage form, i.e. 0.045 is 4.5%. .getMonthlyInterest(): monthly interest can be calculated as balance monthlyInterestRate. .getMonthlyInterest(): monthly interest can be calculated as balance monthlyInterestRate. withdraw(double): will withdraw a certain amount of money from this account. deposit(double): will deposit a certain amount of money from this account transfer(other:Account, amount:double): will transfer a certain amount of money from this account to the other account. .toString(): will concatenate the ID, annuallnterest Rate and current balance to a String. Note: display the annualInterest Rate in its percentage form. Once the definition for the Account class is done, write a client program as Account_test.java, in which you need to the following things: Create one account object account with ID of 1122, a balance of $20,000, an annual interest rate of 4.5%, and the date of the day when you create this object. Create another account object account with ID of 2233, a balance of $1,000, and an annual interest rate of 4.5%, and the date of the day when you create this object. Display for the above two account objects their ID, balance, annuallyinterestRate, monthlyInterestRate and the date created. Suppose we construct transactions on account for successive 5 months, and in each month, you will: + Withdraw an arbitrary amount of money within the range of [0, 2000) from accounti. Display an error message if no more money can be withdrawn from this account. + Deposit an arbitrary amount of money within the range of [0,5000] to accounti. + Display at the end of each month for account its balance and monthlyInterest. Based upon the balance of accounti after the previous step. Transfer $2000 from account to account2, if there is enough money in account to make the successful transaction. Display the balance of account and accoun2 after the transaction. Date 2020/3/10 2020/3/10 Outputs: ID Balance AnnualyInterest Rate MonthlyInterestRate 1122 20000 4.5% 0.375% 2233 1000 4.5% 0.375% Month ID Balance MonthlyInterest 1 1122 19500 73.125 2 1122 23265 872.4375 3 1122 18052 676.95 4 1122 16000 600 5 1122 20000 750 ID Balance 112218000 2233 3000
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started