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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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