Suppose a file named Exercise17_07.dat has been created using the ObjectOutputStream. The file contains Loan objects. The
Question:
Suppose a file named Exercise17_07.dat has been created using the ObjectOutputStream. The file contains Loan objects. The Loan class in Listing 10.2 does not implement Serializable. Rewrite the Loan class to implement Serializable. Write a program that reads the Loan objects from the file and displays the total loan amount. Suppose you don?t know how many Loan objects are there in the file, use EOFException to end the loop.
Listing
Transcribed Image Text:
public class Loan { private double annualInterestRate; private int numberofYears; private double loanAmount; private java.util.Date loanDate; 5 /** Default constructor */ public Loan() { this(2.5, 1, 1000); 10 11 12 /** Construct a loan with specified annual interest rate, 13 number of years, and loan amount */ public Loan(double annualInterestRate, int numberOfYears, double loanAmount) { this. annualInterestRate = annualInterestRate; this.number0fYears = number0fYears; this. loanAmount = loanAmount; loanDate - new java.util.Date(); 14 15 16 17 18 19 20 21 22 23 /** Return annualInterestRate */ public double getAnnualInterestRate() { return annualInterestRate; 24 25 26 27 28 29 30 /** Set a new annualInterestRate */ public void setAnnualInterestRate(double annualInterestRate) { this. annualInterestRate = annualInterestRate; 31 32 33 /** Return numberofYears */ public int getNumberofYears () { return number0fYears; 34 35 36 37 38 /** Set a new numberOfYears */ public void setNumberofYears(int numberofYears) { this.numberofYears = number0fYears; 39 40 41 42 43 /** Return loanAmount */ public double getLoanAmount () { return loanAmount; 44 45 46 47 48 /** Set a new 1loanAmount */ public void setLoanAmount (double loanAmount) { this. loanAmount = loanAmount; 49 50 51 52 /** Find monthly payment */ public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - (1 / Math.pow(1i + monthlyInterestRate, number0fYears * 12))); return monthlyPayment; 53 54 55 56 57 58 59 60 61 /** Find total payment */ public double getTotal Payment () { double totalPayment = getMonthlyPayment () * numberofYears * 12; return totalPayment; 62 63 64 65 66 67 /** Return loan date */ public java.util.Date getloanDate() { return loanDate; 68 69 70 71 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 75% (12 reviews)
Program Plan Define the Loan class with Serializable Define the file with using Obj ectOnput St ream ...View the full answer
Answered By
Muhammad Umair
I have done job as Embedded System Engineer for just four months but after it i have decided to open my own lab and to work on projects that i can launch my own product in market. I work on different softwares like Proteus, Mikroc to program Embedded Systems. My basic work is on Embedded Systems. I have skills in Autocad, Proteus, C++, C programming and i love to share these skills to other to enhance my knowledge too.
3.50+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Implement a class named BitOutputStream, as shown in Figure 17.22, for writing bits to an output stream. The writeBit(char bit) method stores the bit in a byte variable. When you create a...
-
In the following exercises, you will use the data in the TAL Distributors database shown in Figure 2-1 in Chapter 2. (If you use a computer to complete these exercises, use a copy of the original TAL...
-
a. Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set()...
-
A study in Batu Pahat General Hospital's on patient account division has compiled data on the age of accounts receivables. The data collected indicates that the age of the accounts follows a normal...
-
The budget set is convex. Remark 1.22 In establishing that the budget set is compact (exercise 1.231), we relied on the assumption that the choice was over n distinct commodities so that the...
-
Find the maximum and minimum values of v = 1 + 2 sin( t + ), given = 1000 rad/s and = 3 rad. Determine if the function v is periodic, and find its frequency f and period T. Specify the phase angle...
-
It looks to me that you have devoted everything to this company and they have treated you badly. Is that right?
-
Heidebrecht Design acquired 20% of the outstanding common stock of Quayle Company on January 1, 2014, by paying $800,000 for the 30,000 shares. Quayle declared and paid $0.30 per share cash dividends...
-
2. The benefits of financial planning Aa Aa Why Engage in Personal Financial Planning? Many people mistakenly believe that personal financial planning is an activity appropriate for only the wealthy;...
-
Kevan, Jerry, and Dave formed Albee LLC. Jerry and Dave each contributed $245,000 in cash. Kevan contributed the following assets: Kevan: _______________Basis Fair __________Market Value...
-
Suppose you wish to track how many times a program has been executed. You can store an int to count the file. Increase the count by 1 each time this program is executed. Let the program be...
-
The Loan class in Listing 10.2 does not implement Serializable. Rewrite the Loan class to implement Serializable. Write a program that creates five Loan objects and stores them in a file named...
-
Jeremys Book Warehouse distributes hardcover books to retail stores and extends credit terms of 2/10, n/30 to all of its customers. At the end of May, Jeremys inventory consisted of books purchased...
-
Consider the following procedure: procedure f(n: a natural number) if n = 0 then return(0) else return(f(n-1)+n) Which value is f(5)? What does it return for an arbitrary n?
-
Your Bank T-account shows a Debit balance of 10,000 as at 1/1/x9. On the 2/1/x9 you purchase a van for 7,000 and you take out 1,000 to book a family holiday. What is the Bank T-account balance as at...
-
why is critical not to overheat the organic matter being tested in the muffle furnace?
-
1. What is the corporate strategy behind Amazons acquisition of Whole Foods?
-
You execute the following program. Assume all forks succeed in executing. How many hello will be output? #include #include int main(void) { printf("hello "); fork(); fork(); fork(); fork();...
-
Mark's Music is a store that buys and sells musical instruments in Ontario, where the HST rate is 13%. Mark's Music uses a perpetual inventory system. Transactions for the business are shown below:...
-
1-Stern observed all of the following results EXCEPT _______ in his experiment. A-one of the recombinant phenotypes was associated with an X chromosome of normal length B-the number of car, B+ male...
-
Redo the previous problem, but providing an implementation within the class LinkedPositionalList that does not create or destroy any nodes.
-
Suppose we want to extend the PositionalList interface to include a method, positionAtIndex(i), that returns the position of the element having index i (or throws an IndexOutOfBoundsException, if...
-
Describe how to implement the queue ADT using two stacks as instance variables, such that all queue operations execute in amortized O(1) time. Give a formal proof of the amortized bound.
-
In relational model, how to distinguish different keys (primary key,superkey, foreign key and so on)?
-
how to transform this from an EERD to a relational model diagram. Attribute_1-1A Attribute_1-1B Attribute_1-1 Attribute_1-1C Attribute_1-2 Entity 1 FK3 (M,M) Attribute_R_1-2-1 Rel_1-2 Attribute_2-1...
-
why is cardinality important to a relational database model? How is it usually defined and what types of GIS analysis operations is it particularly important to? Provide specific examples in your...
Study smarter with the SolutionInn App