Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What is cultural tourism and why is it growing?

Answered: 1 week ago