Explore BrainMass
Share

Java Programming with Commented Code

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

A marketing research company has hired you to develop a program. Analytics Nation, Inc. has gathered information from about five different products. They would like to follow up with 1% of these households. Analytics Nation requires a third party to select 1% of the households for one of the products. Choices must be random.

Analytics Nation needs you to develop a program that uses a random number generator to identify 1% of the households for one product. Each household is mapped to a unique number ranging from 1 to the number of households as listed below. Choose one product from the following:

Product 1 (mounth wash)
3,765 households

Product 2 (dental floss)
3,800 households

Product 3 (grass seed)
2,400 households

Product 4 (grass fertilizer)
4,012 households

Product 5 (Blue-Ray DVD unit)
3,580 households

Requirements:

Develop a program to select the households for follow up. The user will be prompted for their selection. The code will randomly select 1% of the households for one of the five products using the random method. Your code would generate numbers for 1% of the available household population. For example, there are 2,400 households on record for product 3. The households are individually numbered from 1 to 2,400. You need to generate 24 random numbers between 1-2,400. A table containing these numbers should be produced and printed to the screen. The table must not contain duplicates. Print 7 numbers per row.

You need to use at least one repetition statement, at least one array and the random method in this code. For generating random numbers you should use the random() static method of class Math. It returns a double so you will need to cast it as an integer. If you chose product three you would set the generator range to 2,400 and generate random numbers for 1% (24) of the households. These numbers should range between 1 and 2,400:

number = (int) ( range * Math.random() ) + 1;

© BrainMass Inc. brainmass.com October 25, 2018, 7:34 am ad1c9bdddf
https://brainmass.com/engineering/computer-engineering/java-programming-commented-code-507482

Solution Preview

import java.util.Scanner;

