Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. (Merge two sorted lists) Write the following method that merges two sorted li

ID: 3592756 • Letter: 2

Question

2. (Merge two sorted lists) Write the following method that merges two sorted lists into a new sorted list. void merge (const int listi], int sizel, const int list2, int size2, int 1ist3]) Implement the method in a way that takes at most sizesize2 comparisons. Write a test program that prompts the user to enter two sorted lists and displays the merged list. Here is a sample run. Note that the first number (number in red) in the input indicates the number of the elements in the list. This number is not part of the list Enter 1istl: 51 5 16 61 111 Enter 1ist2: 4 2 4 5 6 The merged list is 1 2 4 5 5 6 16 61 111 3. (The Account class) Design a class named Account that contains A private int data field named id for the account (default 0) A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate A no-arg constructor that creates a default account. A constructor that creates an account with the specified id and initial balance The accessor and mutator methods for id, balance, and annualInterestRate The accessor method for dateCreated A method named getMonthlyInterestRate0 that returns the monthly interest rate A method named getMonthlyInterest) that returns the monthly interest. A method named withdraw that withdraws a specified amount from the account A method named deposit that deposits a specified amount to the account. Draw the UML diagram for the class and then implement the class. (Hint: The method getMonthlyInterest() is to return monthly interest, not the interest rate Monthly interest is balance monthlyInterestRate. monthlyInterestRate is annualInterestRate12. Note that annualInterestRate is a percentage, eg, like 45%. You need to divide it by 100) Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual i terest rate of 4.5%. Use the withdraw method to withdraw $2,500, use the deposit method to deposit S3,000, and print the balance, the monthly interest, and the date when this account was created

Explanation / Answer

Answer 2) Merge two sorted list:

3)

//Main function calling:

problems and my thinking... import java.util.Date; public class Account { // Private data fields for Account object private int id = 0; // Assign default value private double balance = 0; // Assign default value private double annualInterestRate = 0; // Assign default value private Date dateCreated; // Here I'm just letting the compiler know there is a Date object associated with each Account object // but no value for this object is referenced; value referenced when Account object is created by constructors // no arg Constructor for Account public Account() { dateCreated = new Date(); // Here is where I believe you go wrong, create Date object when Account object is created (new Date()) // and assign it's reference to dateCreated, this is why you're getting null returned. // You've got a Date object but it never gets a reference to any actual data. // What you've done is sort of like creating an Array object but not populating it with data; basically a // shortcut that doesn't point to anything hence null, empty. // Also note that I don't have to assign default values for other data fields since I assigned them above. } // Constructor with id and balance args public Account(int newID, double newBalance) { dateCreated = new Date(); // And again for argument constructor id = newID; balance = newBalance; } // Accessor method for id public int getID() { return id; } // Mutator method for id public void setID(int newID) { id = newID; } // Accessor method for balance public double getBalance() { return balance; } // Mutator method for balance public void setBalance(double newBalance) { balance = newBalance; } // Accessor method for annualInterestRate public double getAnnualInterestRate() { return annualInterestRate; } // Mutator method for annualInterestRate public void setAnnualInterestRate(double newAnnualInterestRate) { annualInterestRate = newAnnualInterestRate; } // Accessor method for dateCreated; NOTE: no mutator method for dateCreated required... public Date getDateCreated() { return dateCreated; } // Method for returning monthlyInterestRate calculated from annualInterestRate public double getMonthlyInterestRate() { return annualInterestRate/12; } // Method for withdrawing specified amount public void withdraw(double withdrawAmount) { balance -= withdrawAmount; } // Method for depositing specified amount public void deposit(double depositAmount) { balance += depositAmount; } }  

And test function for it :