Question: Please edit my following JAVA code so that there is no main function . I would like one function in this class that completes what
Please edit my following JAVA code so that there is no main function. I would like one function in this class that completes what the current program is trying to do so that I can call this class in my main class which will be separate.
import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class enterwklyincme { 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 weeklyIncome; Scanner in = new Scanner(System.in); System.out.println("What is you weekly income?"); weeklyIncome = readFloat(in); while (weeklyIncome < 0) { System.out.println("Please enter a value of 0 or higher."); weeklyIncome = readFloat(in); } System.out.println("Weekly income of $" + df.format(weeklyIncome) + " has been saved to your user profile!"); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