public class AnalyticsNation {

public static void main(String[] args) {

//product info
int products[][] = {
{1, 3765},
{2, 3800},
{3, 2400},
{4, 4012},
{5, 3580}
};

Scanner scan = new Scanner(System.in);
boolean stop = false;
String selection;

do {
//print menu
System.out.println();
System.out.println("Select a product.");
System.out.println("1. product 1 (3,765)");
System.out.println("2. product 2 (3,800)");
System.out.println("3. product 3 (2,400)");
System.out.println("4. product 4 (4,012)");
...

Solution Summary

The expert examines Java programming with commented codes.

$2.19
See Also This Related BrainMass Solution

Java Code to Calculate Mortgage Payments

I need help with a program that will calculate mortgage payments. The program must be written in Java that will calculate and display the monthly payment amount to fully amortize a $200,000.00 loan over a 30 year term at 5.75? interest.

Part 1: Complete Change Request #4 in Service Request SR-mf-003:

Part 2: Complete Change Request #5 in Service Request SR-mf-003

Part 3: Complete Change Request #6 in Service Request SR-mf-003:

Part 4: Complete Change Request #7 in Service Request SR-mf-003:

Description of Request:
Need a program that will calculate mortgage payments.

Background of Request:
Agents in the field offices will need to be able to calculate mortgage payment amounts. In the future, we may want to put a mortgage calculator on our Web site.

Expected Results/Impact when completed:
A program written in Java that will calculate and display the monthly payment amount to fully amortize a $200,000.00 loan over a 30 year term at 5.75‰ interest.

Part 1
Design a program using a graphical user interface that prompts the user to enter the mortgage principal, the mortgage term (in years), and annual interest rate (APR), then calculates and displays the mortgage payment amount. Allow the user to loop back and enter new data or quit. The code should follow the formatting and commenting standards posted in the Course Materials forum.
The Mortgage formulas are given at the end of this document.

Change Request #4
Requestor: Ninfa Pendleton - Rapid City, SD
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. Allow the user to loop back and enter new data or quit. Please insert comments in the program to document the program.

Part 2
Modify your program to allow the user to enter the amount of the mortgage and then allow the user to select from a list of mortgage loans: 7 years at 5.35%, 15 years at 5.5%, and 30 years at 5.75%. Use an array of objects for the different loans. The program should calculate and display the mortgage payment amount, then display the loan balance and interest paid for each payment over the term of the loan in a scrolling pane. Allow the user to loop back and enter new data or quit.
The code should follow the formatting and commenting standards posted in the Course Materials forum.

Change Request #5
Requestor: Ninfa Pendleton - Rapid City, SD
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:

- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%

Use an array for the mortgage data for the different loans. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection or quit. Please insert comments in the program to document the program.

Part 3
Modify your program to allow the user to choose whether to enter the term and APR, or to select from the list of mortgage loans.
The code should follow the formatting and commenting standards posted in the Course-Materials forum.

Change Request #6
Requestor: Ninfa Pendleton - Rapid City, SD
Write the program in Java (with a graphical user interface) so that it will allow the user to select which way they want to calculate a mortgage: by input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment or by input of the amount of a mortgage and then select from a menu of mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5 %
- 30 year at 5.75%

In either case, display the mortgage payment amount and then, list the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection, or quit. Insert comments in the program to document the program.

Part 4

Modify your program to read the interest rates and terms for the array from a text file. Add graphics in the form of a chart that displays the change in principal balance over the life of the loan.
The code should follow the formatting and commenting standards posted in the Course-Materials forum.

Change Request #7
Requestor: Ninfa Pendleton - Rapid City, SD
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:

- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%

Use an array for the mortgage data for the different loans. Read the interest rates to fill the array from a sequential file. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Add graphics in the form of a chart. Allow the user to loop back and enter a new amount and make a new selection or quit. Please insert comments in the program to document the program.

Mortgage Formulas
1. Basic payment formula
To calculate the mortgage payment, use the following formula:

PMT = (PV x IR) / (1 - (1 + IR)-NP)
Java implementation: PMT = (PV * IR) / (1 - Math.pow(1 + IR, -NP))

Where:
PMT = Monthly Payment
PV = Principle Value (amount of loan)
IR = Interest Rate, by month
NP = Note Period, or mortgage term in months

IR = APR / 100 / 12
NP = Years * 12 (for example, 5 years means NP = 60)
APR = Annual Percentage Rate (for example 6.25)

Use the formula above when APR > 0.
If APR = 0 (an interest-free loan), then PMT = PV / NP.
2. Amortization Table
Pseudocode for the calculation process
/** initialize the balances **/
loanBalance = NP * payment
principalBalance = PV
interestBalance = loanBalance - principalBalance
totalPrincipalPaid = 0
totalInterestPaid = 0

/** step through all the payment periods */
For paymentNumber from 1 to NP:

/**
The portion of the payment that goes to interest is based on
the remaining principal balance.
**/
interestPaidThisMonth = interestRate * principalBalance

/**
The rest of the payment goes to principal.
**/
principalPaidThisMonth = payment - interestPaidThisMonth

/**
Update the remaining balances and total paid values
**/
loanBalance = loanBalance - payment
principalBalance = principalBalance - principalPaidThisMonth
totalPrincipalPaid = totalPrincipalPaid + principalPaidThisMonth
interestBalance = interestBalance - interestPaidThisMonth
totalInterestPaid = totalInterestPaid + interestPaidThisMonth
End For

Design Checklist

Check Description Comments
Does the design follow good Object Oriented principals?
Are the objects and their relationships described clearly?
Are the methods described clearly?
Does the design make sense and satisfy the requirements?

Code Checklist

Check Description Comments
Are classes and methods described comments?
Are comments clear, concise, and explanatory?
Is indentation used to illustrate the structure of the program and control structures?
Is white spaced used to improve readability?
Do identifiers logically describe use?
Do identifiers follow capitalization standards?
Are all variables and constant declared?

Execution Checklist

Check Description Comments
Does the project compile?
Does the project execute?
Do the input and output match the requirements?
Is the input and output logical and clear to the user?
Does the program perform the required actions correctly?
Does the program handle incorrect and invalid input in a sensible manner?

View Full Posting Details