Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please edit my following JAVA code so that there is no main function . Please show how to write the class so that only functions

Please edit my following JAVA code so that there is no main function. Please show how to write the class so that only functions are called in a separate main.java file. The functionality of the current code should still hold. Thanks in advance.

import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class enterfingoals { private static DecimalFormat df = new DecimalFormat("0.00"); public static float readFloat(Scanner reader) { float num; while (true) { try { num = Float.parseFloat(reader.nextLine()); return num; } catch (Exception e) { System.out.println("Please enter a numerical value."); } } } 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 = readFloat(in); while (spendAmt < 0) { System.out.println("Please enter a value of 0 or higher."); spendAmt = readFloat(in); } 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 = readFloat(in); while (saveAmt < 0) { System.out.println("Please enter a value of 0 or higher."); saveAmt = readFloat(in); } 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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions