Declare a linkedlist that stores strings

Assignment Help JAVA Programming
Reference no: EM13940427

Criterion Score

1. Declare a LinkedList that stores Strings

2. Add code that formats a String with the calculation's results

3. Store the formatted String into the LinkedList

4. Display the elements in the LinkedList when the user ends input

5. Insure that the FutureValueApp class compiles

6. Include a text file showing the output from at least 3 future value calculations

Send as a zip

import java.util.*;
import java.text.*;

public class FutureValueApp
{
public static void main(String[] args)
{
// display a welcome message
System.out.println("Welcome to the Future Value Calculator");
System.out.println();

// perform 1 or more calculations
Scanner sc = new Scanner(System.in);
String choice = "y";
while (choice.equalsIgnoreCase("y"))
{

// get the input from the user
System.out.println("DATA ENTRY");
double monthlyInvestment = getDoubleWithinRange(sc,
"Enter monthly investment: ", 0, 1000);
double interestRate = getDoubleWithinRange(sc,
"Enter yearly interest rate: ", 0, 30);
int years = getIntWithinRange(sc,
"Enter number of years: ", 0, 100);

// calculate the future value
double monthlyInterestRate = interestRate/12/100;
int months = years * 12;
double futureValue = calculateFutureValue(
monthlyInvestment, monthlyInterestRate, months);

// get the currency and percent formatters
NumberFormat currency = NumberFormat.getCurrencyInstance();
NumberFormat percent = NumberFormat.getPercentInstance();
percent.setMinimumFractionDigits(1);

// format the result as a single string
String results =
"Monthly investment:t"
+ currency.format(monthlyInvestment) + "n"
+ "Yearly interest rate:t"
+ percent.format(interestRate/100) + "n"
+ "Number of years:t"
+ years + "n"
+ "Future value:tt"
+ currency.format(futureValue) + "n";

// print the results
System.out.println();
System.out.println("FORMATTED RESULTS");
System.out.println(results);

// see if the user wants to continue
System.out.print("Continue? (y/n): ");
choice = sc.next();
System.out.println();
}
}

public static double getDouble(Scanner sc, String prompt)
{
boolean isValid = false;
double d = 0;
while (isValid == false)
{
System.out.print(prompt);
if (sc.hasNextDouble())
{
d = sc.nextDouble();
isValid = true;
}
else
{
System.out.println("Error! Invalid decimal value. Try again.");
}
sc.nextLine(); // discard any other data entered on the line
}
return d;
}

public static double getDoubleWithinRange(Scanner sc, String prompt,
double min, double max)
{
double d = 0;
boolean isValid = false;
while (isValid == false)
{
d = getDouble(sc, prompt);
if (d <= min)
System.out.println(
"Error! Number must be greater than " + min + ".");
else if (d >= max)
System.out.println(
"Error! Number must be less than " + max + ".");
else
isValid = true;
}
return d;
}

public static int getInt(Scanner sc, String prompt)
{
boolean isValidInt = false;
int i = 0;
while (isValidInt == false)
{
System.out.print(prompt);
if (sc.hasNextInt())
{
i = sc.nextInt();
isValidInt = true;
}
else
{
System.out.println("Error! Invalid integer value. Try again.");
}
sc.nextLine(); // discard any other data entered on the line
}
return i;
}

public static int getIntWithinRange(Scanner sc, String prompt,
int min, int max)
{
int i = 0;
boolean isValid = false;
while (isValid == false)
{
i = getInt(sc, prompt);
if (i <= min)
System.out.println(
"Error! Number must be greater than " + min + ".");
else if (i >= max)
System.out.println(
"Error! Number must be less than " + max + ".");
else
isValid = true;
}
return i;
}

public static double calculateFutureValue(double monthlyInvestment,
double monthlyInterestRate, int months)
{
double futureValue = 0;
for (int i = 1; i <= months; i++)
{
futureValue =
(futureValue + monthlyInvestment) *
(1 + monthlyInterestRate);
}
return futureValue;
}
}

Reference no: EM13940427

Questions Cloud

Provide a plan for reducing the federal debt : Imagine that you are an Economic Advisor to the President and need to provide a plan for reducing the federal debt. Conflicting goals create a need for compromise and tradeoffs to create a national budget while trying to remain under deficit limit..
Write, compile and run a standalone java application : Write, compile and run a standalone Java application that displays an output line on the console.
Describe how other countries implemented community policing : Describe how the other countries have implemented community policing. Is there any data or evidence to show whether these efforts have been effective?
What is the cost per equipment hour for the traceable costs : Explain why you feel these costs are traceable using equipment hours. What is the cost per equipment hour for these traceable costs?
Declare a linkedlist that stores strings : Include a text file showing the output from at least 3 future value calculations
Katie and william recently had a baby : Katie and William recently had a baby. Katie is a famous actress and philanthropist. William is a famous actor and action star. William and Katie are regarded in Hollywood circles as a power couple.
How curb drug abuse, white-collar time, and organized crime : Analyzed the impact of white-collar and organized crimes on public attitude toward crime and their confidence in government, similar crimes, crime organizations, and government machinery.
Develop a new application system : ‘You have been assigned as the manager on a project to develop a new application system for your business partner. You were given two weeks to develop a project plan and high level cost estimates.
Using examples explain what is dumping : Using examples explain what is dumping? Does dumping raise any moral issues? What are they? How could some of these issues be overcome?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create java program to simulate the operation of a bank atm

write a Java program to simulate the operation of a bank ATM (cashpoint) system for payment and deposit on an account. In order to make the system fairly simple there is only one bank account and there are 5 cards that can be used to deposit or wi..

  Write a calculator program for integer numbers in java

Write a calculator program for integer numbers in java. The calculator should be able to do addition, subtraction, multiplication, and division for integer numbers.

  Computes the salaries for a collection of employees

The first programming project involves writing a program that computes the salaries for a collection of employees of different types. This program consists of four classes. The first class is the Employee class, which contains the employee's name and..

  Writing a program to calculate the terms

The third programming project involves writing a program to calculate the terms of the following sequence of numbers: 0 1 2 5 12 29 ... where each term of the sequence is twice the previous term plus the second previous term. The 0th term of the s..

  Write an application that uses an array

Write an application that uses an Array to store 10 messages of type String. You will store this Array with 10 messages of your choosing.

  Write an application bmicalc

Write an application (BMICalc) that reads the user's weight in poinds and height in inches, then calculates the Body Mass Index.

  Two types of gui components might be useful

Radio buttons and check boxes are two of many different kinds of components that can be included in a graphical user interface. How are they similar and how are they different? Which kind requires grouping? Give an example of an application where eac..

  Write a java program to play game of lightsout

Write a java program to play game of LightsOut - prepare a java program to play the game of lightout.

  Write a void function this passed three integers

1. Write a void function this passed three integers by reference. The function should rearrange the parameter values so that the first parameter will get the smallest value; the second parameter the middle value; and the third parameter the largest v..

  Cascading style sheet to a website

Compare and contrast the process of adding JavaScript and a Cascading Style Sheet to a Website. Determine if they can be used simultaneously in a page.

  Make a program in java language with classes

Make a program, in JAVA language with classes, that simulates health attending in one business day, according to the information just given.

  Implement all the methods in each of the classes

You need to have an array for this database, the size of this database is given by MAX. You may simply set MAX to be 8 to save your effort in filling information.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd