a.
Explanation of Solution
Program:
File name: “RetirementGoal.java”
//Import necessary header files
import java.util.Scanner;
//Define a class named RetirementGoal
public class RetirementGoal
{
//Define main method
public static void main (String[] args)
{
//Create an object for the Scanner class
Scanner input = new Scanner(System.in);
//Declare the variables
int years;
int saveAmount;
int total;
/*Prompt the user to enter the number of years the user
has until retirement */
System.out.print("How many years until retirement? >> ");
years = input.nextInt();
/*While condition if the user enters 0 or a negative number*/
while(years <= 0)
{
//Print the error message
System.out.println("Years cannot be 0 or negative");
//Reprompt the user to make a valid entry
System...
b.
Explanation of Solution
Program:
File name: “RetirementGoal2.java”
//Import necessary header files
import java.util.Scanner;
//Define a class named RetirementGoal2
public class RetirementGoal2
{
//Define main method
public static void main (String[] args)
{
//Create an object for the Scanner class
Scanner input = new Scanner(System.in);
//Declare the variables
int years;
int saveAmount;
int total;
final double RATE = 0.04;
/*Prompt the user to enter the number of years the user
has until retirement */
System.out.print("How many years until retirement? >> ");
years = input.nextInt();
/*While condition if the user enters 0 or a negative number*/
while(years <= 0)
{
//Print the error message
System.out.println("Years cannot be 0 or negative");
//Reprompt the user to make a valid entry
System.out.print("Please renter years >> ");
years = input.nextInt();
}
/*Prompt the user to enter the amount of money the user can save annually*/
System.out.print("How much can you save annually? >> ");
saveAmount = input.nextInt();
/*While condition if the user enters 0 or a negative number*/
while(saveAmount <= 0)
{
//Print the error message
System...
Trending nowThis is a popular solution!
- The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. You also will use a file named DebugEmployeeIDException.java with the DebugTwelve4.java file. // An employee ID can't be more than 999 // Keep executing until user enters four valid employee IDs // This program throws a FixDebugEmployeeIDException import java.util.*; public class DebugTwelve4 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String inStr, outString = ""; final int MAX = 999; int[] emps = new int[4]; for(int x = 0; x < emps.length; ++x) { System.out.println("Enter employee ID number"); inStr = input.next(); try { emps[x] = Integer.parseInt(inStr); if(emps[x] > MAX) { throw(new…arrow_forwardIn Chapter 4, you created a program that generates a random number, allows a user to guess it, and displays a message indicating whether the guess is too low, too high, or correct. Now, create a modified program called GuessingGame2 in which the user can continue to enter values until the correct guess is made. After the user guesses correctly, display the number of guesses made. Recall that you can generate a random number whose value is at least min and less than max using the following statements: Random ranNumber = new Random(); int randomNumber; randomNumber = ranNumber.Next(min, max);arrow_forwardIn previous chapters, you created applications for the Greenville Idol competition. Now, modify the version of the GreenvilleRevenue program created in Chapter 5 so that after the user enters the number of contestants in this competition, the user is prompted for the appropriate number of contestant names and a code for each contestant that indicates the type of talent: S for singing, D for dancing, M for playing a musical instrument, or O for other. Make sure that all entered codes are valid, and if not, reprompt the user to enter a correct code. After contestant data entry is complete, display a count of each type of talent. Then, continuously prompt the user for a talent code until the user enters a sentinel value. With each code entry, display a list of the contestants with that code, or display a message that the code is not valid and reprompt the user.arrow_forward
- Danielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that prompts the user for a salesperson initial (D, E, or F). Either uppercase or lowercase initials are valid. While the user does not type Z, continue by prompting for the amount of a sale. Issue an error message for any invalid initials entered. Keep a running total of the amounts sold by each salesperson. After the user types Z or z for an initial, display each salespersons total, a grand total for all sales, and the name of the salesperson with the highest total.arrow_forwardWrite an application that prompts the user for two integers and then prompts the user to enter an option as follows: 1 to add the two integers, 2 to subtract the second integer from the first, 3 to multiply the integers, and 4 to divide the first integer by the second. Display an error message if the user enters an option other than 1 through 4 or if the user chooses the divide option but enters 0 for the second integer. Otherwise, display the results of the arithmetic.arrow_forwardWrite an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average.arrow_forward
- Now code an application that declares a purchase object and prompts the user for purchase details. When this prompt is made, do not allow the user to proceed until a number between 1000 and 6000 inclusive has been entered. When the system prompts for a sale amount, it must not proceed until the user has entered a non-negative value. In the event a valid purchase object has been created, display the object’s invoice number, sale amount and sales taxarrow_forwardCreate an application that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Do not display the computer’s choice yet.)2. The user selects his or her choice of rock, paper, or scissors. To get this input you can use Button controls, or clickable PictureBox controls displaying some of the artwork that you will find in the student sample files.3. The computer’s choice is displayed.4. A winner is selected according to the following rules:• If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)• If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.)• If one player chooses…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT