Assignment 3 - Lehman College - Department of Mathematics and

advertisement
Programming Assignment 3
Due March 8, 2012
Send your source code to (with Subject: A3-Sp12 cmp326 Firstname.Lastname)
gwang.jung@lehman.cuny.edu
Program 1: Write an entity class Person.java that has two instance variables, one for the
person's name and the other for the person's age.
After you write a default constructor that assigns "Bob Schneider" to name and 20 to age, add a
constructor and other methods outlined below.







Constructor that receives two parameters String name and int age and assigns values to
the instance variables name and age of a Person object.
Accessor methods and mutator methods for each instance variable.
Test whether two Person objects are equal (have the same name and age).
Test whether two Person objects have the same name.
Test whether two Person objects are the same age.
Test whether one Person object is older than another.
Test whether one Person object is younger than another.
Write a test program named PersonTest.java that demonstrates each method, with at least one
true and one false case for each of the methods tested.
1
Program 2: Write a class Loan.java that encapsulates data and methods for a loan issued on a
specific date based on the following UML class diagram. Note: default values of the instance
variables are initialized by the default constructor when a loan object is instantiated.
Loan
-annualInterestRate: double
The annual interest rate of the loan (default: 2.5).
-numberOfYears: int
The number of years for the loan (default: 1)
-loanAmount: double
The loan amount (default: 1000).
-loanDate: Date
The date this loan was created.
+Loan()
Constructs a default Loan object.
+Loan(annualInterestRate: double,
numberOfYears: int,
loanAmount: double)
Constructs a loan with specified interest rate, years, and
loan amount.
+getAnnualInterestRate(): double
Returns the annual interest rate of this loan.
+getNumberOfYears(): int
Returns the number of the years of this loan.
+getLoanAmount(): double
Returns the amount of this loan.
+getLoanDate(): Date
Returns the date of the creation of this loan.
+setAnnualInterestRate(
Sets a new annual interest rate to this loan.
annualInterestRate: double): void
Sets a new number of years to this loan.
+setNumberOfYears(
numberOfYears: int): void
+setLoanAmount(
loanAmount: double): void
Sets a new amount to this loan.
+getMonthlyPayment(): double
Returns the monthly payment of this loan.
+getTotalPayment(): double
Returns the total payment of this loan.
Monthly payment is calculated by the following two statements.
monthlyInterestRate = annualInterestRate / 1200.0;
monthlyPayment = loanAmount * monthlyInterestRate / (1 (Math.pow(1 / (1 + monthlyInterestRate), numberOfYears * 12)));

Test Loan.java by LoanTester.java
Pseudo-code
LoanTester.java
{
Create Loan object by the default constructor
and displays monthly payment and total payment.
2
Change annual interest rate, number of years, loan amount,
and displays monthly payment and total payment.
Ask user enter annual interest rate, number of years, loan amount,
Create Loan object by calling the overloaded constructor,
and displays monthly payment and total payment.
}
Format payment in dollar format (keep two digits after the decimal point)
Program 3: Department of Mathematics at Lehman College/CUNY recently obtained federal
education funds for scholarship. Undergraduate students get stipend per month according to their
GPAs. Scholarship pay rates are shown below. Department chairman Professor Schneider asked
a student in CMP326 to develop an application program that gets student’s name, classification
(e.g., freshman, etc.), GPA and displays the monthly stipend for the student in object oriented
programming paradigm.
GPA
Freshman (F)
Sophomore (P)
Junior (J)
Senior (S)
A+ (>= 4.0)
$500.00
$600.00
$700.00
$800.00
A ( > 3.7)
$350.00
$450.00
$550.00
$650.00
A- ( > 3.2)
$200
$300
$400
$450.00
First write Student.java that encapsulates each student’s information. Then write
StudentStipend.java that performs the task specified above. StudentStipend.java iterates until the
user wants to quit.
Program 4: Lehman Computer Store (LCS) is a retail seller of home computers (desktop and
notebook computers, printers, and supplies) located in 250 Bedford Park, Bronx, NY. LCS sales
staff works strictly on commission. At the end of the month, each salesperson’s commission is
calculated according to the following Table.
Sales Amount This Month
less than $10,000
$10,000–14,999
$15,000–17,999
$18,000–21,999
$22,000 or more
Commission Rate
5%
10%
12%
15%
16%
3
For example, a salesperson with $16,000 in monthly sales will earn a 12% commission ($1,920).
Another salesperson with $20,000 in monthly sales will earn a 15% commission ($3,000).
Because the staff gets paid once per month, LCS allows each employee to take up to $1,500 per
month in advance. When sales commissions are calculated, the amount of each employee’s
advanced pay is subtracted from the commission. If any salesperson’s commissions are less than
the amount of their advance, they must reimburse LCS for the difference. Here are two
examples: Beverly and John have $21,400 and $12,600 in sales, respectively. Beverly’s
commission is $3,210 and John’s commission is $1,260. Both Beverly and John took $1,500 in
advance pay. At the end of the month, Beverly gets a check for $1,710, but John must pay $240
back to LCS.
LCS hires a Lehman College CMP326 student to design and implement an application program
that calculates the end-of-month commission, amount of check to be issued, and amount to be
paid back to LCS for an employee (i.e., salesperson) in object oriented programming.
Write Employee.java that encapsulates each salesperson’s data such as name, ID, amount of
monthly sales, amount of advanced pay. Employee.java may have methods for calculating
commission, amount of pay, etc.
The application program must perform the following general steps:
1. Ask the user to enter the salesperson’s name and ID.
2. Ask the user to enter the salesperson’s monthly sales.
3. Ask the user to enter the amount of advanced pay.
4. Create an employee object
5. Use the amount of monthly sales to determine the commission rate.
6. Calculate the commission.
7. Calculate the salesperson’s pay by subtracting the amount of advanced pay from the
commission. If the amount is negative, the salesperson must reimburse the company.
8. Printout the sales person’s name, ID, and the amount of check to be issued, and amount
to be paid back to LCS if necessary.
The application program iterates based on Confirm Dialog Box.
Note: calculating commission, amount of pay, etc. can be performed either by your application
program or by methods in Employee.java.
4
Download