Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am currently getting an error with my following function. Please edit my try catch clock so that this function executes correctly when called. Thanks

I am currently getting an error with my following function. Please edit my try catch clock so that this function executes correctly when called. Thanks in advance.

import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class test { private static DecimalFormat df = new DecimalFormat("0.00"); public static void EnterGoals(){ 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 (true) { // this try catch block is to give an error message when the user attempts to enter in anything other than a number try { spendAmt = Float.parseFloat(in.nextLine()); } catch (Exception e) { System.out.println("Please enter a numerical value."); } } 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

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions