Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please edit my following JAVA code so that if the user enters a letter or any symbol (anything non-numeric) that an error message will be

Please edit my following JAVA code so that if the user enters a letter or any symbol (anything non-numeric) that an error message will be given: "Please enter a value greater than 0." Thanks in advance. PLEASE SHOW SCREENSHOT OF OUTPUT.

import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class EnterFinancialGoals { private static DecimalFormat df = new DecimalFormat("0.00"); public static void main(String args[]) { float saveAmt; float spendAmt; Scanner in = new Scanner(System.in); System.out.println("How much would you like to spend per week?"); spendAmt=in.nextFloat(); while (spendAmt<0) { System.out.println("Please enter a value of 0 or higher."); spendAmt = in.nextFloat(); } System.out.println("Spending amount of $" + df.format(spendAmt) + " has been saved to your user profile!"); System.out.println(" "); System.out.println("How much would you like to save per week?"); saveAmt=in.nextFloat(); while (saveAmt<0) { System.out.println("Please enter a value of 0 or higher."); saveAmt = in.nextFloat(); } System.out.println("Saving amount of $" + df.format(saveAmt) + " has been saved to your user profile!"); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions

Question

What is human nature?

Answered: 1 week ago