Can I get the answers in Java, please?
Write an application that prompts a user for the number of years the user has until retirement and the amount of money the user can save annually. If the user enters a 0 or a negative number for either value, reprompt the user until valid entries are made. Display the amount of money the user will have at retirement.
The total amount of money the user will have can be calculated with the following equation:
total=numYears∗amountSaved
Example input:
0 5 -2 45
Example output:
How many years until retirement? Years cannot be 0 or negative. Reenter years: How much can you save annually? Amount cannot be 0 or negative. Reenter amount to save annually: If you save $45 for 5 years, you will have $225
import java.util.*;
class Retirement
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int numYears;
System.out.println("How many years until retirement?");
// get user input
numYears = sc.nextInt();
// infinite loop
while(true)
{
// if input is correct
if( numYears > 0 )
break;
System.out.print("Years cannot be 0 or negative. Reenter years: ");
// get user input
numYears = sc.nextInt();
}
int amountSaved;
System.out.println("\nHow much can you save annually?");
// get user input
amountSaved = sc.nextInt();
// infinite loop
while(true)
{
// if input is correct
if( amountSaved > 0 )
break;
System.out.print("Amount cannot be 0 or negative. Reenter amount to save annually: ");
// get user input
amountSaved = sc.nextInt();
}
// calculate total amount saved
int total = numYears * amountSaved;
System.out.println("If you saved $" + amountSaved + " for " + numYears + " years, you will hava $" + total);
}
}
Sample Output

Can I get the answers in Java, please? Write an application that prompts a user for...
I need help with the following assignment: Write an application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message: Valid temperatures range from -20 to 130. Please reenter temperature. Before the program ends, display the...
CSC-295 Spring 2019 Assignment – String, StringBuilder and StringBuffer Write an application that prompts the user for a password that contains at least two uppercase letters, at least three lowercase letters, and at least one digit. Continuously reprompt the user until a valid password is entered. Display Valid password if the password is valid; if not, display the appropriate reason(s) the password is not valid as follows: The password did not have enough of the following: uppercase letters lowercase letters...
1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in); } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...
JAVA 2. (8 points) Write a code segment which prompts the user to enter the price of a tour and receives input from the user. A valid tour price is between $52.95 and $259.95, inclusive. Your program should continue to repeat until a valid tour price has been entered. If the user enters an invalid price, display a message describing why the input is invalid. You may assume that the user only enters a real number. The user will not...
(java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...
Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit 1. For Erase-ArrayContent option, write complete code for the C++ function Erase described below. The prototype for Erase function is as follow: void Erase( int a[ ], int * N, int * Search-Element) The function Erase should remove all occurrences of Search-Element from the array al). Note that array a[ ] is loaded with integer numbers entered by the user through the keyboard. N...
Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows: Product 1 1...
in java
Write an application that: 1. Prompts the user for a number of trials to perform (I will call this "N"). This operation should be type-safe for integers. 2. Simulates N trials of rolling two dice and finding the sum. 3. Uses an array to keep track of how many times each outcome has been rolled (you do not need to keep track of the actual rolls themselves). 4. Computes the percentage of the total number of rolls for...
How can I do this program complete with input validation so that the computer prompts the user to enter a number 0 through 100 if he/she guesses anything lower than 0, a floating point number, or other characters? And later, prompts the user to enter yes or no if he/she enters anything else when the program prompts the user to play again? Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number...
c# language
Description: Design and implement a C# application that allows the user to enter a number N. It returns to the user the result of the Fibonacci of N. The Fibonacci of a number N is calculated as follows: Fibonacci (0) 0 Fibonacci (1) - Fibonacci (n) - Fibonacci (n-1) + Fibonacci (n-2) Requirements Your Application should have the following: • An exception class called FibException that is thrown when the user enters a negative value of N •...